-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python3Packages.mkPythonEditablePackage: init
- Loading branch information
1 parent
12fb820
commit 41611f8
Showing
4 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
buildPythonPackage, | ||
lib, | ||
hatchling, | ||
formats, | ||
}: | ||
{ | ||
pname, | ||
version, | ||
|
||
# Editable root as string. | ||
# Environment variables will be expanded at runtime using os.path.expandvars. | ||
root, | ||
|
||
# Arguments passed on verbatim to buildPythonPackage | ||
derivationArgs ? { }, | ||
|
||
# Python dependencies | ||
dependencies ? [ ], | ||
optional-dependencies ? { }, | ||
|
||
# PEP-518 build-system https://peps.python.org/pep-518 | ||
build-system ? [ ], | ||
|
||
# PEP-621 entry points https://peps.python.org/pep-0621/#entry-points | ||
scripts ? { }, | ||
gui-scripts ? { }, | ||
entry-points ? { }, | ||
|
||
passthru ? { }, | ||
meta ? { }, | ||
}: | ||
|
||
# Create a PEP-660 (https://peps.python.org/pep-0660/) editable package pointing to an impure location outside the Nix store. | ||
# The primary use case of this function is to enable local development workflows where the local package is installed into a virtualenv-like environment using withPackages. | ||
|
||
assert lib.isString root; | ||
let | ||
# In editable mode build-system's are considered to be runtime dependencies. | ||
dependencies' = dependencies ++ build-system; | ||
|
||
pyproject = { | ||
# PEP-621 project table | ||
project = { | ||
name = pname; | ||
inherit | ||
version | ||
scripts | ||
gui-scripts | ||
entry-points | ||
; | ||
dependencies = map lib.getName (dependencies'); | ||
optional-dependencies = lib.mapAttrs (_: lib.getName) optional-dependencies; | ||
}; | ||
|
||
# Allow empty package | ||
tool.hatch.build.targets.wheel.bypass-selection = true; | ||
|
||
# Include our editable pointer file in build | ||
tool.hatch.build.targets.wheel.force-include."_${pname}.pth" = "_${pname}.pth"; | ||
|
||
# Build editable package using hatchling | ||
build-system = { | ||
requires = [ "hatchling" ]; | ||
build-backend = "hatchling.build"; | ||
}; | ||
}; | ||
|
||
pyproject' = (formats.toml { }).generate "pyproject.toml" pyproject; | ||
|
||
in | ||
buildPythonPackage ( | ||
{ | ||
inherit | ||
pname | ||
version | ||
optional-dependencies | ||
passthru | ||
meta | ||
; | ||
dependencies = dependencies'; | ||
|
||
pyproject = true; | ||
|
||
unpackPhase = '' | ||
cp ${pyproject'} pyproject.toml | ||
echo 'import os.path, sys; sys.path.insert(0, os.path.expandvars("${root}"))' > _${pname}.pth | ||
''; | ||
|
||
build-system = [ hatchling ]; | ||
} | ||
// derivationArgs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters