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 9e0d623
Show file tree
Hide file tree
Showing 7 changed files with 1,765 additions and 143 deletions.
72 changes: 38 additions & 34 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ 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:
name: Frontend Checks
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx inject poetry poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Set up Rust
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
run: |
pip install setuptools_scm
- 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 inject poetry 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 inject poetry 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 All @@ -91,6 +92,10 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx inject poetry poetry-dynamic-versioning==${{ env.POETRY_DYNAMIC_VERSIONING_VERSION }}
- name: Set up Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${{ env.RUST_VERSION }} --profile minimal
Expand All @@ -108,18 +113,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 inject poetry 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 +136,15 @@ jobs:
python-version: "3.10"
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
pipx inject poetry 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 +155,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
20 changes: 10 additions & 10 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 All @@ -30,20 +30,20 @@ check_frontend:
check_backend: check_black check_ruff check_mypy

check_black:
black --check --diff $(PYTHON_PACKAGES)
poetry run black --check --diff $(PYTHON_PACKAGES)

check_ruff:
ruff check $(PYTHON_PACKAGES)
poetry run ruff check $(PYTHON_PACKAGES)

check_mypy:
mypy --pretty $(PYTHON_PACKAGES)
poetry run mypy --pretty $(PYTHON_PACKAGES)

.PHONY: format

format:
cargo fmt --manifest-path=frontend/Cargo.toml
ruff --fix-only $(PYTHON_PACKAGES) | true
black $(PYTHON_PACKAGES)
poetry run ruff --fix-only $(PYTHON_PACKAGES) | true
poetry run black $(PYTHON_PACKAGES)

.PHONY: test test_frontend test_backend test_e2e

Expand All @@ -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
7 changes: 2 additions & 5 deletions frontend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
use std::process::Command;

fn main() {
let output = Command::new("python")
.args([
"-c",
"from setuptools_scm import get_version; print(get_version(root='..'))",
])
let output = Command::new("poetry")
.args(["version", "-s"])
.output()
.unwrap();
let version = String::from_utf8(output.stdout).unwrap();
Expand Down
Loading

0 comments on commit 9e0d623

Please sign in to comment.