Skip to content

Commit a4172e5

Browse files
committed
Improve local development setup with uv
1 parent ae08b41 commit a4172e5

File tree

13 files changed

+2695
-39
lines changed

13 files changed

+2695
-39
lines changed

.env.template

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copy this file to .env and fill in the values.
2+
# uv run will automatically load .env when running commands.
3+
#
4+
# For a full overview of environment variables, see the section
5+
# "Site-specific settings" of the documentation.
6+
7+
DEBUG=1
8+
EMAIL_HOST=localhost
9+
EMAIL_PORT=25
10+
# Run `uv run manage.py gen_secret_key` to create a SECRET_KEY
11+
SECRET_KEY=
12+
13+
# Use argus.site.settings.dev for defaults, or a local settings.py file (see docs)
14+
DJANGO_SETTINGS_MODULE=
15+
# Syntax: postgresql://argus:<LOCAL DB PASSWORD>@localhost:5432/argus
16+
DATABASE_URL=

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
!.readthedocs.yaml
1010
!.sonarcloud.properties
1111
!.mailmap
12+
!.env.template
1213

1314
# local config files
1415
cmd.sh

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
.PHONY: clean testclean distclean coverageclean cacheclean nuke tailwind docclean upgrade-tailwind tailwind-watch
1+
.PHONY: clean testclean distclean coverageclean cacheclean nuke tailwind docclean upgrade-tailwind tailwind-watch install run
22

33
TAILWINDDIR=src/argus/htmx/tailwindtheme
44
STATICDIR=src/argus/htmx/static
55
PYTHONPATH=./src
66

77

8+
install:
9+
uv sync --extra dev
10+
11+
run:
12+
uv run manage.py runserver
13+
14+
815
clean:
916
-find . -name __pycache__ -print0 | xargs -0 rm -rf
1017
-find . -name "*.pyc" -print0 | xargs -0 rm -rf

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ There are several ways to install Argus.
3838

