Skip to content

Commit

Permalink
feat: Set up devbox
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 4, 2023
1 parent 4feafdd commit 76a40fe
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 107 deletions.
40 changes: 8 additions & 32 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,27 @@ jobs:
tests:
name: Run tests

strategy:
matrix:
python-version: ["3.10", "3.11"]
os: ["ubuntu-latest"]

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# Installing via `pipx` is 'fully supported', so no need for
# https://github.com/snok/install-poetry, which is a bit slower. See also
# https://python-poetry.org/docs/master/#installing-with-pipx
- name: Install Poetry
run: pipx install poetry

# Counterintuitively, the Python setup step itself is setup *after* installing
# `poetry`, else the `poetry` command isn't found and the setup step fails. See
# also:
# https://github.com/marketplace/actions/setup-python#caching-packages-dependencies
- uses: actions/setup-python@v4
- name: Install devbox
uses: jetpack-io/[email protected]
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Set up Python environment
# `poetry env use` instructs all `poetry` runs to go through the correct (NOT
# the default aka system) Python environment, see also:
# https://github.com/actions/setup-python/issues/374#issuecomment-1088938718
# As long as we then call all actions via `poetry run ...`, we're fine.
run: |
poetry env use ${{ matrix.python-version }}
poetry install
enable-cache: true

- name: Run linting
run: make lint
run: devbox run lint

- name: Check code formatting
run: make formatcheck
run: devbox run formatcheck

- name: Run type checks
run: make typecheck
run: devbox run typecheck

- name: Run tests
run: make test
run: devbox run test
env:
# Unit tests actually run against the GH API for 'real integration testing',
# and providing a token will increase the otherwise too-low rate limit.
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: lint
name: Run linting
language: system
entry: make lint
entry: devbox run lint
stages:
- "commit"
- "push"
Expand All @@ -20,7 +20,7 @@ repos:
- id: check-formatting
name: Check formatting
language: system
entry: make formatcheck
entry: devbox run formatcheck
stages:
- "commit"
- "push"
Expand All @@ -32,7 +32,7 @@ repos:
- id: run-typecheck
name: Run typecheck
language: system
entry: make typecheck
entry: devbox run typecheck
stages:
- "commit"
- "push"
Expand All @@ -44,7 +44,7 @@ repos:
- id: run-tests
name: Run tests
language: system
entry: make test
entry: devbox run test
stages:
- "commit"
- "push"
Expand All @@ -56,6 +56,6 @@ repos:
- id: build-image
name: Build image
language: system
entry: make image
entry: devbox run build-image
stages:
- "push"
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

23 changes: 11 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

## Environment setup

Sadly, the setup cannot be automated arbitrarily (say, using a `make init` target).
Installing `poetry` requires system packages (`python3`, `pip`, `curl`) that cannot be easily installed on the user's behalf in a distribution-independent way.
Further, inserting `poetry` in one's `$PATH` is best done manually and consciously (environments, user desires etc. differ too much).
[![Built with Devbox](https://jetpack.io/img/devbox/shield_moon.svg)](https://jetpack.io/devbox/docs/contributor-quickstart/)

1. [Install `poetry`](https://python-poetry.org/docs/master/#installing-with-the-official-installer).
Use devbox to set up a development environment.
Refer to [the available `script`s](devbox.json) to see what's possible.
Generally, even when running in a `devbox shell`, `poetry run` is necessary:

If you're having trouble with version mismatch, check which version the `poetry` installation currently uses in the [CI](https://github.com/alexpovel/ancv/actions).
2. Run `poetry install` in the root directly (where the [`pyproject.toml`](./pyproject.toml) is located).
- devbox sets up what used to be system-wide packages (Python, poetry, ...) deterministically and automatically
- within the devbox virtual environment, we still manage and use a Python virtual environment through `poetry run`

`poetry` will throw an error here if your Python version isn't supported by the project.
If that is the case, look into using [`pyenv`](https://github.com/pyenv/pyenv), which will use the version specified in [`.python-version`](.python-version), guaranteeing a version match.
3. Enter into the created environment with `poetry shell`.
That way, we get the normal Python package management for normal Python packages (`ruff`, `black`, `pytest`, ...), and devbox for the overarching rest.

*Alternatively*, prepend all commands pertaining to the repository with `poetry run`, like `poetry run python -m ancv`.
4. Set up `git` hooks provided by [`pre-commit`](https://pre-commit.com/#intro) (already installed through `poetry`): `make hooks`.
Lastly, for bonus points, set up pre-commit hooks:

For this to work, you will have to have `make` installed (Windows alternatives exist).
```bash
devbox run install-hooks
```

## Creating components

Expand Down
57 changes: 0 additions & 57 deletions Makefile

This file was deleted.

28 changes: 28 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"packages": [
"python@3",
"[email protected]",
"graphviz@8",
"pre-commit@3"
],
"env": {
"LIBRARY": "ancv"
},
"shell": {
"init_hook": [
"echo 'Running command in devbox shell...'",
"poetry install"
],
"scripts": {
"build-image": "docker build --progress=plain --tag ${LIBRARY}/${LIBRARY} .",
"format-check": "poetry run black --check --diff \"LIBRARY\"",
"install-hooks": "pre-commit install --hook-type pre-push --hook-type pre-commit --hook-type commit-msg",
"lint": "poetry run ruff .",
"make-depgraph.svg": "poetry run pydeps --max-bacon=4 --cluster -T svg -o depgraph.svg \"$LIBRARY\"",
"make-github.py": "poetry run datamodel-codegen --url \"https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/dereferenced/api.github.com.deref.json\" --encoding utf-8 --input-file-type openapi --openapi-scopes paths --output github.py",
"make-resume.py": "poetry run datamodel-codegen --url \"https://raw.githubusercontent.com/jsonresume/resume-schema/master/schema.json\" --encoding utf-8 --input-file-type jsonschema --output resume.py",
"test": "poetry run pytest --cov=\"LIBRARY\" --cov-report=html --cov-report=term --cov-report=xml",
"typecheck": "poetry run mypy -p \"$LIBRARY\""
}
}
}
30 changes: 30 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"lockfile_version": "1",
"packages": {
"graphviz@8": {
"last_modified": "2023-07-23T03:35:12Z",
"resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#graphviz",
"source": "devbox-search",
"version": "8.0.5"
},
"[email protected]": {
"last_modified": "2023-07-23T03:35:12Z",
"resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#poetry",
"source": "devbox-search",
"version": "1.5.1"
},
"pre-commit@3": {
"last_modified": "2023-06-30T04:44:22Z",
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#pre-commit",
"source": "devbox-search",
"version": "3.3.3"
},
"python@3": {
"last_modified": "2023-07-30T12:29:02Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/3acb5c4264c490e7714d503c7166a3fde0c51324#python312",
"source": "devbox-search",
"version": "3.12.0b4"
}
}
}

0 comments on commit 76a40fe

Please sign in to comment.