@@ -7,6 +7,10 @@ SHELL := bash
77PACKAGE_NAME := package
88PACKAGE_VERSION := $(shell python -c $$'try: import $(PACKAGE_NAME ) ; print($(PACKAGE_NAME ) .__version__) ;\nexcept: print("unknown");')
99
10+ # Files that this package depends on are in the src/ folder, so collect them
11+ # all into a list.
12+ PACKAGE_DEPS := $(shell find src/$(PACKAGE_NAME ) -type f -not -path "* /__pycache__/* ")
13+
1014# This variable contains the first goal that matches any of the listed goals
1115# here, else it contains an empty string. The net effect is to filter out
1216# whether this current run of `make` requires a Python virtual environment
@@ -106,7 +110,8 @@ upgrade-quiet:
106110
107111# Generate a Software Bill of Materials (SBOM).
108112.PHONY : sbom
109- sbom : requirements
113+ sbom : requirements dist/$(PACKAGE_NAME ) -$(PACKAGE_VERSION ) -sbom.json
114+ dist/$(PACKAGE_NAME ) -$(PACKAGE_VERSION ) -sbom.json :
110115 cyclonedx-py --force --requirements --format json --output dist/$(PACKAGE_NAME ) -$(PACKAGE_VERSION ) -sbom.json
111116
112117# Generate a requirements.txt file containing version and integrity hashes for all
@@ -119,8 +124,8 @@ sbom: requirements
119124# We also want to make sure that this package itself is added to the requirements.txt
120125# file, and if possible even with proper hashes.
121126.PHONY : requirements
122- requirements : requirements.txt
123- requirements.txt : pyproject.toml
127+ requirements : requirements.txt dist/ $( PACKAGE_NAME ) - $( PACKAGE_VERSION ) -requirements.txt
128+ requirements.txt dist/ $( PACKAGE_NAME ) - $( PACKAGE_VERSION ) -requirements.txt : .venv/upgraded-on
124129 echo -n " " > requirements.txt
125130 for pkg in $$ (python -m pip freeze --local --disable-pip-version-check --exclude-editable); do \
126131 pkg=$$ {pkg//[$$ ' \r\n' ]}; \
@@ -160,14 +165,18 @@ check-lint:
160165 pre-commit run pylint --all-files
161166check-mypy :
162167 pre-commit run mypy --all-files
163- check :
168+ check : .venv/checked-on
169+ .venv/checked-on : $(PACKAGE_DEPS )
164170 pre-commit run --all-files
171+ echo " Automatically generated by Python Package Makefile on $$ (date '+%Y-%m-%d %H:%M:%S %z')." > .venv/checked-on
165172
166173# Run all unit tests. The --files option avoids stashing but passes files; however,
167174# the hook setup itself does not pass files to pytest (see .pre-commit-config.yaml).
168175.PHONY : test
169- test :
176+ test : check .venv/tested-on
177+ .venv/tested-on : $(PACKAGE_DEPS )
170178 pre-commit run pytest --hook-stage push --files tests/
179+ echo " Automatically generated by Python Package Makefile on $$ (date '+%Y-%m-%d %H:%M:%S %z')." > .venv/tested-on
171180
172181# Build a source distribution package and a binary wheel distribution artifact.
173182# When building these artifacts, we need the environment variable SOURCE_DATE_EPOCH
0 commit comments