mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 16:51:40 -05:00
Automatically build most packages without passing format param
We should never have to use `format = "setuptools"` since pip can _also_ handle setuptools packages. This uses a custom pipBuildHook that removes pyproject.toml in case there is also a setup.py in the same sources.
This commit is contained in:
parent
1158541d5f
commit
b9221f61b5
5 changed files with 76 additions and 5 deletions
|
@ -102,7 +102,7 @@ let
|
|||
# The canonical name is setuptools-scm
|
||||
setuptools-scm = super.setuptools_scm;
|
||||
|
||||
inherit (hooks) removePathDependenciesHook poetry2nixFixupHook;
|
||||
inherit (hooks) pipBuildHook removePathDependenciesHook poetry2nixFixupHook;
|
||||
}
|
||||
)
|
||||
# Null out any filtered packages, we don't want python.pkgs from nixpkgs
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
, callPackage
|
||||
, makeSetupHook
|
||||
, yj
|
||||
, wheel
|
||||
, pip
|
||||
}:
|
||||
let
|
||||
pythonInterpreter = python.pythonForBuild.interpreter;
|
||||
pythonSitePackages = python.sitePackages;
|
||||
in
|
||||
{
|
||||
|
||||
|
@ -21,6 +24,17 @@ in
|
|||
} ./remove-path-dependencies.sh
|
||||
) {};
|
||||
|
||||
pipBuildHook = callPackage (
|
||||
{ pip, wheel }:
|
||||
makeSetupHook {
|
||||
name = "pip-build-hook.sh";
|
||||
deps = [ pip wheel ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter pythonSitePackages;
|
||||
};
|
||||
} ./pip-build-hook.sh
|
||||
) {};
|
||||
|
||||
poetry2nixFixupHook = callPackage (
|
||||
{}:
|
||||
makeSetupHook {
|
||||
|
|
50
hooks/pip-build-hook.sh
Normal file
50
hooks/pip-build-hook.sh
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Setup hook to use for pip projects
|
||||
echo "Sourcing pip-build-hook"
|
||||
|
||||
pipBuildPhase() {
|
||||
echo "Executing pipBuildPhase"
|
||||
runHook preBuild
|
||||
|
||||
# Prefer using setup.py to avoid build-system dependencies if we have a setup.py
|
||||
if [ -z "${dontPreferSetupPy-}" ]; then
|
||||
if test -e setup.py && test -e pyproject.toml; then
|
||||
echo "Removing pyproject.toml..."
|
||||
rm -f pyproject.toml
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p dist
|
||||
echo "Creating a wheel..."
|
||||
@pythonInterpreter@ -m pip wheel --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .
|
||||
echo "Finished creating a wheel..."
|
||||
|
||||
runHook postBuild
|
||||
echo "Finished executing pipBuildPhase"
|
||||
}
|
||||
|
||||
pipShellHook() {
|
||||
echo "Executing pipShellHook"
|
||||
runHook preShellHook
|
||||
|
||||
# Long-term setup.py should be dropped.
|
||||
if [ -e pyproject.toml ]; then
|
||||
tmp_path=$(mktemp -d)
|
||||
export PATH="$tmp_path/bin:$PATH"
|
||||
export PYTHONPATH="$tmp_path/@pythonSitePackages@:$PYTHONPATH"
|
||||
mkdir -p "$tmp_path/@pythonSitePackages@"
|
||||
@pythonInterpreter@ -m pip install -e . --prefix "$tmp_path" >&2
|
||||
fi
|
||||
|
||||
runHook postShellHook
|
||||
echo "Finished executing pipShellHook"
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePipBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
||||
echo "Using pipBuildPhase"
|
||||
buildPhase=pipBuildPhase
|
||||
fi
|
||||
|
||||
if [ -z "${shellHook-}" ]; then
|
||||
echo "Using pipShellHook"
|
||||
shellHook=pipShellHook
|
||||
fi
|
|
@ -6,7 +6,14 @@ import sys
|
|||
|
||||
data = json.load(sys.stdin)
|
||||
|
||||
for dep in data['tool']['poetry']['dependencies'].values():
|
||||
|
||||
def get_deep(o, path):
|
||||
for p in path.split('.'):
|
||||
o = o.get(p, {})
|
||||
return o
|
||||
|
||||
|
||||
for dep in get_deep(data, 'tool.poetry.dependencies').values():
|
||||
if isinstance(dep, dict):
|
||||
try:
|
||||
del dep['path'];
|
||||
|
|
|
@ -74,10 +74,10 @@ pythonPackages.callPackage (
|
|||
format =
|
||||
if _isEgg then "egg"
|
||||
else if lib.strings.hasSuffix ".whl" name then "wheel"
|
||||
else "setuptools";
|
||||
else "pyproject";
|
||||
kind =
|
||||
if _isEgg then python.pythonVersion
|
||||
else if format == "setuptools" then "source"
|
||||
else if format == "pyproject" then "source"
|
||||
else (builtins.elemAt (lib.strings.splitString "-" name) 2);
|
||||
};
|
||||
|
||||
|
@ -89,7 +89,7 @@ pythonPackages.callPackage (
|
|||
];
|
||||
baseBuildInputs = lib.optional (! lib.elem name skipSetupToolsSCM) pythonPackages.setuptools-scm;
|
||||
|
||||
format = if isLocal then "pyproject" else if isGit then "setuptools" else fileInfo.format;
|
||||
format = if isLocal then "pyproject" else if isGit then "pyproject" else fileInfo.format;
|
||||
in
|
||||
|
||||
buildPythonPackage {
|
||||
|
|
Loading…
Add table
Reference in a new issue