Skip to content

Commit

Permalink
Ensure reproducible development and test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Dec 17, 2023
1 parent cde4fc3 commit 1f87a2f
Show file tree
Hide file tree
Showing 8 changed files with 1,802 additions and 173 deletions.
66 changes: 33 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ name: tests
on:
push:
schedule:
- cron: '0 2 * * *'
- cron: '0 2 * * 6'

env:
RUST_VERSION: "1.68.2"
TRUNK_VERSION: "0.17.5"
POETRY_VERSION: "1.7.1"
POETRY_DYNAMIC_VERSIONING_VERSION: "1.2.0"

jobs:
check_frontend:
Expand All @@ -19,9 +21,10 @@ jobs:
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${{ env.RUST_VERSION }}
echo ~/.cargo/bin >> $GITHUB_PATH
- name: Install dependencies
- name: Install Poetry
run: |
pip install setuptools_scm
pipx install poetry==${{ env.POETRY_VERSION }}
pipx install poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Check
run: |
make check_frontend
Expand All @@ -36,18 +39,18 @@ jobs:
target: [black, ruff, mypy]
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx install poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
cache: poetry
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --user -e .[devel]
echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
poetry install
- name: Check
run: |
make check_${{ matrix.target }}
Expand All @@ -60,15 +63,15 @@ jobs:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx install poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
cache: poetry
- name: Set up Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${{ env.RUST_VERSION }} --target wasm32-unknown-unknown --profile minimal
Expand All @@ -79,8 +82,6 @@ jobs:
- name: Install dependencies
run: |
sudo apt install libarchive-tools
python -m pip install --upgrade pip
pip install build setuptools_scm
cargo install --locked trunk@${{ env.TRUNK_VERSION }}
- name: Test
run: |
Expand Down Expand Up @@ -108,18 +109,18 @@ jobs:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx install poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
cache: poetry
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --user -e .[devel]
echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
poetry install
- name: Test
run: |
make test_backend
Expand All @@ -131,13 +132,15 @@ jobs:
python-version: "3.10"
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx install poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
cache: poetry
- name: Set up Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${{ env.RUST_VERSION }} --target wasm32-unknown-unknown --profile minimal
Expand All @@ -148,11 +151,8 @@ jobs:
- name: Install dependencies
run: |
sudo apt install libarchive-tools
python -m pip install --upgrade pip
pip install build setuptools_scm
pip install --user -e .[devel]
poetry install
cargo install --locked trunk@${{ env.TRUNK_VERSION }}
echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
- name: Test
run: |
make test_e2e
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FRONTEND_FILES := index.css manifest.json service-worker.js valens-frontend.js v
PACKAGE_FRONTEND_FILES := valens/frontend $(addprefix valens/frontend/,$(FRONTEND_FILES))
BUILD_DIR := $(PWD)/build
CONFIG_FILE := $(BUILD_DIR)/config.py
VERSION ?= $(shell python3 -c "import setuptools_scm; print(setuptools_scm.get_version())")
VERSION ?= $(shell poetry version -s)
WHEEL ?= dist/valens-$(VERSION)-py3-none-any.whl

export SQLALCHEMY_WARN_20=1
Expand Down Expand Up @@ -55,13 +55,13 @@ test_frontend:
test_backend:
mkdir -p valens/frontend
touch $(addprefix valens/frontend/,$(FRONTEND_FILES))
python3 -m pytest -n$(shell nproc) -vv --cov=valens --cov-branch --cov-fail-under=100 --cov-report=term-missing:skip-covered tests/backend
poetry run pytest -n$(shell nproc) -vv --cov=valens --cov-branch --cov-fail-under=100 --cov-report=term-missing:skip-covered tests/backend

test_installation: $(BUILD_DIR)/venv/bin/valens
$(BUILD_DIR)/venv/bin/valens --version

test_e2e: $(BUILD_DIR)/venv/bin/valens
python3 -m pytest -n$(shell nproc) -vv --driver chrome --headless tests/e2e
poetry run pytest -n$(shell nproc) -vv --driver chrome --headless tests/e2e

$(BUILD_DIR)/venv:
python3 -m venv $(BUILD_DIR)/venv
Expand Down Expand Up @@ -105,7 +105,7 @@ screenshots: $(PACKAGE_FRONTEND_FILES)
dist: $(WHEEL)

$(WHEEL): $(PACKAGE_FRONTEND_FILES)
python3 -m build
poetry build

valens/frontend:
mkdir -p valens/frontend
Expand All @@ -126,7 +126,7 @@ run_frontend:
PATH=~/.cargo/bin:${PATH} trunk --config frontend/Trunk.toml serve --port 8000

run_backend: $(CONFIG_FILE)
VALENS_CONFIG=$(CONFIG_FILE) flask --app valens --debug run -h 0.0.0.0
VALENS_CONFIG=$(CONFIG_FILE) poetry run flask --app valens --debug run -h 0.0.0.0

$(CONFIG_FILE): $(BUILD_DIR)
valens config -d build
Expand Down
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ http {
The following software is required:

- Python 3
- [Poetry](https://python-poetry.org/) with [dynamic versioning plugin](https://github.com/mtkennerly/poetry-dynamic-versioning)
- Rust toolchain
- tmux (optional)

Expand All @@ -124,22 +125,10 @@ Install the Rust development tools.
$ cargo install --locked trunk
```

Create a Python virtual environment.
Install the Python project and development tools.

```console
$ python3 -m venv .venv
```

Activate the virtual environment.

```console
$ . .venv/bin/activate
```

Install the Python development tools and install the package in editable mode.

```console
$ pip install -e ".[devel]"
$ poetry install
```

### Running development servers
Expand Down
Loading

0 comments on commit 1f87a2f

Please sign in to comment.