Skip to content

Commit

Permalink
feat: Support Nix for development
Browse files Browse the repository at this point in the history
- Cache Python packages in CI using the "linz" repository
- Lint and format the Nix code
- Create a symlink to the Python executable for easy IDE integration
- Use the same version of Geos as in Ubuntu
  • Loading branch information
l0b0 committed Sep 23, 2024
1 parent 9c52fef commit 310134c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 19 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/format-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ jobs:
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4
with:
python-version: "3.12.3"
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
- uses: cachix/cachix-action@18cf96c7c98e048e10a83abd92116114cd8504be # v14
with:
name: linz
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Format
run: nix-shell --pure --run 'pre-commit run --all-files'
- name: Install
run: |
pip install poetry
poetry install --no-root
- name: Format
run: |
poetry run pre-commit run --all-files
- name: Unit Tests
run: |
poetry run pytest --doctest-modules .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.pyc
__pycache__
/.pytest_cache
/python
Thumbs.db
/.venv
/.vscode
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ repos:
stages: [commit]
types: [python]

- id: deadnix
name: deadnix
entry: deadnix
args: [--edit, --fail]
files: \.nix$
language: system
stages: [commit]

- id: gitlint
name: gitlint
entry: gitlint
Expand All @@ -34,6 +42,13 @@ repos:
types: [python]
require_serial: true

- id: nixfmt
name: nixfmt
entry: nixfmt
files: \.nix$
language: system
stages: [commit]

- id: pylint
name: pylint
entry: pylint
Expand All @@ -42,6 +57,15 @@ repos:
types: [python]
require_serial: true

- id: statix
name: statix
entry: statix
args: [check]
files: \.nix$
pass_filenames: false
language: system
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: a99a3fbe79a9d346cabd02a5e167ad0edafe616b # v2.3.0
hooks:
Expand Down
16 changes: 1 addition & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ pytest = "*"
pytest-dependency = "*"
pytest-mock = "*"
pytest-subtests = "*"
shellcheck-py = "*"
48 changes: 48 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
let
pkgs = import (builtins.fetchTarball {
name = "nixos-unstable-2024-09-17";
url = "https://github.com/nixos/nixpkgs/archive/345c263f2f53a3710abe117f28a5cb86d0ba4059.tar.gz";
sha256 = "1llzyzw7a0jqdn7p3px0sqa35jg24v5pklwxdybwbmbyr2q8cf5j";
}) { overlays = [ (_final: prev: { geos = prev.geos_3_11; }) ]; };
poetry2nix = import (builtins.fetchTarball {
url = "https://github.com/nix-community/poetry2nix/archive/2024.9.1542864.tar.gz";
sha256 = "06vz5hwylvjvx4ywbv4y3kadq8zxmvpf5h7pjy6w1yhkwpjd6k25";
}) { inherit pkgs; };
poetryPackages = poetry2nix.mkPoetryPackages {
projectDir = ./.;
python = pkgs.python312;
overrides = poetry2nix.overrides.withDefaults (
final: prev: {
cryptography = prev.cryptography.overridePythonAttrs (
# TODO: Remove when <URL> is in poetry2nix
old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
final.distutils
];
}
);
}
);
};
pythonWithPackages = poetryPackages.python.withPackages (_ps: poetryPackages.poetryPackages);
in
pkgs.mkShell {
packages = [
pythonWithPackages
pkgs.bashInteractive
pkgs.cacert
pkgs.deadnix
pkgs.gcc # To install Python debugging in IDEA
pkgs.gdal
pkgs.gitFull
pkgs.nixfmt-rfc-style
pkgs.nodejs
pkgs.poetry
pkgs.shellcheck
pkgs.statix
pkgs.which
];
shellHook = ''
ln --force --no-target-directory --symbolic "${pkgs.lib.getExe pythonWithPackages}" python
'';
}

0 comments on commit 310134c

Please sign in to comment.