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

Additional v1 python use cases #543

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
35 changes: 35 additions & 0 deletions examples/v1-multi-python/code1/pypkg1/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# NOTE: Move into top-level subdirectory to have all nix tooling in one place?
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
dream2nix.modules.drv-parts.mkDerivation
dream2nix.modules.drv-parts.pip
];

name = "pypkg1";
version = "1";

deps = {nixpkgs, ...}: {
inherit (nixpkgs) stdenv;
};

mkDerivation = {
src = ./.;
};

pip = {
# NOTE: Pass via CLI or define once for multiple packages?
pypiSnapshotDate = "2023-06-30";

# NOTE: How do we select the optional dev dependencies?
requirementsFile = [
"."
];
};
}
20 changes: 20 additions & 0 deletions examples/v1-multi-python/code1/pypkg1/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools>=65.4.0", "wheel"]
build-backend = "setuptools.build_meta"


[project]
name = "pypkg1"
version = "1.0.0"
dependencies = [
"cryptography"
]

[project.optional-dependencies]
dev = [
"ruff",
]


[tool.setuptools.packages.find]
where = ["src"]
43 changes: 43 additions & 0 deletions examples/v1-multi-python/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.dream2nix.url = "github:nix-community/dream2nix";

outputs = {
self,
nixpkgs,
flake-utils,
dream2nix,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
l = nixpkgs.lib // builtins;

callModule = module:
dream2nix.lib.evalModules {
packageSets = {
nixpkgs = pkgs;
};
modules = [
module
# ./lock.nix
];
};

hello = callModule ./hello;
pypkg1 = callModule ./code1/pypkg1;
in {
devShell = pkgs.mkShell {
# SITEPACKAGES = pyenv.out + "/" + pyenv.sitePackages;
buildInputs = [
hello
pypkg1
];
};

packages = {
inherit hello pypkg1;
};
}
);
}
26 changes: 26 additions & 0 deletions examples/v1-multi-python/hello/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
dream2nix.modules.drv-parts.mkDerivation
];

name = "hello";
version = "2.12";

deps = {nixpkgs, ...}: {
inherit (nixpkgs) stdenv;
};

mkDerivation = {
src = l.fetchTarball {
url = "https://ftp.gnu.org/gnu/hello/hello-${config.version}.tar.gz";
sha256 = "sha256-4GQeKLIxoWfYiOraJub5RsHNVQBr2H+3bfPP22PegdU=";
};
};
}
26 changes: 26 additions & 0 deletions examples/v1-pip-compile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Motivation

A project consists of multiple python packages in different subdirectories. Each
of these has dependencies and optional dev dependencies. Compiled requirements
with hashes exist, written with pip-compile:

- ``code1/pypkg1/requirements.txt``
- ``code1/pypkg1/requirements-dev.txt``

Two modes of operation:

1. Use compiled requirements files and create nix lock files accordingly.
2. Create nix lock files without using compiled requirements, but only
dependency declarations in pyproject.toml, and pip-compile afterwards for
projects not using nix.

We'd like to create environments where requirements for individual packages and
combinations of these packages are available.

For the projects' python packages:

1. Do not install, environment with requirements only.

2. Install selected packages.

3. Install selected packages in editable mode.
49 changes: 49 additions & 0 deletions examples/v1-pip-compile/code1/pypkg1/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# NOTE: Move into top-level subdirectory to have all nix tooling in one place?
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
dream2nix.modules.drv-parts.pip
];

name = "pypkg1";
version = "1";

deps = {nixpkgs, ...}: {
inherit
(nixpkgs)
stdenv
;
python = nixpkgs.python310;
setuptools = nixpkgs.python310Packages.setuptools;
};

mkDerivation = {
src = ./.;

# NOTE: Should be taken from pyproject.toml [build-sytem].
nativeBuildInputs = [
config.deps.setuptools
];
};

buildPythonPackage = {
format = "pyproject";
};

pip = {
# NOTE: Pass via CLI or define once for multiple packages?
pypiSnapshotDate = "2023-06-30";

requirementsFiles = [
# NOTE: Switch flavour in central location
# "code1/pypkg1/requirements.txt",
"code1/pypkg1/requirements-dev.txt"
];
};
}
20 changes: 20 additions & 0 deletions examples/v1-pip-compile/code1/pypkg1/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools>=65.4.0", "wheel"]
build-backend = "setuptools.build_meta"


[project]
name = "pypkg1"
version = "1.0.0"
dependencies = [
"cryptography"
]

[project.optional-dependencies]
dev = [
"ruff",
]


