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

Move configuration of python version and project name into pyproject.toml #817

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions examples/packages/single-language/python-project/README.md
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An easier command to update the lock file is nix run .#default.lock


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.
6 changes: 3 additions & 3 deletions examples/packages/single-language/python-project/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ in {
];

deps = {nixpkgs, ...}: {
python = nixpkgs.python310;
python = nixpkgs.${pyproject.tool.dream2nix.python-version};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could parse the python version directly from the requires_python field using pyproject.nix.
But maybe this can be done in a separate PR.
If you are interested in working on this, you can see how to access the pyproject.nix library if you look at the WIP-python-pdm module as an example that already uses this lib (it doesn't parse yet the python version, though).

};

inherit (pyproject.project) name version;
Expand All @@ -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 []
Expand Down
32 changes: 16 additions & 16 deletions examples/packages/single-language/python-project/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand All @@ -54,5 +54,5 @@
}
}
},
"invalidationHash": "9d63b829115c1d449d6830377e4a586d684393b9b63a76a1f89f7486b6d0ed33"
"invalidationHash": "e39f705e9824b321eeb42ae07e043ff4609f5e2e229c4602e5434bc936951304"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import requests


print("Hello World!")
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment on lines +15 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I like this idea in general, I would like to implement this in a more generic way, so that everything from, for example tool.draem2nix.config gets mapped to the package's config.

For now I'd prefer not to add these, because we will have to deprecate them again once the generic implementation is in place, and users will face breakages.