From 9c7902461a9f2e91f38fbbdb3ef0727db28a6339 Mon Sep 17 00:00:00 2001 From: Wibowo Arindrarto Date: Tue, 23 Jul 2024 22:18:23 +0200 Subject: [PATCH] chore: Use poetry venv for local development --- .envrc | 2 -- Makefile | 5 +++++ flake.nix | 56 +++++++++++++++++++++++++++++-------------------------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/.envrc b/.envrc index edd04e0..a7793d7 100644 --- a/.envrc +++ b/.envrc @@ -7,6 +7,4 @@ fi use flake . --impure -watch_file ./poetry.lock - source_env_if_exists .envrc-private diff --git a/Makefile b/Makefile index 5f0f5e0..cf70a88 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,11 @@ dev: ## Configure local development environment with nix and direnv. fi +.PHONY: dev-reset +dev-reset: ## Resets the local development environment. + rm -rf .venv .direnv && direnv reload + + .PHONY: docs-html docs-html: ## Build HTML documentation. cd $(DOCS_DIR) && LC_ALL=C.UTF_8 make html diff --git a/flake.nix b/flake.nix index 9050085..cd52f19 100644 --- a/flake.nix +++ b/flake.nix @@ -23,21 +23,9 @@ let pkgs = nixpkgs.legacyPackages.${system}; p2n = poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }; - overrides = p2n.overrides.withDefaults ( - # Using wheel since mypy compilation is too long and it is only a dev/test dependency. - _final: prev: { mypy = prev.mypy.override { preferWheel = true; }; } - ); python = pkgs.python312; # NOTE: Keep in-sync with pyproject.toml. pythonPkgs = pkgs.python312Packages; - pythonEnv = p2n.mkPoetryEnv rec { - inherit overrides python; - projectDir = self; - editablePackageSources = { - volt = projectDir; - }; - }; shellPkgs = with pkgs; [ - pythonEnv curl deadnix entr @@ -49,8 +37,12 @@ (poetry.withPlugins (_ps: [ pythonPkgs.poetry-dynamic-versioning ])) ]; app = p2n.mkPoetryApplication { - inherit overrides python; + inherit python; projectDir = self; + overrides = p2n.overrides.withDefaults ( + # Using wheel since mypy compilation is too long and it is only a dev/test dependency. + _final: prev: { mypy = prev.mypy.override { preferWheel = true; }; } + ); }; in { @@ -60,19 +52,31 @@ program = "${app}/bin/${app.pname}"; }; }; - devShells = rec { - ci = pkgs.mkShellNoCC { packages = shellPkgs; }; - default = ci.overrideAttrs ( - _final: prev: { - # Set PYTHONPATH so that changes made in source tree is reflected from - # wherever we are running commands, not just when we are in source root. - shellHook = - prev.shellHook - + '' - export PYTHONPATH=${builtins.getEnv "PWD"}:$PYTHONPATH - ''; - } - ); + devShells = { + ci = pkgs.mkShellNoCC { packages = shellPkgs ++ [ app ]; }; + default = pkgs.mkShellNoCC rec { + nativeBuildInputs = with pkgs; [ + python + pythonPkgs.venvShellHook + taglib + openssl + git + libxml2 + libxslt + libzip + zlib + ]; + packages = shellPkgs; + venvDir = "./.venv"; + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + poetry env use ${venvDir}/bin/python + poetry install + ''; + postShellHook = '' + unset SOURCE_DATE_EPOCH + ''; + }; }; packages = let