[tool.setuptools.packages.find]
where = ["src"]
116 changes: 116 additions & 0 deletions examples/v1-pip-compile/code1/pypkg1/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --extra=dev --generate-hashes --output-file=requirements-dev.txt pyproject.toml
#
cffi==1.15.1 \
--hash=sha256:00a9ed42e88df81ffae7a8ab6d9356b371399b91dbdf0c3cb1e84c03a13aceb5 \
--hash=sha256:03425bdae262c76aad70202debd780501fabeaca237cdfddc008987c0e0f59ef \
--hash=sha256:04ed324bda3cda42b9b695d51bb7d54b680b9719cfab04227cdd1e04e5de3104 \
--hash=sha256:0e2642fe3142e4cc4af0799748233ad6da94c62a8bec3a6648bf8ee68b1c7426 \
--hash=sha256:173379135477dc8cac4bc58f45db08ab45d228b3363adb7af79436135d028405 \
--hash=sha256:198caafb44239b60e252492445da556afafc7d1e3ab7a1fb3f0584ef6d742375 \
--hash=sha256:1e74c6b51a9ed6589199c787bf5f9875612ca4a8a0785fb2d4a84429badaf22a \
--hash=sha256:2012c72d854c2d03e45d06ae57f40d78e5770d252f195b93f581acf3ba44496e \
--hash=sha256:21157295583fe8943475029ed5abdcf71eb3911894724e360acff1d61c1d54bc \
--hash=sha256:2470043b93ff09bf8fb1d46d1cb756ce6132c54826661a32d4e4d132e1977adf \
--hash=sha256:285d29981935eb726a4399badae8f0ffdff4f5050eaa6d0cfc3f64b857b77185 \
--hash=sha256:30d78fbc8ebf9c92c9b7823ee18eb92f2e6ef79b45ac84db507f52fbe3ec4497 \
--hash=sha256:320dab6e7cb2eacdf0e658569d2575c4dad258c0fcc794f46215e1e39f90f2c3 \
--hash=sha256:33ab79603146aace82c2427da5ca6e58f2b3f2fb5da893ceac0c42218a40be35 \
--hash=sha256:3548db281cd7d2561c9ad9984681c95f7b0e38881201e157833a2342c30d5e8c \
--hash=sha256:3799aecf2e17cf585d977b780ce79ff0dc9b78d799fc694221ce814c2c19db83 \
--hash=sha256:39d39875251ca8f612b6f33e6b1195af86d1b3e60086068be9cc053aa4376e21 \
--hash=sha256:3b926aa83d1edb5aa5b427b4053dc420ec295a08e40911296b9eb1b6170f6cca \
--hash=sha256:3bcde07039e586f91b45c88f8583ea7cf7a0770df3a1649627bf598332cb6984 \
--hash=sha256:3d08afd128ddaa624a48cf2b859afef385b720bb4b43df214f85616922e6a5ac \
--hash=sha256:3eb6971dcff08619f8d91607cfc726518b6fa2a9eba42856be181c6d0d9515fd \
--hash=sha256:40f4774f5a9d4f5e344f31a32b5096977b5d48560c5592e2f3d2c4374bd543ee \
--hash=sha256:4289fc34b2f5316fbb762d75362931e351941fa95fa18789191b33fc4cf9504a \
--hash=sha256:470c103ae716238bbe698d67ad020e1db9d9dba34fa5a899b5e21577e6d52ed2 \
--hash=sha256:4f2c9f67e9821cad2e5f480bc8d83b8742896f1242dba247911072d4fa94c192 \
--hash=sha256:50a74364d85fd319352182ef59c5c790484a336f6db772c1a9231f1c3ed0cbd7 \
--hash=sha256:54a2db7b78338edd780e7ef7f9f6c442500fb0d41a5a4ea24fff1c929d5af585 \
--hash=sha256:5635bd9cb9731e6d4a1132a498dd34f764034a8ce60cef4f5319c0541159392f \
--hash=sha256:59c0b02d0a6c384d453fece7566d1c7e6b7bae4fc5874ef2ef46d56776d61c9e \
--hash=sha256:5d598b938678ebf3c67377cdd45e09d431369c3b1a5b331058c338e201f12b27 \
--hash=sha256:5df2768244d19ab7f60546d0c7c63ce1581f7af8b5de3eb3004b9b6fc8a9f84b \
--hash=sha256:5ef34d190326c3b1f822a5b7a45f6c4535e2f47ed06fec77d3d799c450b2651e \
--hash=sha256:6975a3fac6bc83c4a65c9f9fcab9e47019a11d3d2cf7f3c0d03431bf145a941e \
--hash=sha256:6c9a799e985904922a4d207a94eae35c78ebae90e128f0c4e521ce339396be9d \
--hash=sha256:70df4e3b545a17496c9b3f41f5115e69a4f2e77e94e1d2a8e1070bc0c38c8a3c \
--hash=sha256:7473e861101c9e72452f9bf8acb984947aa1661a7704553a9f6e4baa5ba64415 \
--hash=sha256:8102eaf27e1e448db915d08afa8b41d6c7ca7a04b7d73af6514df10a3e74bd82 \
--hash=sha256:87c450779d0914f2861b8526e035c5e6da0a3199d8f1add1a665e1cbc6fc6d02 \
--hash=sha256:8b7ee99e510d7b66cdb6c593f21c043c248537a32e0bedf02e01e9553a172314 \
--hash=sha256:91fc98adde3d7881af9b59ed0294046f3806221863722ba7d8d120c575314325 \
--hash=sha256:94411f22c3985acaec6f83c6df553f2dbe17b698cc7f8ae751ff2237d96b9e3c \
--hash=sha256:98d85c6a2bef81588d9227dde12db8a7f47f639f4a17c9ae08e773aa9c697bf3 \
--hash=sha256:9ad5db27f9cabae298d151c85cf2bad1d359a1b9c686a275df03385758e2f914 \
--hash=sha256:a0b71b1b8fbf2b96e41c4d990244165e2c9be83d54962a9a1d118fd8657d2045 \
--hash=sha256:a0f100c8912c114ff53e1202d0078b425bee3649ae34d7b070e9697f93c5d52d \
--hash=sha256:a591fe9e525846e4d154205572a029f653ada1a78b93697f3b5a8f1f2bc055b9 \
--hash=sha256:a5c84c68147988265e60416b57fc83425a78058853509c1b0629c180094904a5 \
--hash=sha256:a66d3508133af6e8548451b25058d5812812ec3798c886bf38ed24a98216fab2 \
--hash=sha256:a8c4917bd7ad33e8eb21e9a5bbba979b49d9a97acb3a803092cbc1133e20343c \
--hash=sha256:b3bbeb01c2b273cca1e1e0c5df57f12dce9a4dd331b4fa1635b8bec26350bde3 \
--hash=sha256:cba9d6b9a7d64d4bd46167096fc9d2f835e25d7e4c121fb2ddfc6528fb0413b2 \
--hash=sha256:cc4d65aeeaa04136a12677d3dd0b1c0c94dc43abac5860ab33cceb42b801c1e8 \
--hash=sha256:ce4bcc037df4fc5e3d184794f27bdaab018943698f4ca31630bc7f84a7b69c6d \
--hash=sha256:cec7d9412a9102bdc577382c3929b337320c4c4c4849f2c5cdd14d7368c5562d \
--hash=sha256:d400bfb9a37b1351253cb402671cea7e89bdecc294e8016a707f6d1d8ac934f9 \
--hash=sha256:d61f4695e6c866a23a21acab0509af1cdfd2c013cf256bbf5b6b5e2695827162 \
--hash=sha256:db0fbb9c62743ce59a9ff687eb5f4afbe77e5e8403d6697f7446e5f609976f76 \
--hash=sha256:dd86c085fae2efd48ac91dd7ccffcfc0571387fe1193d33b6394db7ef31fe2a4 \
--hash=sha256:e00b098126fd45523dd056d2efba6c5a63b71ffe9f2bbe1a4fe1716e1d0c331e \
--hash=sha256:e229a521186c75c8ad9490854fd8bbdd9a0c9aa3a524326b55be83b54d4e0ad9 \
--hash=sha256:e263d77ee3dd201c3a142934a086a4450861778baaeeb45db4591ef65550b0a6 \
--hash=sha256:ed9cb427ba5504c1dc15ede7d516b84757c3e3d7868ccc85121d9310d27eed0b \
--hash=sha256:fa6693661a4c91757f4412306191b6dc88c1703f780c8234035eac011922bc01 \
--hash=sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0
# via cryptography
cryptography==41.0.1 \
--hash=sha256:059e348f9a3c1950937e1b5d7ba1f8e968508ab181e75fc32b879452f08356db \
--hash=sha256:1a5472d40c8f8e91ff7a3d8ac6dfa363d8e3138b961529c996f3e2df0c7a411a \
--hash=sha256:1a8e6c2de6fbbcc5e14fd27fb24414507cb3333198ea9ab1258d916f00bc3039 \
--hash=sha256:1fee5aacc7367487b4e22484d3c7e547992ed726d14864ee33c0176ae43b0d7c \
--hash=sha256:5d092fdfedaec4cbbffbf98cddc915ba145313a6fdaab83c6e67f4e6c218e6f3 \
--hash=sha256:5f0ff6e18d13a3de56f609dd1fd11470918f770c6bd5d00d632076c727d35485 \
--hash=sha256:7bfc55a5eae8b86a287747053140ba221afc65eb06207bedf6e019b8934b477c \
--hash=sha256:7fa01527046ca5facdf973eef2535a27fec4cb651e4daec4d043ef63f6ecd4ca \
--hash=sha256:8dde71c4169ec5ccc1087bb7521d54251c016f126f922ab2dfe6649170a3b8c5 \
--hash=sha256:8f4ab7021127a9b4323537300a2acfb450124b2def3756f64dc3a3d2160ee4b5 \
--hash=sha256:948224d76c4b6457349d47c0c98657557f429b4e93057cf5a2f71d603e2fc3a3 \
--hash=sha256:9a6c7a3c87d595608a39980ebaa04d5a37f94024c9f24eb7d10262b92f739ddb \
--hash=sha256:b46e37db3cc267b4dea1f56da7346c9727e1209aa98487179ee8ebed09d21e43 \
--hash=sha256:b4ceb5324b998ce2003bc17d519080b4ec8d5b7b70794cbd2836101406a9be31 \
--hash=sha256:cb33ccf15e89f7ed89b235cff9d49e2e62c6c981a6061c9c8bb47ed7951190bc \
--hash=sha256:d198820aba55660b4d74f7b5fd1f17db3aa5eb3e6893b0a41b75e84e4f9e0e4b \
--hash=sha256:d34579085401d3f49762d2f7d6634d6b6c2ae1242202e860f4d26b046e3a1006 \
--hash=sha256:eb8163f5e549a22888c18b0d53d6bb62a20510060a22fd5a995ec8a05268df8a \
--hash=sha256:f73bff05db2a3e5974a6fd248af2566134d8981fd7ab012e5dd4ddb1d9a70699
# via pypkg1 (pyproject.toml)
pycparser==2.21 \
--hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \
--hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206
# via cffi
ruff==0.0.275 \
--hash=sha256:0c4e6468da26f77b90cae35319d310999f471a8c352998e9b39937a23750149e \
--hash=sha256:0dbdea02942131dbc15dd45f431d152224f15e1dd1859fcd0c0487b658f60f1a \
--hash=sha256:1cc599022fe5ffb143a965b8d659eb64161ab8ab4433d208777eab018a1aab67 \
--hash=sha256:22efd9f41af27ef8fb9779462c46c35c89134d33e326c889971e10b2eaf50c63 \
--hash=sha256:2c09662112cfa22d7467a19252a546291fd0eae4f423e52b75a7a2000a1894db \
--hash=sha256:508b13f7ca37274cceaba4fb3ea5da6ca192356323d92acf39462337c33ad14e \
--hash=sha256:5206fc1cd8c1c1deadd2e6360c0dbcd690f1c845da588ca9d32e4a764a402c60 \
--hash=sha256:5859ee543b01b7eb67835dfd505faa8bb7cc1550f0295c92c1401b45b42be399 \
--hash=sha256:5e6554a072e7ce81eb6f0bec1cebd3dcb0e358652c0f4900d7d630d61691e914 \
--hash=sha256:6afb1c4422f24f361e877937e2a44b3f8176774a476f5e33845ebfe887dd5ec2 \
--hash=sha256:80043726662144876a381efaab88841c88e8df8baa69559f96b22d4fa216bef1 \
--hash=sha256:8347fc16aa185aae275906c4ac5b770e00c896b6a0acd5ba521f158801911998 \
--hash=sha256:a19ce3bea71023eee5f0f089dde4a4272d088d5ac0b675867e074983238ccc65 \
--hash=sha256:a63a0b645da699ae5c758fce19188e901b3033ec54d862d93fcd042addf7f38d \
--hash=sha256:c8ace4d40a57b5ea3c16555f25a6b16bc5d8b2779ae1912ce2633543d4e9b1da \
--hash=sha256:d9b264d78621bf7b698b6755d4913ab52c19bd28bee1a16001f954d64c1a1220 \
--hash=sha256:ec43658c64bfda44fd84bbea9da8c7a3b34f65448192d1c4dd63e9f4e7abfdd4
# via pypkg1 (pyproject.toml)
Loading