Skip to content

Commit

Permalink
chore: Use poetry venv for local development
Browse files Browse the repository at this point in the history
  • Loading branch information
bow committed Jul 23, 2024
1 parent cf14e83 commit 9c79024
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
2 changes: 0 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ fi

use flake . --impure

watch_file ./poetry.lock

source_env_if_exists .envrc-private
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 30 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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
Expand Down

0 comments on commit 9c79024

Please sign in to comment.