Skip to content
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

Python: change bootstrapping. #248866

Merged
merged 32 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5d2290b
python3.pkgs.bootstrap.flit-core: init at 3.8.0
tjni Jul 26, 2023
8fe3d15
python3.pkgs.bootstrap.installer: init at 0.7.0
tjni Jul 26, 2023
b53cef7
python3.pkgs.bootstrap.build: init at 0.10.0
tjni Jul 26, 2023
a4d66bc
python3.pkgs.pypaInstallHook: init
tjni Jul 28, 2023
93d25dd
python3.pkgs.pypaBuildHook: switch to pyproject-build
tjni Jul 28, 2023
e8cca49
python2.{buildPythonPackage,buildPythonApplication}: extract into its…
tjni Aug 2, 2023
6c85fff
python3.pkgs.buildPythonPackage: switch to PyPA build and installer
tjni Jul 28, 2023
0d76478
python3.pkgs.installer: move tests to passthru
tjni Jul 28, 2023
349f57f
python3.pkgs.pyproject-hooks: move tests to passthru
tjni Jul 28, 2023
e1cafe6
python3.pkgs.build: move tests to passthru
tjni Jul 28, 2023
4e7188c
python3.pkgs.buildPythonPackage: disable conflict check for setuptool…
tjni Jul 28, 2023
dd1256d
python3.pkgs.pythonRelaxDepsHook: don't propagate wheel
tjni Aug 2, 2023
3cd71e0
python3.pkgs.wheel: 0.38.4 -> 0.41.1
tjni Jul 28, 2023
6b63908
poetry2nix.overrides.wheel: adapt to new wheel version
tjni Aug 2, 2023
253a291
poetry2nix.overrides: update build systems for bootstrap packages
tjni Aug 2, 2023
5a9dda2
python3.pkgs.setuptools: build without bootstrapped-pip
tjni Jul 28, 2023
ab55437
python3.pkgs.pip: build without bootstrapped-pip
tjni Jul 28, 2023
e60ec67
python3.pkgs.cypari2: build without bootstrapped-pip
tjni Jul 28, 2023
43c7517
python3.pkgs.pip: 23.0.1 -> 23.2.1
tjni Jul 29, 2023
d7fea44
python3.pkgs.pip-tools: 6.13.0 -> 7.2.0
tjni Jul 31, 2023
b56b0dd
python3.pkgs.setuptools: 67.4.0 -> 68.0.0
tjni Jul 29, 2023
a9b7086
python310Packages.attrs: 22.2.0 -> 23.1.0
natsukium Aug 1, 2023
9c363cc
python3.pkgs.pip: install shell completions
tjni Aug 12, 2023
39fc433
python3.pkgs.jedi: 0.18.2 -> 0.19.0
tjni Aug 17, 2023
6c1313a
python3.pkgs.scramp: remove versioningit reference
tjni Aug 17, 2023
db40116
python3.pkgs.pyproject-api: 1.5.0 -> 1.5.4
tjni Aug 17, 2023
1f47268
awsebcli: fixup, remove scripts from setup.py
kirillrdy Aug 18, 2023
84503a6
python3.pkgs.scipy: Don't relax deps twice
doronbehar Aug 18, 2023
854302c
python3.pkgs.scipy: Fix some issues in update script
doronbehar Aug 18, 2023
bc1fea4
python3.pkgs.scipy: 1.11.1 -> 1.11.2
doronbehar Aug 18, 2023
3c3fd2f
home-assistant: unpin and fix build dependencies
tjni Aug 19, 2023
3229b1e
home-assistant-intents: fix package
FRidh Aug 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions pkgs/development/interpreters/python/hooks/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
self: dontUse: with self;

let
pythonInterpreter = python.pythonForBuild.interpreter;
inherit (python) pythonForBuild;
pythonInterpreter = pythonForBuild.interpreter;
pythonSitePackages = python.sitePackages;
pythonCheckInterpreter = python.interpreter;
setuppy = ../run_setup.py;
Expand Down Expand Up @@ -66,11 +67,9 @@ in {
makePythonHook {
name = "pypa-build-hook.sh";
propagatedBuildInputs = [ build wheel ];
substitutions = {
inherit pythonInterpreter;
};
} ./pypa-build-hook.sh) {};

} ./pypa-build-hook.sh) {
inherit (pythonForBuild.pkgs) build;
};

pipInstallHook = callPackage ({ makePythonHook, pip }:
makePythonHook {
Expand All @@ -81,6 +80,17 @@ in {
};
} ./pip-install-hook.sh) {};

pypaInstallHook = callPackage ({ makePythonHook, installer }:
makePythonHook {
name = "pypa-install-hook";
propagatedBuildInputs = [ installer ];
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
} ./pypa-install-hook.sh) {
inherit (pythonForBuild.pkgs) installer;
};