3939
* Python 3.10+
4040
* Django 5.2
41-
* pip
41+
* [uv](https://docs.astral.sh/uv/)
4242
* PostgreSQL 14+
4343

4444
#### Optional requirements
@@ -76,10 +76,10 @@ the release was tested on. The file `constraints.txt` is for controlling
7676
versions of sub-dependencies so as to not poison the pyproject.toml. The wheel
7777
package does not contain either of these two files.
7878

79-
To install from the lock-file use pip:
79+
To install from the lock-file use uv:
8080

8181
```console
82-
$ pip install -c constraints.txt --upgrade -r requirements.txt
82+
$ uv pip install -c constraints.txt --upgrade -r requirements.txt
8383
```
8484

8585
### First run
@@ -110,7 +110,7 @@ $ python manage.py runserver
110110
To update the dependency lock-files, use `tox`:
111111

112112
```console
113-
$ pip install "tox>=4"
113+
$ uv pip install "tox>=4" tox-uv
114114
$ tox run -e upgrade-deps -- -U
115115
```
116116

@@ -171,39 +171,34 @@ $ git clone https://github.com/Uninett/Argus.git
171171
$ cd Argus
172172
```
173173

174-
We recommend using virtualenv or virtualenvwrapper to create
175-
a place to stash Argus' dependencies.
176-
177174
Create and activate a Python virtual environment.
178175
```console
179-
$ python -m venv venv
180-
$ source venv/bin/activate
176+
$ uv venv
177+
$ source .venv/bin/activate
181178
```
182179

183180
Install Argus' requirements into the virtual env.
184181
```console
185-
$ pip install -r requirements-django52.txt
186-
$ pip install -r requirements/dev.txt
182+
$ uv pip install -r requirements-django52.txt
183+
$ uv pip install -r requirements/dev.txt
187184
```
188185

189186
### Step 2: Setting environment variables and Django settings
190187

191-
Copy the `cmd.sh-template` to `cmd.sh` and make it executable
188+
Copy `.env.template` to `.env` and fill in the values.
192189
```console
193-
$ cp cmd.sh-template cmd.sh
194-
$ chmod u+x cmd.sh
190+
$ cp .env.template .env
195191
```
196-
Now set the environment variables in the file using an editor.
197192

198-
Required settings in `cmd.sh` are
193+
Required settings in `.env` are
199194

200195
- `DATABASE_URL`,
201196
- `DJANGO_SETTINGS_MODULE` and
202197
- `SECRET_KEY`.
203198

204199
`DJANGO_SETTINGS_MODULE` can be set to `argus.site.settings.dev`.
205200

206-
If you need more complex settings than environment variables and ``cmd.sh`` can provide,
201+
If you need more complex settings than environment variables can provide,
207202
we recommend having a `localsettings.py` in the same directory as `manage.py` with any
208203
overrides.
209204

@@ -217,10 +212,10 @@ See https://argus-server.readthedocs.io/en/latest/reference/htmx-frontend.html.
217212

218213
### Step 3: Run Argus in development
219214

220-
Afterwards, run the initial Argus setup and start the server.
215+
`uv run` automatically loads the `.env` file. Run the initial Argus setup and start the server.
221216
```console
222-
$ python manage.py initial_setup
223-
$ python manage.py runserver
217+
$ uv run manage.py initial_setup
218+
$ uv run manage.py runserver
224219
```
225220

226221
You will find Argus running at http://localhost:8000/.

docs/development/howtos/change-settings.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ A settings file may override anything set via environment variable.
4242
``argus.site.settings.prod`` is a good starting point for production.
4343

4444
.. note:: The development settings file assumes that the optional development
45-
dependencies are installed. You can get them via ``pip install argus-server[dev]``.
45+
dependencies are installed. You can get them via ``uv sync --extra dev``.
4646

4747
Development
4848
~~~~~~~~~~~

docs/development/howtos/regenerate-the-ER-diagram.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Get dependencies
1111

1212
You need to have installed the development dependencies to regenerate the diagram::
1313

14-
pip install argus-server[dev]
14+
uv sync --extra dev
1515

1616
This will install ``django_extensions`` which has the diagram generator we use.
1717

docs/development/howtos/toggle-django-debug-toolbar.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ Make sure it is installed
1515
You need to have ``django-debug-toolbar`` installed for this, it's part of the
1616
dev-dependencies so you can get it through any of::
1717

18-
pip install django-debug-toolbar
18+
uv pip install django-debug-toolbar
1919

2020
or::
2121

22-
pip install argus-server[dev]
22+
uv pip install argus-server[dev]
2323

2424
or::
2525

26-
pip install -r requirements/dev.txt
26+
uv sync --extra dev
2727

2828
Set up extra-apps with django-debug-toolbar
2929
-------------------------------------------

docs/development/makefile-rules.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
Makefile rules
55
==============
66

7-
The repo has a ``Makefile`` to help with development. None of the rules depend
8-
on a virtualenv being activated, but may depend on having python 3 in the path.
7+
The repo has a ``Makefile`` to help with development. The rules depend on having
8+
``uv`` installed.
99

1010
Always run ``make`` from the root of the repository.
1111

12+
Rules for development setup
13+
===========================
14+
15+
install
16+
-------
17+
18+
Runs ``uv sync --extra dev`` to create a virtual environment and install all
19+
dependencies including dev extras.
20+
21+
run
22+
---
23+
24+
Runs the Django development server via ``uv run manage.py runserver``.
25+
1226
Rules that delete files
1327
=======================
1428

docs/development/management-commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ as such:
5353
Generate a secret key
5454
---------------------
5555

56-
To generate a secret key to be used in the `cmd.sh` file one can use
56+
To generate a secret key to be used in the `.env` file one can use
5757
the command `gen_secret_key`:
5858

5959
.. code:: console

docs/development/notes.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ in Argus:
1717
2. using a ``settings.py`` file.
1818

1919
For development, a simple and good practice is to define environment variables in a
20-
``cmd.sh`` file.
21-
This file serves as a "wrapper" to call ``manage.py`` with a defined set of environment
22-
variables, and simplifies the development process.
23-
24-
You may find it useful to have several ``cmd.sh`` files for different purposes, for
25-
instance to invoke different databases.
26-
The files can be named ``cmd-local.sh``, ``cmd-prod.sh`` and ``cmd-demo.sh`` or
27-
similar.
20+
``.env`` file. Copy ``.env.template`` to ``.env`` and fill in the values. The dev
21+
settings (``argus.site.settings.dev``) will automatically load ``.env`` via
22+
``python-dotenv``.
2823

2924
The limitation of environment variables is that they can only contain numbers, Boolean
3025
values (``0``/``1``) and strings.
@@ -44,5 +39,5 @@ files later.
4439
``True``.
4540
Otherwise, logentries will appear twice.
4641

47-
.. warning:: Do not check your ``cmd.sh`` or ``settings.py`` files into version control,
42+
.. warning:: Do not check your ``.env`` or ``settings.py`` files into version control,
4843
since they contain passwords and sensitive data.

0 commit comments

Comments
 (0)