commit 27acf4cb56ce07aa913692ecf780d8c8f0637a87
parent 1083eb0126561155b8cfab92500fe96d16fc33fd
Author: Jan Pobrislo <ccx@te2000.cz>
Date: Wed, 25 Jun 2025 03:00:47 +0000
Untested implementation for using pyproject.toml as requirements source
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/pip-tools.mk b/pip-tools.mk
@@ -12,7 +12,7 @@ venv: $(python_venv_targets) # installs/updates and symlinks all virtual enviro
# -- requirement file rule generator
-### example use:
+### from requirements.in files; example use:
## create "release" environment from "release-requirements.in" file
# $(eval $(call PIP_COMPILE_RULE,release,release-requirements.in))
## create "dev" environment from both "release-requirements.in" and "dev-requirements.in" files
@@ -22,7 +22,25 @@ define PIP_COMPILE_RULE =
$(1)-$(PYTHON_IMPL)-requirements.txt: $(2) $(PIP_COMPILE_DEP)
$(PIP_COMPILE) -v --annotate -o '$$@.new' $(2)
mv '$$@.new' '$$@'
+$(eval $(call PY_ENVIRONMENT_RULE,$(1)))
+endef
+
+### from pyproject.toml; example use:
+## create "release" environment non-optional dependencies
+# $(eval $(call PYPROJECT_RULE,release,))
+## create "dev" that also includes "doc" and "test" optional-dependencies
+## note the semicolon used to separate included extras
+# $(eval $(call PYPROJECT_RULE,dev,doc;test))
+
+_comma:=, # to workaround lack of quoting or escaping in function calls
+define PYPROJECT_RULE =
+$(1)-$(PYTHON_IMPL)-requirements.txt: pyproject.toml $(PIP_COMPILE_DEP)
+ $(PIP_COMPILE) -v --annotate -o '$$@.new' --extra='$(subst ;,$(comma),$(2))' pyproject.toml
+ mv '$$@.new' '$$@'
+$(eval $(call PY_ENVIRONMENT_RULE,$(1)))
+endef
+define PY_ENVIRONMENT_RULE =
.PRECIOUS: $(1)-$(PYTHON_IMPL)-requirements.txt
python_requirements_targets+=$(1)-$(PYTHON_IMPL)-requirements.txt