pytestCheckHook = callPackage ({ makePythonHook, pytest }:
makePythonHook {
name = "pytest-check-hook";
Expand Down Expand Up @@ -134,9 +144,8 @@ in {
pythonRelaxDepsHook = callPackage ({ makePythonHook, wheel }:
makePythonHook {
name = "python-relax-deps-hook";
propagatedBuildInputs = [ wheel ];
substitutions = {
inherit pythonInterpreter;
inherit pythonInterpreter pythonSitePackages wheel;
};
} ./python-relax-deps-hook.sh) {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pypaBuildPhase() {
runHook preBuild

echo "Creating a wheel..."
@pythonInterpreter@ -m build --no-isolation --outdir dist/ --wheel $pypaBuildFlags
pyproject-build --no-isolation --outdir dist/ --wheel $pypaBuildFlags
echo "Finished creating a wheel..."

runHook postBuild
Expand Down
21 changes: 21 additions & 0 deletions pkgs/development/interpreters/python/hooks/pypa-install-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Setup hook for PyPA installer.
echo "Sourcing pypa-install-hook"

pypaInstallPhase() {
echo "Executing pypaInstallPhase"
runHook preInstall

for wheel in dist/*.whl; do
@pythonInterpreter@ -m installer --prefix "$out" "$wheel"
done

export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH"

runHook postInstall
echo "Finished executing pypaInstallPhase"
}

if [ -z "${dontUsePypaInstall-}" ] && [ -z "${installPhase-}" ]; then
echo "Using pypaInstallPhase"
installPhase=pypaInstallPhase
fi
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ pythonRelaxDepsHook() {

# We generally shouldn't have multiple wheel files, but let's be safer here
for wheel in "$pkg_name"*".whl"; do
@pythonInterpreter@ -m wheel unpack --dest "$unpack_dir" "$wheel"
PYTHONPATH="@wheel@/@pythonSitePackages@:$PYTHONPATH" \
@pythonInterpreter@ -m wheel unpack --dest "$unpack_dir" "$wheel"
rm -rf "$wheel"

# Using no quotes on purpose since we need to expand the glob from `$metadata_file`
Expand All @@ -96,7 +97,8 @@ pythonRelaxDepsHook() {
cat $metadata_file
fi

@pythonInterpreter@ -m wheel pack "$unpack_dir/$pkg_name"*
PYTHONPATH="@wheel@/@pythonSitePackages@:$PYTHONPATH" \
@pythonInterpreter@ -m wheel pack "$unpack_dir/$pkg_name"*
done

# Remove the folder since it will otherwise be in the dist output.
Expand Down
51 changes: 42 additions & 9 deletions pkgs/development/interpreters/python/mk-python-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
, update-python-libraries
, setuptools
, flitBuildHook
, pipBuildHook
, pipInstallHook
, pypaBuildHook
, pypaInstallHook
, pythonCatchConflictsHook
, pythonImportsCheckHook
, pythonNamespacesHook
Expand Down Expand Up @@ -161,6 +161,20 @@ let

in inputs: builtins.map (checkDrv) inputs;

isBootstrapInstallPackage = builtins.elem (attrs.pname or null) [
"flit-core" "installer"
];

isBootstrapPackage = isBootstrapInstallPackage || builtins.elem (attrs.pname or null) ([
"build" "packaging" "pyproject-hooks" "wheel"
] ++ lib.optionals (python.pythonOlder "3.11") [
"tomli"
]);

isSetuptoolsDependency = builtins.elem (attrs.pname or null) [
"setuptools" "wheel"
];

# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
self = toPythonModule (stdenv.mkDerivation ((builtins.removeAttrs attrs [
"disabled" "checkPhase" "checkInputs" "nativeCheckInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "format"
Expand All @@ -174,7 +188,15 @@ let
wrapPython
ensureNewerSourcesForZipFilesHook # move to wheel installer (pip) or builder (setuptools, flit, ...)?
pythonRemoveTestsDirHook
] ++ lib.optionals catchConflicts [
] ++ lib.optionals (catchConflicts && !isBootstrapPackage && !isSetuptoolsDependency) [
#
# 1. When building a package that is also part of the bootstrap chain, we
# must ignore conflicts after installation, because there will be one with
# the package in the bootstrap.
#
# 2. When a package is a dependency of setuptools, we must ignore conflicts
# because the hook that checks for conflicts uses setuptools.
#
pythonCatchConflictsHook
] ++ lib.optionals removeBinBytecode [
pythonRemoveBinBytecodeHook
Expand All @@ -184,15 +206,26 @@ let
setuptoolsBuildHook
] ++ lib.optionals (format == "flit") [
flitBuildHook
] ++ lib.optionals (format == "pyproject") [
pipBuildHook
] ++ lib.optionals (format == "wheel") [
] ++ lib.optionals (format == "pyproject") [(
if isBootstrapPackage then
pypaBuildHook.override {
inherit (python.pythonForBuild.pkgs.bootstrap) build;
wheel = null;
}
else
pypaBuildHook
)] ++ lib.optionals (format == "wheel") [
wheelUnpackHook
] ++ lib.optionals (format == "egg") [
eggUnpackHook eggBuildHook eggInstallHook
] ++ lib.optionals (!(format == "other") || dontUsePipInstall) [
pipInstallHook
] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [
] ++ lib.optionals (format != "other") [(
if isBootstrapInstallPackage then
pypaInstallHook.override {
inherit (python.pythonForBuild.pkgs.bootstrap) installer;
}
else
pypaInstallHook
)] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [
# This is a test, however, it should be ran independent of the checkPhase and checkInputs
pythonImportsCheckHook
] ++ lib.optionals (python.pythonAtLeast "3.3") [
Expand Down
9 changes: 7 additions & 2 deletions pkgs/development/interpreters/python/python-packages-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ let
}
else result;

buildPythonPackage = makeOverridablePythonPackage (lib.makeOverridable (callPackage ./mk-python-derivation.nix {
mkPythonDerivation = if python.isPy3k then
./mk-python-derivation.nix
else
./python2/mk-python-derivation.nix;

buildPythonPackage = makeOverridablePythonPackage (lib.makeOverridable (callPackage mkPythonDerivation {
inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}"
inherit toPythonModule; # Libraries provide modules
}));

buildPythonApplication = makeOverridablePythonPackage (lib.makeOverridable (callPackage ./mk-python-derivation.nix {
buildPythonApplication = makeOverridablePythonPackage (lib.makeOverridable (callPackage mkPythonDerivation {
namePrefix = ""; # Python applications should not have any prefix
toPythonModule = x: x; # Application does not provide modules.
}));
Expand Down
Loading