Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copy this file to .env and fill in the values.
# uv run will automatically load .env when running commands.
#
# For a full overview of environment variables, see the section
# "Site-specific settings" of the documentation.

DEBUG=1
EMAIL_HOST=localhost
EMAIL_PORT=25
# Run `uv run manage.py gen_secret_key` to create a SECRET_KEY
SECRET_KEY=

# Use argus.site.settings.dev for defaults, or a local settings.py file (see docs)
DJANGO_SETTINGS_MODULE=
# Syntax: postgresql://argus:<LOCAL DB PASSWORD>@localhost:5432/argus
DATABASE_URL=
15 changes: 5 additions & 10 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Install dependencies
- name: Check HTML formatting and lint
run: |
pip install -U pip
pip install djlint

- name: Format HTML
run: |
djlint --version
djlint . --check --configuration pyproject.toml
uvx djlint --version
uvx djlint . --check --lint --configuration pyproject.toml
6 changes: 4 additions & 2 deletions .github/workflows/generate-er-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ jobs:
with:
python-version: 3.11

- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Install dependencies
run: |
pip install -U pip
pip install tox
uv pip install --system tox tox-uv
sudo apt-get install -y --no-install-recommends graphviz

- name: Create and switch to new branch
Expand Down
36 changes: 4 additions & 32 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@ jobs:
with:
version: "0.14.13"

djlint:
runs-on: ubuntu-latest
name: Lint HTML
steps:
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6

- name: Install dependencies
run: |
pip install -U pip
pip install djlint

- name: Lint HTML
run: djlint --lint .

test:
needs: ruff

Expand All @@ -48,19 +31,14 @@ jobs:
steps:
- uses: actions/checkout@v6

- uses: actions/cache@v5
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Set Environment Variables
run: |
echo "DJANGO_SETTINGS_MODULE=argus.site.settings.test_CI" >> $GITHUB_ENV
Expand All @@ -69,13 +47,7 @@ jobs:
echo "POSTGRES_PASSWORD=password" >> $GITHUB_ENV

- name: Install dependencies
# if: steps.cache.outputs.cache-hit != 'true'
run: |
set -xe
python -VV
python -m site
python -m pip install --upgrade pip "setuptools<46" wheel
python -m pip install --upgrade virtualenv "tox>=4" tox-gh-actions coverage
run: uv pip install --system "tox>=4" tox-gh-actions tox-uv coverage

- name: Set up PostgreSQL
uses: ankane/setup-postgres@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!.readthedocs.yaml
!.sonarcloud.properties
!.mailmap
!.env.template

