-
-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
editablePackageSources
doesn't work for packages in a src
directory
#1641
Comments
I'm facing the same issue and I have no solution, but I want to at least thank you for sharing a working flake that demonstrates |
I found this in another issue which seems related: #425 . Potentially it's a feature of flakes more so than a bug with poetry2nix? |
Hmm yeah I think you are right, though still strange that it seems to work better without the |
I think it's a I'm thinking the way to go is editablePackageSources = {
myProject = "${builtins.getEnv "PWD"}/src";;
} as discussed in #425 and https://discourse.nixos.org/t/editable-python-environment-with-poetry2nix/44520 |
Ok actually I found a few interesting issues and a workaround that seems to work. Firstly, I've confirmed that without flakes { pkgs ? import <nixpkgs> {} }:
let
poetry2nix = pkgs.callPackage (pkgs.fetchgit {
url = "https://github.com/nix-community/poetry2nix.git";
rev = "7619e43c2b48c29e24b88a415256f09df96ec276";
sha256 = "sha256-gD0N0pnKxWJcKtbetlkKOIumS0Zovgxx/nMfOIJIzoI=";
}) {};
mkPoetryEnv = poetry2nix.mkPoetryEnv;
in
pkgs.mkShell {
buildInputs = [
(mkPoetryEnv {
projectDir = ./.;
editablePackageSources = {
app = ./src;
};
})
pkgs.poetry
];
} If you enter the shell and check the following: $ nix-shell
$ python
>>> import sys
>>> print(sys.path)
['', '/paths/in/the/nix/store', ..., '/abs/path/to/project/src']
>>> import app
>>> print(app.__file__)
'/abs/path/to/project/src/app/__init__.py' However, with the equivalent flake {
description = "Application packaged using poetry2nix";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEnv;
in
{
devShells.default = pkgs.mkShell {
inputsFrom = [ self.devShells.${system}.pythonEnv.env ];
};
devShells.pythonEnv = mkPoetryEnv {
projectDir = ./.;
editablePackageSources = {
app = ./src;
};
};
});
} The behavior is different $ nix develop
$ python
>>> import sys
>>> print(sys.path)
['', '/paths/in/the/nix/store', ..., '/path/in/the/nix/store/src']
>>> import app
>>> print(app.__file__)
'/path/in/the/nix/store/src/app/__init__.py' Modifying Instead, what does seem to work is using {
description = "Application packaged using poetry2nix";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
poetry2nix = {vim
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEnv;
in
{
devShells.default = pkgs.mkShell {
inputsFrom = [ self.devShells.${system}.pythonEnv.env ];
shellHook = ''
export PYTHONPATH=$PWD/src:$PYTHONPATH
'';
};
devShells.pythonEnv = mkPoetryEnv {
projectDir = ./.;
};
});
} This sort of works although it is not identical to the $ nix develop
$ python
>>> import sys
>>> print(sys.path)
['', '/abs/path/to/project/src', '/abs/path/to/project', '/paths/in/the/nix/store', ..., ]
>>> import app
>>> print(app.__file__)
'/abs/path/to/project/src/app/__init__.py' This will only work when you run I also tried Likely the reason it works with a flake without |
Well done, yeah it seems like you are correct. A bit annoying that this is the case, and at least I can't see any easy way of fixing this, this just seems like python and nix not being friends (as usual). For the record, one detail which has made it easier for me to work with this is using ...
apps = {
testing = {
type = "app";
program = "${myapp-env}/bin/testing";
};
}; Then instead of running |
Describe the issue
When a package is in a
src
directory, theeditablePackageSources
attribute doesn't work.Additional context
Set up a package
app
in the main directory, with a single__init__.py
file:If the
flake.nix
andpyproject.toml
files are set up like this:default.nix
/shell.nix
/flake.nix
:pyproject.toml
:poetry.lock
:The result is that changing the main function in
app/__init__.py
will change the behaviour of thetesting
script (within the devshell defined in the flake).If this
app
package is moved to asrc
folder, and the following changes are applied to theflake.nix
andpyproject.toml
files, this behaviour is lost, and only recompiling the project will apply the changes. The only changes are changing theeditablePackageSources.app
attribute from./.
to./src
in theflake.nix
file, and addingpackages = [{include="app", from="src}]
to the[tool.poetry]
field of thepyproject.toml
file:default.nix
/shell.nix
/flake.nix
:pyproject.toml
:poetry.lock
:The text was updated successfully, but these errors were encountered: