Skip to content

Commit

Permalink
fix(pip): prevent conflict if setuptools is runtime dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DavHau committed Jan 7, 2024
1 parent 935df57 commit 29f241d
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/dream2nix/pip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@
)
metadata.sources;

dependencyModule = {config, ...}: let
dependencyModule = depConfig: let
cfg = depConfig.config;
setuptools =
if config.name == "setuptools"
if cfg.name == "setuptools"
then config.deps.python.pkgs.setuptools
else config.pip.drvs.setuptools.public or config.deps.python.pkgs.setuptools;
in {
# deps.python cannot be defined in commonModule as this would trigger an
# infinite recursion.
deps = {inherit python;};
buildPythonPackage.format = l.mkDefault (
if l.hasSuffix ".whl" config.mkDerivation.src
if l.hasSuffix ".whl" cfg.mkDerivation.src
then "wheel"
else "pyproject"
);
mkDerivation.buildInputs =
lib.optionals
(! lib.hasSuffix ".whl" config.mkDerivation.src)
(! lib.hasSuffix ".whl" cfg.mkDerivation.src)
[setuptools];
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# An example package with dependencies defined via pyproject.toml
{
config,
lib,
dream2nix,
...
}: let
pyproject = lib.importTOML (config.mkDerivation.src + /pyproject.toml);
in {
imports = [
dream2nix.modules.dream2nix.pip
];

deps = {nixpkgs, ...}: {
python = nixpkgs.python310;
};

inherit (pyproject.project) name version;

mkDerivation = {
src = ./.;
propagatedBuildInputs = [
config.pip.drvs.setuptools.public
];
};

buildPythonPackage = {
format = lib.mkForce "pyproject";
pythonImportsCheck = [
"my_tool"
];
};

pip = {
pypiSnapshotDate = "2023-08-27";
requirementsList =
pyproject.build-system.requires
or []
++ pyproject.project.dependencies;
flattenDependencies = true;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
description = "My flake with dream2nix packages";

inputs = {
dream2nix.url = "github:nix-community/dream2nix";
nixpkgs.follows = "dream2nix/nixpkgs";
};

outputs = inputs @ {
self,
dream2nix,
nixpkgs,
...
}: let
system = "x86_64-linux";
in {
# All packages defined in ./packages/<name> are automatically added to the flake outputs
# e.g., 'packages/hello/default.nix' becomes '.#packages.hello'
packages.${system}.default = dream2nix.lib.evalModules {
packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system};
modules = [
./default.nix
{
paths.projectRoot = ./.;
# can be changed to ".git" or "flake.nix" to get rid of .project-root
paths.projectRootFile = "flake.nix";
paths.package = ./.;
}
];
};
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"fetchPipMetadata": {
"sources": {
"setuptools": {
"sha256": "3d8083eed2d13afc9426f227b24fd1659489ec107c0e86cec2ffdde5c92e790b",
"type": "url",
"url": "https://files.pythonhosted.org/packages/4f/ab/0bcfebdfc3bfa8554b2b2c97a555569c4c1ebc74ea288741ea8326c51906/setuptools-68.1.2-py3-none-any.whl",
"version": "68.1.2"
},
"zope-event": {
"sha256": "2832e95014f4db26c47a13fdaef84cef2f4df37e66b59d8f1f4a8f319a632c26",
"type": "url",
"url": "https://files.pythonhosted.org/packages/fe/42/f8dbc2b9ad59e927940325a22d6d3931d630c3644dae7e2369ef5d9ba230/zope.event-5.0-py3-none-any.whl",
"version": "5.0"
}
},
"targets": {
"default": {
"setuptools": [],
"zope-event": [
"setuptools"
]
}
}
},
"invalidationHash": "a28486f07b358a61417372651204d501d66b8e54addea5c6a66fa306a5074d6f"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import zope.event


def main():
print("Hello World!")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = [ "setuptools" ]
build-backend = "setuptools.build_meta"

[project]
name = "my-tool"
description = "my tool"
version = "1.0.0"
dependencies = [
# This depends on setuptools at runtime
# It must not lead to a conflict with the nixpkgs setuptools
"zope-event"
]

[project.scripts]
my-tool = "my_tool:main"

0 comments on commit 29f241d

Please sign in to comment.