# local config files
cmd.sh
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends tini \
build-essential libpq-dev libffi-dev libssl-dev git
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
RUN mkdir -p /argus
COPY requirements.txt /argus
COPY requirements/*.txt /argus/requirements/

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
RUN uv venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

WORKDIR /argus
RUN pip install gunicorn -r requirements.txt -r /argus/requirements/dev.txt
RUN uv pip install gunicorn -r requirements.txt -r /argus/requirements/dev.txt

ENV PYTHONPATH=/argus/src
ENV PYTHONDONTWRITEBYTECODE=1
Expand Down
38 changes: 37 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
.PHONY: clean testclean distclean coverageclean cacheclean nuke tailwind docclean upgrade-tailwind tailwind-watch
.PHONY: clean testclean distclean coverageclean cacheclean nuke tailwind docclean upgrade-tailwind tailwind-watch install run set-env create-env

TAILWINDDIR=src/argus/htmx/tailwindtheme
STATICDIR=src/argus/htmx/static
PYTHONPATH=./src


ifneq ($(filter set-env create-env,$(MAKECMDGOALS)),)
ENV_NAME := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
ifneq ($(ENV_NAME),)
$(eval $(ENV_NAME):;@:)
endif
endif

set-env:
ifdef ENV_NAME
@if [ ! -f ".env.$(ENV_NAME)" ]; then echo "Error: .env.$(ENV_NAME) not found"; exit 1; fi
@if [ -f .env ] && [ ! -L .env ]; then echo "Error: .env is a regular file, rename it first (e.g. mv .env .env.default)"; exit 1; fi
@ln -sf ".env.$(ENV_NAME)" .env
@echo "Selected .env.$(ENV_NAME)"
else
@echo "Available environments:"
@ls -1 .env.* 2>/dev/null | grep -v '\.env\.template$$' | sed 's/\.env\./ /' || echo " (none)"
@if [ -L .env ]; then echo "\nActive: $$(readlink .env)"; fi
@echo "\nUsage: make set-env <name>"
endif

create-env:
ifndef ENV_NAME
@echo "Usage: make create-env <name>"
else
@if [ -f ".env.$(ENV_NAME)" ]; then echo "Error: .env.$(ENV_NAME) already exists"; exit 1; fi
@cp .env.template ".env.$(ENV_NAME)"
@echo "Created .env.$(ENV_NAME) from template"
endif

install:
uv sync --extra dev

run:
uv run manage.py runserver


clean:
-find . -name __pycache__ -print0 | xargs -0 rm -rf
-find . -name "*.pyc" -print0 | xargs -0 rm -rf
Expand Down
49 changes: 28 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ There are several ways to install Argus.

* Python 3.10+
* Django 5.2
* pip
* [uv](https://docs.astral.sh/uv/)
* PostgreSQL 14+

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

To install from the lock-file use pip:
To install from the lock-file use uv:

```console
$ pip install -c constraints.txt --upgrade -r requirements.txt
$ uv pip install -c constraints.txt --upgrade -r requirements.txt
```

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

```console
$ pip install "tox>=4"
$ uv pip install "tox>=4" tox-uv
$ tox run -e upgrade-deps -- -U
```

Expand Down Expand Up @@ -171,39 +171,45 @@ $ git clone https://github.com/Uninett/Argus.git
$ cd Argus
```

We recommend using virtualenv or virtualenvwrapper to create
a place to stash Argus' dependencies.
Comment on lines -174 to -175

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will still need to be able to use virtualenvwrapper because I need to switch between different sets of dependencies...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the text to mention this as an option.


Create and activate a Python virtual environment.
Create and activate a Python virtual environment. You can also use
virtualenv or virtualenvwrapper if you prefer.
```console
$ python -m venv venv
$ source venv/bin/activate
$ uv venv
$ source .venv/bin/activate
```

Install Argus' requirements into the virtual env.
```console
$ pip install -r requirements-django52.txt
$ pip install -r requirements/dev.txt
$ uv pip install -r requirements-django52.txt
$ uv pip install -r requirements/dev.txt
```

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

Copy the `cmd.sh-template` to `cmd.sh` and make it executable
Environment files follow the naming convention `.env.<name>`. Create one from the
template:
```console
$ cp cmd.sh-template cmd.sh
$ chmod u+x cmd.sh
$ make create-env dev
```
Now set the environment variables in the file using an editor.

Required settings in `cmd.sh` are
Edit `.env.dev` and fill in the required settings:

- `DATABASE_URL`,
- `DJANGO_SETTINGS_MODULE` and
- `SECRET_KEY`.

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

If you need more complex settings than environment variables and ``cmd.sh`` can provide,
You can create multiple environments for different configurations (e.g.
`.env.dev`, `.env.test`) and switch between them:
```console
$ make set-env dev
```

This symlinks `.env.dev` to `.env` so that `uv run` picks it up automatically.
Run `make set-env` without arguments to list available environments.

If you need more complex settings than environment variables can provide,
we recommend having a `localsettings.py` in the same directory as `manage.py` with any
overrides.

Expand All @@ -217,10 +223,11 @@ See https://argus-server.readthedocs.io/en/latest/reference/htmx-frontend.html.

### Step 3: Run Argus in development

Afterwards, run the initial Argus setup and start the server.
`uv run` automatically loads the `.env` file (or the file set via `UV_ENV_FILE`).
Run the initial Argus setup and start the server.
```console
$ python manage.py initial_setup
$ python manage.py runserver
$ uv run manage.py initial_setup
$ uv run manage.py runserver
```

You will find Argus running at http://localhost:8000/.
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1787.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use uv for faster dependency installation, CI pipelines, and Docker builds
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cd /argus
git config --global --add safe.directory /argus
python3 -m pip install -e .
uv pip install -e .
python3 manage.py collectstatic --noinput
python3 manage.py migrate --noinput

Expand Down
7 changes: 4 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ FROM python:3.13-trixie
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends tini build-essential
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
RUN uv venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install some dev requirements that aren't part of the minimal dependencies:
RUN pip install psycopg2-binary django-extensions python-dotenv gunicorn
RUN uv pip install psycopg2-binary django-extensions gunicorn

# Make an unprivileged user to run the server
RUN useradd --system argus
Expand All @@ -26,7 +27,7 @@ RUN mkdir -p /static && chown argus /static
ENV STATIC_ROOT=/static

COPY . /src
RUN pip install '/src' && rm -rf /src
RUN uv pip install '/src' && rm -rf /src

# Install API backend settings suitable for Docker deployment
RUN mkdir /extrapython
Expand Down
2 changes: 1 addition & 1 deletion docs/development/howtos/change-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ A settings file may override anything set via environment variable.
``argus.site.settings.prod`` is a good starting point for production.

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

Development
~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/development/howtos/regenerate-the-ER-diagram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Get dependencies

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

pip install argus-server[dev]
uv sync --extra dev

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

Expand Down
6 changes: 3 additions & 3 deletions docs/development/howtos/toggle-django-debug-toolbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Make sure it is installed
You need to have ``django-debug-toolbar`` installed for this, it's part of the
dev-dependencies so you can get it through any of::

pip install django-debug-toolbar
uv pip install django-debug-toolbar

or::

pip install argus-server[dev]
uv pip install argus-server[dev]

or::

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

Set up extra-apps with django-debug-toolbar
-------------------------------------------
Expand Down
Loading
Loading