From e4eb86659eb7a4a8a6d81382c0f1e2755a3ecb95 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 21 Mar 2024 13:16:34 +1300 Subject: [PATCH] feat: Add Nix support --- .github/workflows/ci.yml | 16 ++++++---------- .gitignore | 1 + .pre-commit-config.yaml | 32 ++++++++++++++++++++++++++++---- shell.nix | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 shell.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cbb7ea..024991e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,16 +13,12 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 - - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + - uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26 + - uses: cachix/cachix-action@18cf96c7c98e048e10a83abd92116114cd8504be # v14 with: - python-version: "3.12.3" - - name: Install - run: | - pip install poetry - poetry install --no-root + name: linz + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - name: Lint & format - run: | - poetry run pre-commit run --all-files + run: nix-shell --pure --run 'pre-commit run --all-files' - name: Test - run: | - poetry run pytest + run: nix-shell --pure --run pytest diff --git a/.gitignore b/.gitignore index de40c11..471b7dd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.pyc __pycache__ /.pytest_cache/ +/python Thumbs.db /.vscode/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 797d555..b0c4f59 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,14 +8,22 @@ repos: name: black entry: black language: system - stages: [commit] + stages: [pre-commit] types: [python] + - id: deadnix + name: deadnix + entry: deadnix + args: [--edit, --fail] + files: \.nix$ + language: system + stages: [pre-commit] + - id: isort name: isort entry: isort language: system - stages: [commit] + stages: [pre-commit] types: [python] - id: mypy @@ -23,14 +31,30 @@ repos: entry: mypy args: [--no-incremental] language: system - stages: [commit] + stages: [pre-commit] types: [python] require_serial: true + - id: nixfmt + name: nixfmt + entry: nixfmt + files: \.nix$ + language: system + stages: [pre-commit] + - id: pylint name: pylint entry: pylint language: system - stages: [commit] + stages: [pre-commit] types: [python] require_serial: true + + - id: statix + name: statix + entry: statix + args: [check] + files: \.nix$ + pass_filenames: false + language: system + stages: [pre-commit] diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..52e1fe9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,33 @@ +let + pkgs = import (builtins.fetchTarball { + name = "nixos-unstable-2024-10-17"; + url = "https://github.com/nixos/nixpkgs/archive/a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c.tar.gz"; + sha256 = "1wn29537l343lb0id0byk0699fj0k07m1n2d7jx2n0ssax55vhwy"; + }) { }; + poetry2nix = import (builtins.fetchTarball { + url = "https://github.com/nix-community/poetry2nix/archive/2024.10.1637698.tar.gz"; + sha256 = "08w14qxgn6rklfc83p8z6h91si854kl6nr1pjhdn8smfx7nw5819"; + }) { inherit pkgs; }; + poetryPackages = poetry2nix.mkPoetryPackages { + projectDir = builtins.path { + path = ./.; + name = "python-linz-logger"; + }; + }; +in +pkgs.mkShell { + packages = [ + pkgs.bashInteractive + pkgs.poetry + pkgs.deadnix + pkgs.gitFull + pkgs.nixfmt-rfc-style + pkgs.statix + poetryPackages.poetryPackages + poetryPackages.python.pkgs.pip # For IDEA package resolution + poetryPackages.python.pkgs.setuptools # For IDEA package resolution + ]; + shellHook = '' + ln --force --no-target-directory --symbolic "${poetryPackages.python}/bin/python" python + ''; +}