Skip to content

Commit dae7f53

Browse files
jaysa68Jaysa Garciapre-commit-ci[bot]
authored
Devenv (#891)
* devenv? * devenv works on desktop * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * devenv works on koi * submodule init * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove bootstrap symlink * pkgs.python311 instead of nixpkgs-python * less bullshit from cachix * refine README.md * devenv update --------- Co-authored-by: Jaysa Garcia <jaysa@ginger.ocf.berkeley.edu> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 17d8aac commit dae7f53

10 files changed

Lines changed: 76 additions & 75 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/.version
77
/ocfweb/static/scss/**/*.css
88
/venv
9+
/venv-*/
910
/virtualenv_run
1011
/ocflib
1112

Makefile

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
BIN := venv/bin
2-
PYTHON := $(BIN)/python
1+
PYTHON := python
32
SHELL := /usr/bin/env bash
43
RANDOM_PORT := $(shell expr $$(( 8000 + (`id -u` % 1000) )))
54
LISTEN_IP := 0.0.0.0
@@ -11,13 +10,13 @@ DOCKER_TAG_STATIC = $(DOCKER_REPO)ocfweb-static:$(DOCKER_REVISION)
1110

1211
.PHONY: test
1312
test: export OCFWEB_TESTING ?= 1
14-
test: venv mypy
15-
$(BIN)/py.test -v tests/
16-
$(BIN)/pre-commit run --all-files
13+
test: mypy
14+
py.test -v tests/
15+
pre-commit run --all-files
1716

1817
.PHONY: mypy
19-
mypy: venv
20-
$(BIN)/mypy -p ocfweb
18+
mypy:
19+
mypy -p ocfweb
2120

2221
.PHONY: cook-image
2322
cook-image:
@@ -34,52 +33,46 @@ push-image:
3433
docker push $(DOCKER_TAG_STATIC)
3534

3635
.PHONY: dev
37-
dev: venv ocfweb/static/scss/site.scss.css
38-
@echo -e "\e[1m\e[93mRunning on http://$(shell hostname -f ):$(RANDOM_PORT)/\e[0m"
36+
dev: ocfweb/static/scss/site.scss.css
37+
@echo -e "\e[1m\e[93mRunning on http://localhost:$(RANDOM_PORT)/ (run: ssh -L $(RANDOM_PORT):localhost:$(RANDOM_PORT) $(shell hostname -s))\e[0m"
3938
$(PYTHON) ./manage.py runserver $(LISTEN_IP):$(RANDOM_PORT)
4039

4140
.PHONY: local-dev
4241
local-dev: LISTEN_IP=127.0.0.1
4342
local-dev: dev
4443

45-
venv: requirements.txt requirements-dev.txt
46-
test -d venv || python3.11 -m venv venv
47-
$(BIN)/pip install --upgrade pip
48-
$(BIN)/pip install -r requirements.txt -r requirements-dev.txt
49-
touch venv
50-
5144
.PHONY: install-hooks
52-
install-hooks: venv
53-
$(BIN)/pre-commit install -f --install-hooks
45+
install-hooks:
46+
pre-commit install -f --install-hooks
5447

5548
.PHONY: lint
56-
lint: venv
57-
$(BIN)/pre-commit run --all-files
49+
lint:
50+
pre-commit run --all-files
5851

5952
.PHONY: clean
6053
clean:
61-
rm -rf *.egg-info venv
54+
rm -rf *.egg-info
6255

6356
# closer to prod
6457
.PHONY: gunicorn
65-
gunicorn: venv
58+
gunicorn:
6659
@echo "Running on port $(RANDOM_PORT)"
67-
$(BIN)/gunicorn -b 0.0.0.0:$(RANDOM_PORT) ocfweb.wsgi
60+
gunicorn -b 0.0.0.0:$(RANDOM_PORT) ocfweb.wsgi
6861

6962
# phony because it depends on other files, too many to express
7063
.PHONY: ocfweb/static/scss/site.scss.css
71-
ocfweb/static/scss/site.scss.css: ocfweb/static/scss/site.scss venv
72-
$(BIN)/pysassc "$<" "$@"
64+
ocfweb/static/scss/site.scss.css: ocfweb/static/scss/site.scss
65+
pysassc -I bootstrap-scss/assets/stylesheets "$<" "$@"
7366

7467
.PHONY: watch-scss
75-
watch-scss: venv
68+
watch-scss:
7669
while :; do \
7770
make ocfweb/static/scss/site.scss.css; \
7871
find ocfweb/static -type f -name '*.scss' | \
7972
inotifywait --fromfile - -e modify; \
8073
done
8174

8275
.PHONY: update-requirements
83-
update-requirements: venv
84-
$(BIN)/upgrade-requirements
76+
update-requirements:
77+
upgrade-requirements
8578
sed -i 's/^ocflib==.*/ocflib/' requirements.txt

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ ocfweb
77
[The main ocf website.](https://www.ocf.berkeley.edu/)
88

99

10-
## Working on `ocfweb`
10+
## Working on `ocfweb` on the ocfstaff remote dev server
11+
12+
1. Run `devenv up`
13+
- It may take about several minutes for all of the dependencies to install the first time. Give it at least 10 min.
14+
- You will see a process-compose tui appear, with a process called "web" and the logs visible. Your user's port is what is generated in the log line `Running on https://koi.ocf.berkeley.edu:YOUROWNPORT`, based on your uid. This is to avoid conflicts with other users who might also be running dev servers on koi.
15+
2. Open an SSH tunnel on your local host (**not** on `koi` or other OCF servers): `ssh -L YOUROWNPORT:localhost:YOUROWNPORT koi`
16+
- to avoid this extra step in the future, add the following to your `~/.ssh/config`:
17+
```
18+
Host koi
19+
HostName koi.ocf.berkeley.edu
20+
LocalForward YOUROWNPORT localhost:YOUROWNPORT
21+
```
22+
3. Go to https://localhost:YOUROWNPORT in your local browser!
23+
24+
25+
## BELOW THIS IS OUTDATED. WIP
26+
27+
---
1128
1229
We recommend following all of these steps
1330
[on supernova](https://www.ocf.berkeley.edu/docs/staff/procedures/ssh-supernova/),

devenv.lock

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"devenv": {
44
"locked": {
55
"dir": "src/modules",
6-
"lastModified": 1769881431,
6+
"lastModified": 1777679510,
77
"owner": "cachix",
88
"repo": "devenv",
9-
"rev": "72d5e66e2dd5112766ef4c9565872b51094b542d",
9+
"rev": "bc8b21628907c726c74094cedc439c10a455cdb7",
1010
"type": "github"
1111
},
1212
"original": {
@@ -31,21 +31,6 @@
3131
"type": "github"
3232
}
3333
},
34-
"flake-compat_2": {
35-
"flake": false,
36-
"locked": {
37-
"lastModified": 1767039857,
38-
"owner": "edolstra",
39-
"repo": "flake-compat",
40-
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
41-
"type": "github"
42-
},
43-
"original": {
44-
"owner": "edolstra",
45-
"repo": "flake-compat",
46-
"type": "github"
47-
}
48-
},
4934
"git-hooks": {
5035
"inputs": {
5136
"flake-compat": "flake-compat",
@@ -55,10 +40,10 @@
5540
]
5641
},
5742
"locked": {
58-
"lastModified": 1769069492,
43+
"lastModified": 1776796298,
5944
"owner": "cachix",
6045
"repo": "git-hooks.nix",
61-
"rev": "a1ef738813b15cf8ec759bdff5761b027e3e1d23",
46+
"rev": "3cfd774b0a530725a077e17354fbdb87ea1c4aad",
6247
"type": "github"
6348
},
6449
"original": {
@@ -88,11 +73,14 @@
8873
}
8974
},
9075
"nixpkgs": {
76+
"inputs": {
77+
"nixpkgs-src": "nixpkgs-src"
78+
},
9179
"locked": {
92-
"lastModified": 1767052823,
80+
"lastModified": 1776852779,
9381
"owner": "cachix",
9482
"repo": "devenv-nixpkgs",
95-
"rev": "538a5124359f0b3d466e1160378c87887e3b51a4",
83+
"rev": "ec3063523dcd911aeadb50faa589f237cdab5853",
9684
"type": "github"
9785
},
9886
"original": {
@@ -102,23 +90,20 @@
10290
"type": "github"
10391
}
10492
},
105-
"nixpkgs-python": {
106-
"inputs": {
107-
"flake-compat": "flake-compat_2",
108-
"nixpkgs": [
109-
"nixpkgs"
110-
]
111-
},
93+
"nixpkgs-src": {
94+
"flake": false,
11295
"locked": {
113-
"lastModified": 1765052656,
114-
"owner": "cachix",
115-
"repo": "nixpkgs-python",
116-
"rev": "04b27dbad2e004cb237db202f21154eea3c4f89f",
96+
"lastModified": 1776329215,
97+
"narHash": "sha256-a8BYi3mzoJ/AcJP8UldOx8emoPRLeWqALZWu4ZvjPXw=",
98+
"owner": "NixOS",
99+
"repo": "nixpkgs",
100+
"rev": "b86751bc4085f48661017fa226dee99fab6c651b",
117101
"type": "github"
118102
},
119103
"original": {
120-
"owner": "cachix",
121-
"repo": "nixpkgs-python",
104+
"owner": "NixOS",
105+
"ref": "nixpkgs-unstable",
106+
"repo": "nixpkgs",
122107
"type": "github"
123108
}
124109
},
@@ -127,7 +112,6 @@
127112
"devenv": "devenv",
128113
"git-hooks": "git-hooks",
129114
"nixpkgs": "nixpkgs",
130-
"nixpkgs-python": "nixpkgs-python",
131115
"pre-commit-hooks": [
132116
"git-hooks"
133117
]

devenv.nix

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
{ pkgs, lib, config, inputs, ... }:
22

33
{
4+
cachix.enable = false;
45
languages.python = {
56
enable = true;
6-
version = "3.11";
7+
package = pkgs.python311;
8+
venv = {
9+
enable = true;
10+
requirements = builtins.readFile ./requirements.txt + builtins.readFile ./requirements-dev.txt;
11+
};
12+
uv.enable = true;
713
};
814
packages = with pkgs; [
915
gnumake
10-
python312Packages.shellescape
1116
];
17+
env.DJANGO_DEBUG = "1";
18+
19+
processes.web.exec = "make dev";
20+
21+
enterShell = ''
22+
git submodule update --init
23+
'';
1224
}

devenv.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
inputs:
22
nixpkgs:
33
url: github:cachix/devenv-nixpkgs/rolling
4-
nixpkgs-python:
5-
url: github:cachix/nixpkgs-python
6-
inputs:
7-
nixpkgs:
8-
follows: nixpkgs

ocfweb/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def __mod__(self, ref: Any) -> str:
156156
conf.read('/etc/ocfweb/ocfweb.conf')
157157

158158
SECRET_KEY = conf.get('django', 'secret')
159-
DEBUG = conf.getboolean('django', 'debug')
159+
DEBUG = os.getenv('DJANGO_DEBUG') == '1' or conf.getboolean('django', 'debug')
160160

161161
STATIC_URL = conf.get('django', 'static_url')
162162
STATIC_ROOT = os.environ.get('OCFWEB_STATIC_ROOT') or conf.get('django', 'static_root')

ocfweb/static/scss/bootstrap

Lines changed: 0 additions & 1 deletion
This file was deleted.

ocfweb/static/scss/site.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@import 'bootstrap/bootstrap';
2-
@import 'bootstrap/bootstrap/variables';
1+
@import 'bootstrap';
2+
@import 'bootstrap/variables';
33

44
/*
55
Useful variables from Bootstrap:

tests/account/vhost_mail_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import crypt
21
import csv
32
import io
43
import re
@@ -7,6 +6,7 @@
76
from textwrap import dedent
87
from unittest import mock
98

9+
import crypt
1010
import pytest
1111
from django.contrib import messages
1212
from django.http import HttpResponseRedirect

0 commit comments

Comments
 (0)