From 0fe959ee52999c6cc161f4c1a2f74681c8145369 Mon Sep 17 00:00:00 2001 From: Constantin Gahr Date: Wed, 11 Sep 2024 10:01:20 +0200 Subject: [PATCH 1/5] add flake.nix for project environment --- flake.lock | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 53 ++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..777b51f --- /dev/null +++ b/flake.lock @@ -0,0 +1,118 @@ +{ + "nodes": { + "mdbook-nixdoc": { + "inputs": { + "nix-github-actions": [ + "pyproject-nix", + "nix-github-actions" + ], + "nixpkgs": [ + "pyproject-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1708395692, + "narHash": "sha256-smf0VmxGbjJDZqKvxxG3ZVqubgbVwAWG26wPo+BT/A0=", + "owner": "adisbladis", + "repo": "mdbook-nixdoc", + "rev": "d6a71b114b9221c0b4f20d31b81766d072cc26be", + "type": "github" + }, + "original": { + "owner": "adisbladis", + "repo": "mdbook-nixdoc", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "pyproject-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720066371, + "narHash": "sha256-uPlLYH2S0ACj0IcgaK9Lsf4spmJoGejR9DotXiXSBZQ=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "622f829f5fe69310a866c8a6cd07e747c44ef820", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725983898, + "narHash": "sha256-4b3A9zPpxAxLnkF9MawJNHDtOOl6ruL0r6Og1TEDGCE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "1355a0cbfeac61d785b7183c0caaec1f97361b43", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pyproject-nix": { + "inputs": { + "mdbook-nixdoc": "mdbook-nixdoc", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1726093189, + "narHash": "sha256-aPzd6M1k1H0C2zoMlSfAdTg4Za+WfB8Qj+OAbQAVAMs=", + "owner": "nix-community", + "repo": "pyproject.nix", + "rev": "6c56846759ba16382bc2bdbee42c2f56c21654be", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "pyproject-nix": "pyproject-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "pyproject-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1724833132, + "narHash": "sha256-F4djBvyNRAXGusJiNYInqR6zIMI3rvlp6WiKwsRISos=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "3ffd842a5f50f435d3e603312eefa4790db46af5", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f449513 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + + pyproject-nix = { + url = "github:nix-community/pyproject.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + pyproject-nix, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + + project = pyproject-nix.lib.project.loadPyproject { projectRoot = ./.; }; + python = pkgs.python312; + in + { + devShells.default = + let + attrs = project.renderers.withPackages { + inherit python; + extras = [ "tests" ]; + extraPackages = python-pkgs: [ python-pkgs.ipykernel ]; + }; + pythonEnv = python.withPackages attrs; + in + pkgs.mkShell { + packages = + [ pythonEnv ] + ++ (with pkgs; [ + ruff + pre-commit + ]); + shellHook = '' + export PYTHONPATH="$(pwd)/src" + ''; + }; + } + ); +} From 696e954c0c007b768b0d5b2fdc4d2444286dce07 Mon Sep 17 00:00:00 2001 From: Constantin Gahr Date: Wed, 11 Sep 2024 10:10:33 +0200 Subject: [PATCH 2/5] update .envrc --- .envrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.envrc b/.envrc index 175de89..4819b0d 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ -layout python +watch_file pyproject.toml +use flake From 70e411efcb734f77335fb3defb23b20352497d77 Mon Sep 17 00:00:00 2001 From: Constantin Gahr Date: Wed, 11 Sep 2024 10:15:44 +0200 Subject: [PATCH 3/5] dont track .envrc --- .envrc => .envrc.default | 0 .gitignore | 2 ++ 2 files changed, 2 insertions(+) rename .envrc => .envrc.default (100%) diff --git a/.envrc b/.envrc.default similarity index 100% rename from .envrc rename to .envrc.default diff --git a/.gitignore b/.gitignore index f71cc31..611ca26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.envrc + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From 1c41591f52ecad72e168ea3fa74881e24a7d547a Mon Sep 17 00:00:00 2001 From: Constantin Gahr Date: Wed, 11 Sep 2024 15:03:00 +0200 Subject: [PATCH 4/5] workaround for pre-commit ruff on nixos --- .pre-commit-config.yaml | 10 +--------- flake.lock | 34 ++++++++++++++++++++++++++++++++++ flake.nix | 3 +++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5067311..43a6864 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,12 +42,4 @@ repos: hooks: - id: mypy exclude: tests - - repo: local - hooks: - - id: pytest - name: pytest - entry: pytest - language: python - pass_filenames: false - always_run: true -fail_fast: true +fail_fast: false diff --git a/flake.lock b/flake.lock index 777b51f..ae2c6bc 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,23 @@ { "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "mdbook-nixdoc": { "inputs": { "nix-github-actions": [ @@ -87,10 +105,26 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "pyproject-nix": "pyproject-nix" } }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": [ diff --git a/flake.nix b/flake.nix index f449513..336f66f 100644 --- a/flake.nix +++ b/flake.nix @@ -43,9 +43,12 @@ ++ (with pkgs; [ ruff pre-commit + rustc # for pre-commit ruff + cargo # for pre-commit ruff ]); shellHook = '' export PYTHONPATH="$(pwd)/src" + export PIP_NO_BINARY="ruff" ''; }; } From b1f68932196a367b448fc3498b4f5b5a2e145fd9 Mon Sep 17 00:00:00 2001 From: Constantin Gahr Date: Thu, 12 Sep 2024 10:50:23 +0200 Subject: [PATCH 5/5] remove skip pytest instruction --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43a6864..f2419ee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,4 @@ ci: - skip: [pytest] autoupdate_schedule: monthly autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' repos: