From 5f4449ff63c8ad70c0fe3ad76dc3fac3b4445d53 Mon Sep 17 00:00:00 2001 From: mathijssh Date: Fri, 5 Jan 2024 15:45:54 +0100 Subject: [PATCH 1/4] Moved configuration of - Python version - Project folder - PyPi snapshot date into the `pyproject.toml` configuration file. Leverages the possibility to create arbitrary configuration in the [tool] table (more info: https://packaging.python.org/en/latest/specifications/pyproject-toml/#arbitrary-tool-configuration-the-tool-table) --- .../python-project/default.nix | 6 ++-- .../single-language/python-project/lock.json | 32 +++++++++---------- .../{my_tool => my_project}/__init__.py | 1 - .../python-project/pyproject.toml | 9 +++++- 4 files changed, 27 insertions(+), 21 deletions(-) rename examples/packages/single-language/python-project/{my_tool => my_project}/__init__.py (97%) diff --git a/examples/packages/single-language/python-project/default.nix b/examples/packages/single-language/python-project/default.nix index 79f59f2616..0f371a9cfa 100644 --- a/examples/packages/single-language/python-project/default.nix +++ b/examples/packages/single-language/python-project/default.nix @@ -12,7 +12,7 @@ in { ]; deps = {nixpkgs, ...}: { - python = nixpkgs.python310; + python = nixpkgs.${pyproject.tool.dream2nix.python-version}; }; inherit (pyproject.project) name version; @@ -24,12 +24,12 @@ in { buildPythonPackage = { format = lib.mkForce "pyproject"; pythonImportsCheck = [ - "my_tool" + pyproject.tool.dream2nix.project-folder ]; }; pip = { - pypiSnapshotDate = "2023-08-27"; + pypiSnapshotDate = pyproject.tool.dream2nix.pypi-snapshot-date; requirementsList = pyproject.build-system.requires or [] diff --git a/examples/packages/single-language/python-project/lock.json b/examples/packages/single-language/python-project/lock.json index e9e7613861..efa5a71080 100644 --- a/examples/packages/single-language/python-project/lock.json +++ b/examples/packages/single-language/python-project/lock.json @@ -2,22 +2,22 @@ "fetchPipMetadata": { "sources": { "certifi": { - "sha256": "92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9", + "sha256": "e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474", "type": "url", - "url": "https://files.pythonhosted.org/packages/4c/dd/2234eab22353ffc7d94e8d13177aaa050113286e93e7b40eae01fbf7c3d9/certifi-2023.7.22-py3-none-any.whl", - "version": "2023.7.22" + "url": "https://files.pythonhosted.org/packages/64/62/428ef076be88fa93716b576e4a01f919d25968913e817077a386fcbe4f42/certifi-2023.11.17-py3-none-any.whl", + "version": "2023.11.17" }, "charset-normalizer": { - "sha256": "193cbc708ea3aca45e7221ae58f0fd63f933753a9bfb498a3b474878f12caaad", + "sha256": "753f10e867343b4511128c6ed8c82f7bec3bd026875576dfd88483c5c73b2fd8", "type": "url", - "url": "https://files.pythonhosted.org/packages/a4/65/057bf29660aae6ade0816457f8db4e749e5c0bfa2366eb5f67db9912fa4c/charset_normalizer-3.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", - "version": "3.2.0" + "url": "https://files.pythonhosted.org/packages/40/26/f35951c45070edc957ba40a5b1db3cf60a9dbb1b350c2d5bef03e01e61de/charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", + "version": "3.3.2" }, "idna": { - "sha256": "90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2", + "sha256": "c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", "type": "url", - "url": "https://files.pythonhosted.org/packages/fc/34/3030de6f1370931b9dbb4dad48f6ab1015ab1d32447850b9fc94e60097be/idna-3.4-py3-none-any.whl", - "version": "3.4" + "url": "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", + "version": "3.6" }, "requests": { "sha256": "58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f", @@ -26,16 +26,16 @@ "version": "2.31.0" }, "setuptools": { - "sha256": "3d8083eed2d13afc9426f227b24fd1659489ec107c0e86cec2ffdde5c92e790b", + "sha256": "385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05", "type": "url", - "url": "https://files.pythonhosted.org/packages/4f/ab/0bcfebdfc3bfa8554b2b2c97a555569c4c1ebc74ea288741ea8326c51906/setuptools-68.1.2-py3-none-any.whl", - "version": "68.1.2" + "url": "https://files.pythonhosted.org/packages/55/3a/5121b58b578a598b269537e09a316ad2a94fdd561a2c6eb75cd68578cc6b/setuptools-69.0.3-py3-none-any.whl", + "version": "69.0.3" }, "urllib3": { - "sha256": "de7df1803967d2c2a98e4b11bb7d6bd9210474c46e8a0401514e3a42a75ebde4", + "sha256": "55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3", "type": "url", - "url": "https://files.pythonhosted.org/packages/9b/81/62fd61001fa4b9d0df6e31d47ff49cfa9de4af03adecf339c7bc30656b37/urllib3-2.0.4-py3-none-any.whl", - "version": "2.0.4" + "url": "https://files.pythonhosted.org/packages/96/94/c31f58c7a7f470d5665935262ebd7455c7e4c7782eb525658d3dbf4b9403/urllib3-2.1.0-py3-none-any.whl", + "version": "2.1.0" } }, "targets": { @@ -54,5 +54,5 @@ } } }, - "invalidationHash": "9d63b829115c1d449d6830377e4a586d684393b9b63a76a1f89f7486b6d0ed33" + "invalidationHash": "e39f705e9824b321eeb42ae07e043ff4609f5e2e229c4602e5434bc936951304" } \ No newline at end of file diff --git a/examples/packages/single-language/python-project/my_tool/__init__.py b/examples/packages/single-language/python-project/my_project/__init__.py similarity index 97% rename from examples/packages/single-language/python-project/my_tool/__init__.py rename to examples/packages/single-language/python-project/my_project/__init__.py index bca054a8dd..591d055e6d 100644 --- a/examples/packages/single-language/python-project/my_tool/__init__.py +++ b/examples/packages/single-language/python-project/my_project/__init__.py @@ -1,4 +1,3 @@ import requests - print("Hello World!") diff --git a/examples/packages/single-language/python-project/pyproject.toml b/examples/packages/single-language/python-project/pyproject.toml index 01c49d8be6..52f120d02b 100644 --- a/examples/packages/single-language/python-project/pyproject.toml +++ b/examples/packages/single-language/python-project/pyproject.toml @@ -6,6 +6,13 @@ build-backend = "setuptools.build_meta" name = "my-tool" description = "my tool" version = "1.0.0" + +requires-python = ">=3.11.0" dependencies = [ - "requests" + "requests", ] + +[tool.dream2nix] +project-folder = "my_project" +python-version = "python311" +pypi-snapshot-date = "2024-03-01" From f2542411c32fdd4f9fc777fe0888e0ceaa308bb0 Mon Sep 17 00:00:00 2001 From: mathijssh Date: Fri, 5 Jan 2024 15:49:23 +0100 Subject: [PATCH 2/4] README added --- .../single-language/python-project/README.md | 13 ++ .../single-language/python-project/flake.lock | 112 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 examples/packages/single-language/python-project/README.md create mode 100644 examples/packages/single-language/python-project/flake.lock diff --git a/examples/packages/single-language/python-project/README.md b/examples/packages/single-language/python-project/README.md new file mode 100644 index 0000000000..90f7b52e24 --- /dev/null +++ b/examples/packages/single-language/python-project/README.md @@ -0,0 +1,13 @@ +### Description +Creates an isolated development enviroment for developing your own python project. + + +### How to use + +1. Modify `pyproject.toml` according to your project, and optionally rename the `my_project` directory +2. Enable environment `$ nix develop --impure` to start shell environment (will build all dependencies on first run and after any updates) +3. Update the `lock.json` by running the command generated by dream2nix (see terminal output, `bash -c $(nix-build...` or something similar) + +To add new python packages to your project, modify `pyproject.toml` and re-run steps 2 and 3. + +To integrate with your IDE, run `which python` from within the activated development environment, and point the interpreter path in your IDE to its output. Make sure to run/start your IDE from within the activated development environment, so it will be able to find the installed python packages. diff --git a/examples/packages/single-language/python-project/flake.lock b/examples/packages/single-language/python-project/flake.lock new file mode 100644 index 0000000000..aea880af30 --- /dev/null +++ b/examples/packages/single-language/python-project/flake.lock @@ -0,0 +1,112 @@ +{ + "nodes": { + "dream2nix": { + "inputs": { + "nixpkgs": "nixpkgs", + "purescript-overlay": "purescript-overlay", + "pyproject-nix": "pyproject-nix" + }, + "locked": { + "lastModified": 1704251370, + "narHash": "sha256-8pGZFY+K4mXDMHzZ8UB7iJXSOzF9P1g//o1vZjamyfs=", + "owner": "nix-community", + "repo": "dream2nix", + "rev": "1741d0785efda39ba44d12efef6d3739fc29ed9e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "dream2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1702272962, + "narHash": "sha256-D+zHwkwPc6oYQ4G3A1HuadopqRwUY/JkMwHz1YF7j4Q=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e97b3e4186bcadf0ef1b6be22b8558eab1cdeb5d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "purescript-overlay": { + "inputs": { + "nixpkgs": [ + "dream2nix", + "nixpkgs" + ], + "slimlock": "slimlock" + }, + "locked": { + "lastModified": 1696022621, + "narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=", + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "rev": "047c7933abd6da8aa239904422e22d190ce55ead", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "type": "github" + } + }, + "pyproject-nix": { + "flake": false, + "locked": { + "lastModified": 1702448246, + "narHash": "sha256-hFg5s/hoJFv7tDpiGvEvXP0UfFvFEDgTdyHIjDVHu1I=", + "owner": "davhau", + "repo": "pyproject.nix", + "rev": "5a06a2697b228c04dd2f35659b4b659ca74f7aeb", + "type": "github" + }, + "original": { + "owner": "davhau", + "ref": "dream2nix", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "dream2nix": "dream2nix", + "nixpkgs": [ + "dream2nix", + "nixpkgs" + ] + } + }, + "slimlock": { + "inputs": { + "nixpkgs": [ + "dream2nix", + "purescript-overlay", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688610262, + "narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=", + "owner": "thomashoneyman", + "repo": "slimlock", + "rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "slimlock", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} From 2ec0e6fb97e129d5bbf8d94770058bc0a5f35d1c Mon Sep 17 00:00:00 2001 From: mathijssh Date: Fri, 5 Jan 2024 18:00:05 +0100 Subject: [PATCH 3/4] Delete examples/packages/single-language/python-project/flake.lock --- .../single-language/python-project/flake.lock | 112 ------------------ 1 file changed, 112 deletions(-) delete mode 100644 examples/packages/single-language/python-project/flake.lock diff --git a/examples/packages/single-language/python-project/flake.lock b/examples/packages/single-language/python-project/flake.lock deleted file mode 100644 index aea880af30..0000000000 --- a/examples/packages/single-language/python-project/flake.lock +++ /dev/null @@ -1,112 +0,0 @@ -{ - "nodes": { - "dream2nix": { - "inputs": { - "nixpkgs": "nixpkgs", - "purescript-overlay": "purescript-overlay", - "pyproject-nix": "pyproject-nix" - }, - "locked": { - "lastModified": 1704251370, - "narHash": "sha256-8pGZFY+K4mXDMHzZ8UB7iJXSOzF9P1g//o1vZjamyfs=", - "owner": "nix-community", - "repo": "dream2nix", - "rev": "1741d0785efda39ba44d12efef6d3739fc29ed9e", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "dream2nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1702272962, - "narHash": "sha256-D+zHwkwPc6oYQ4G3A1HuadopqRwUY/JkMwHz1YF7j4Q=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "e97b3e4186bcadf0ef1b6be22b8558eab1cdeb5d", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "purescript-overlay": { - "inputs": { - "nixpkgs": [ - "dream2nix", - "nixpkgs" - ], - "slimlock": "slimlock" - }, - "locked": { - "lastModified": 1696022621, - "narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=", - "owner": "thomashoneyman", - "repo": "purescript-overlay", - "rev": "047c7933abd6da8aa239904422e22d190ce55ead", - "type": "github" - }, - "original": { - "owner": "thomashoneyman", - "repo": "purescript-overlay", - "type": "github" - } - }, - "pyproject-nix": { - "flake": false, - "locked": { - "lastModified": 1702448246, - "narHash": "sha256-hFg5s/hoJFv7tDpiGvEvXP0UfFvFEDgTdyHIjDVHu1I=", - "owner": "davhau", - "repo": "pyproject.nix", - "rev": "5a06a2697b228c04dd2f35659b4b659ca74f7aeb", - "type": "github" - }, - "original": { - "owner": "davhau", - "ref": "dream2nix", - "repo": "pyproject.nix", - "type": "github" - } - }, - "root": { - "inputs": { - "dream2nix": "dream2nix", - "nixpkgs": [ - "dream2nix", - "nixpkgs" - ] - } - }, - "slimlock": { - "inputs": { - "nixpkgs": [ - "dream2nix", - "purescript-overlay", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1688610262, - "narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=", - "owner": "thomashoneyman", - "repo": "slimlock", - "rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6", - "type": "github" - }, - "original": { - "owner": "thomashoneyman", - "repo": "slimlock", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} From c3224ff939a2beca0cae4c1a07ec1163d1de73ad Mon Sep 17 00:00:00 2001 From: DavHau Date: Fri, 12 Jan 2024 16:30:51 +0700 Subject: [PATCH 4/4] format --- examples/packages/single-language/python-project/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/packages/single-language/python-project/default.nix b/examples/packages/single-language/python-project/default.nix index 0f371a9cfa..26e7a52b28 100644 --- a/examples/packages/single-language/python-project/default.nix +++ b/examples/packages/single-language/python-project/default.nix @@ -24,7 +24,7 @@ in { buildPythonPackage = { format = lib.mkForce "pyproject"; pythonImportsCheck = [ - pyproject.tool.dream2nix.project-folder + pyproject.tool.dream2nix.project-folder ]; };