From 935df57a46f1456a6d4fedb136d1e1eb8727c0de Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 7 Jan 2024 19:57:57 +0700 Subject: [PATCH] pip: add test can-build-setuptools to ensure that a setuptools dependency doesn't raise a collision --- .../packages/can-build-setuptools/default.nix | 42 +++++++++++++++++++ .../packages/can-build-setuptools/flake.nix | 32 ++++++++++++++ .../packages/can-build-setuptools/lock.json | 18 ++++++++ .../can-build-setuptools/my_tool/__init__.py | 9 ++++ .../can-build-setuptools/pyproject.toml | 14 +++++++ 5 files changed, 115 insertions(+) create mode 100644 modules/dream2nix/pip/tests/packages/can-build-setuptools/default.nix create mode 100644 modules/dream2nix/pip/tests/packages/can-build-setuptools/flake.nix create mode 100644 modules/dream2nix/pip/tests/packages/can-build-setuptools/lock.json create mode 100644 modules/dream2nix/pip/tests/packages/can-build-setuptools/my_tool/__init__.py create mode 100644 modules/dream2nix/pip/tests/packages/can-build-setuptools/pyproject.toml diff --git a/modules/dream2nix/pip/tests/packages/can-build-setuptools/default.nix b/modules/dream2nix/pip/tests/packages/can-build-setuptools/default.nix new file mode 100644 index 00000000..8af54410 --- /dev/null +++ b/modules/dream2nix/pip/tests/packages/can-build-setuptools/default.nix @@ -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; + }; +} diff --git a/modules/dream2nix/pip/tests/packages/can-build-setuptools/flake.nix b/modules/dream2nix/pip/tests/packages/can-build-setuptools/flake.nix new file mode 100644 index 00000000..51a16833 --- /dev/null +++ b/modules/dream2nix/pip/tests/packages/can-build-setuptools/flake.nix @@ -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/ 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 = ./.; + } + ]; + }; + }; +} diff --git a/modules/dream2nix/pip/tests/packages/can-build-setuptools/lock.json b/modules/dream2nix/pip/tests/packages/can-build-setuptools/lock.json new file mode 100644 index 00000000..73933994 --- /dev/null +++ b/modules/dream2nix/pip/tests/packages/can-build-setuptools/lock.json @@ -0,0 +1,18 @@ +{ + "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" + } + }, + "targets": { + "default": { + "setuptools": [] + } + } + }, + "invalidationHash": "6be3a43e2b4f000cc9324bfc4eacca5646d482d679a78865167b72f0291a3c63" +} \ No newline at end of file diff --git a/modules/dream2nix/pip/tests/packages/can-build-setuptools/my_tool/__init__.py b/modules/dream2nix/pip/tests/packages/can-build-setuptools/my_tool/__init__.py new file mode 100644 index 00000000..c1ce29af --- /dev/null +++ b/modules/dream2nix/pip/tests/packages/can-build-setuptools/my_tool/__init__.py @@ -0,0 +1,9 @@ +from setuptools import setup + + +def main(): + print("Hello World!") + + +if __name__ == "__main__": + main() diff --git a/modules/dream2nix/pip/tests/packages/can-build-setuptools/pyproject.toml b/modules/dream2nix/pip/tests/packages/can-build-setuptools/pyproject.toml new file mode 100644 index 00000000..2c6b1929 --- /dev/null +++ b/modules/dream2nix/pip/tests/packages/can-build-setuptools/pyproject.toml @@ -0,0 +1,14 @@ +[build-system] +requires = [ "setuptools" ] +build-backend = "setuptools.build_meta" + +[project] +name = "my-tool" +description = "my tool" +version = "1.0.0" +dependencies = [ + "setuptools" +] + +[project.scripts] +my-tool = "my_tool:main"