Merge pull request #487 from nix-community/editable-path-deps

Add path dependencies where develop=true as editable packages by default
This commit is contained in:
adisbladis 2022-01-05 16:54:30 +00:00 committed by GitHub
commit d5d2f4a77c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View file

@ -74,7 +74,7 @@ Creates an environment that provides a Python interpreter along with all depende
- **poetrylock**: `poetry.lock` file path (_default_: `projectDir + "/poetry.lock"`).
- **overrides**: Python overrides to apply (_default_: `[defaultPoetryOverrides]`).
- **python**: The Python interpreter to use (_default:_ `pkgs.python3`).
- **editablePackageSources**: A mapping from package name to source directory, these will be installed in editable mode (_default:_ `{}`).
- **editablePackageSources**: A mapping from package name to source directory, these will be installed in editable mode. Note that path dependencies with `develop = true` will be installed in editable mode unless explicitly passed to `editablePackageSources` as `null`. (_default:_ `{}`).
- **extraPackages**: A function taking a Python package set and returning a list of extra packages to include in the environment. This is intended for packages deliberately not added to `pyproject.toml` that you still want to include. An example of such a package may be `pip`. (_default:_ `(ps: [ ])`).
#### Example

View file

@ -122,10 +122,10 @@ lib.makeScope pkgs.newScope (self: {
# Example: { my-app = ./src; }
, editablePackageSources ? { }
, __isBootstrap ? false # Hack: Always add Poetry as a build input unless bootstrapping
, pyProject ? readTOML pyproject
}@attrs:
let
poetryPkg = poetry.override { inherit python; };
pyProject = readTOML pyproject;
scripts = pyProject.tool.poetry.scripts or { };
hasScripts = scripts != { };
@ -133,9 +133,11 @@ lib.makeScope pkgs.newScope (self: {
inherit python scripts;
};
hasEditable = editablePackageSources != { };
editablePackageSources' = lib.filterAttrs (name: path: path != null) editablePackageSources;
hasEditable = editablePackageSources' != { };
editablePackage = self.mkPoetryEditablePackage {
inherit pyProject python editablePackageSources;
inherit pyProject python;
editablePackageSources = editablePackageSources';
};
poetryLock = readTOML poetrylock;
@ -267,15 +269,30 @@ lib.makeScope pkgs.newScope (self: {
, extraPackages ? ps: [ ]
}:
let
inherit (lib) elem hasAttr;
pyProject = readTOML pyproject;
# Automatically add dependencies with develop = true as editable packages, but only if path dependencies
getEditableDeps = set: lib.mapAttrs
(name: value: projectDir + "/${value.path}")
(lib.filterAttrs (name: dep: dep.develop or false && hasAttr "path" dep) set);
editablePackageSources' = (
(getEditableDeps (pyProject.tool.poetry."dependencies" or { }))
// (getEditableDeps (pyProject.tool.poetry."dev-dependencies" or { }))
// editablePackageSources
);
poetryPython = self.mkPoetryPackages {
inherit pyproject poetrylock overrides python pwd preferWheels editablePackageSources;
inherit pyproject poetrylock overrides python pwd preferWheels pyProject;
editablePackageSources = editablePackageSources';
};
inherit (poetryPython) poetryPackages;
inherit (lib) elem;
# Don't add editable sources to the environment since they will sometimes fail to build and are not useful in the development env
editableAttrs = lib.attrNames editablePackageSources;
editableAttrs = lib.attrNames editablePackageSources';
envPkgs = builtins.filter (drv: ! lib.elem (drv.pname or drv.name or "") editableAttrs) poetryPackages;
in