Debian Codegraph @

Makefile

raw ◀ ▶
2 Debian patches touch this file
1 # Shortcuts for various tasks (UNIX only).
2 # To use a specific Python version run: "make install PYTHON=python3.3"
3 # You can set the variables below from the command line.
4
5 # Configurable
6 PYTHON = python3
•7 PYTHONPATH = .
8 ARGS =
9
10 # In not in a virtualenv, add --user options for install commands.
11 SETUP_INSTALL_ARGS = `$(PYTHON) -c \
12 "import sys; print('' if hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix else '--user')"`
13 PIP_INSTALL_ARGS = --trusted-host files.pythonhosted.org --trusted-host pypi.org --upgrade
•14 PYTHON_ENV_VARS = PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTHONPATH=$(PYTHONPATH)
15 SUDO = $(if $(filter $(OS),Windows_NT),,sudo -E)
16 DPRINT = ~/.dprint/bin/dprint
17
18 # if make is invoked with no arg, default to `make help`
19 .DEFAULT_GOAL := help
20
21 # install git hook
22 _ := $(shell mkdir -p .git/hooks/ && ln -sf ../../scripts/internal/git_pre_commit.py .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit)
23
24 # ===================================================================
25 # Install
26 # ===================================================================
27
28 clean: ## Remove all build files.
29 @rm -rfv `find . \
30 -type d -name __pycache__ \
31 -o -type f -name \*.bak \
32 -o -type f -name \*.orig \
33 -o -type f -name \*.pyc \
34 -o -type f -name \*.pyd \
35 -o -type f -name \*.pyo \
36 -o -type f -name \*.rej \
37 -o -type f -name \*.so \
38 -o -type f -name \*.~ \
39 -o -type f -name \*\$testfn`
40 @rm -rfv \
41 *.core \
42 *.egg-info \
43 *\@psutil-* \
44 .coverage \
45 .failed-tests.txt \
46 .pytest_cache \
47 .ruff_cache/ \
48 build/ \
49 dist/ \
50 docs/_build/ \
51 htmlcov/ \
52 pytest-cache-files* \
53 wheelhouse
54
55 .PHONY: build
56 build: ## Compile (in parallel) without installing.
57 @# "build_ext -i" copies compiled *.so files in ./psutil directory in order
58 @# to allow "import psutil" when using the interactive interpreter from
59 @# within this directory.
60 $(PYTHON_ENV_VARS) $(PYTHON) setup.py build_ext -i --parallel 4
61 $(PYTHON_ENV_VARS) $(PYTHON) -c "import psutil" # make sure it actually worked
62
63 install: ## Install this package as current user in "edit" mode.
64 ${MAKE} build
65 $(PYTHON_ENV_VARS) $(PYTHON) setup.py develop $(SETUP_INSTALL_ARGS)
66
67 uninstall: ## Uninstall this package via pip.
68 cd ..; $(PYTHON_ENV_VARS) $(PYTHON) -m pip uninstall -y -v psutil || true
69 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/purge_installation.py
70
71 install-pip: ## Install pip (no-op if already installed).
72 $(PYTHON) scripts/internal/install_pip.py
73
74 install-sysdeps:
75 ./scripts/internal/install-sysdeps.sh
76
77 install-pydeps-test: ## Install python deps necessary to run unit tests.
78 ${MAKE} install-pip
79 $(PYTHON) -m pip install $(PIP_INSTALL_ARGS) -e .[test]
80
81 install-pydeps-dev: ## Install python deps meant for local development.
82 ${MAKE} install-git-hooks
83 ${MAKE} install-pip
84 $(PYTHON) -m pip install $(PIP_INSTALL_ARGS) -e .[test,dev]
85
86 install-git-hooks: ## Install GIT pre-commit hook.
87 ln -sf ../../scripts/internal/git_pre_commit.py .git/hooks/pre-commit
88 chmod +x .git/hooks/pre-commit
89
90 # ===================================================================
91 # Tests
92 # ===================================================================
93
94 test: ## Run all tests. To run a specific test do "make test ARGS=psutil.tests.test_system.TestDiskAPIs"
95 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest --ignore=psutil/tests/test_memleaks.py --ignore=psutil/tests/test_sudo.py $(ARGS)
96
97 test-parallel: ## Run all tests in parallel.
98 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest --ignore=psutil/tests/test_memleaks.py -p xdist -n auto --dist loadgroup $(ARGS)
99
100 test-process: ## Run process-related API tests.
101 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_process.py
102
103 test-process-all: ## Run tests which iterate over all process PIDs.
104 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_process_all.py
105
106 test-system: ## Run system-related API tests.
107 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_system.py
108
109 test-misc: ## Run miscellaneous tests.
110 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_misc.py
111
112 test-scripts: ## Run scripts tests.
113 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_scripts.py
114
115 test-testutils: ## Run test utils tests.
116 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_testutils.py
117
118 test-unicode: ## Test APIs dealing with strings.
119 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_unicode.py
120
121 test-contracts: ## APIs sanity tests.
122 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_contracts.py
123
124 test-connections: ## Test psutil.net_connections() and Process.net_connections().
125 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_connections.py
126
127 test-posix: ## POSIX specific tests.
128 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_posix.py
129
130 test-platform: ## Run specific platform tests only.
131 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS", "AIX") if getattr(psutil, x)][0])'`.py
132
133 test-memleaks: ## Memory leak tests.
134 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_memleaks.py
135
136 test-last-failed: ## Re-run tests which failed on last run
137 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest --last-failed $(ARGS)
138
139 test-coverage: ## Run test coverage.
140 # Note: coverage options are controlled by .coveragerc file
141 rm -rf .coverage htmlcov
142 $(PYTHON_ENV_VARS) $(PYTHON) -m coverage run -m pytest --ignore=psutil/tests/test_memleaks.py $(ARGS)
143 $(PYTHON) -m coverage report
144 @echo "writing results to htmlcov/index.html"
145 $(PYTHON) -m coverage html
146 $(PYTHON) -m webbrowser -t htmlcov/index.html
147
148 test-sudo: ## Run tests requiring root privileges.
149 # Use unittest runner because pytest may not be installed as root.
150 $(SUDO) $(PYTHON_ENV_VARS) $(PYTHON) -m unittest -v psutil.tests.test_sudo
151
152 test-ci: ## Run tests on GitHub CI.
153 ${MAKE} install-sysdeps
154 PIP_BREAK_SYSTEM_PACKAGES=1 ${MAKE} install-pydeps-test
155 ${MAKE} print-sysinfo
156 $(PYTHON) -m pip list
157 ${MAKE} test
158 ${MAKE} test-memleaks
159 ${MAKE} test-sudo
160
161 test-cibuildwheel: ## Run tests from cibuildwheel.
162 # testing the wheels means we can't use other test targets which are rebuilding the python extensions
163 # we also need to run the tests from another folder for pytest not to use the sources but only what's been installed
164 ${MAKE} install-sysdeps
165 mkdir -p .tests
166 cd .tests/ && python -c "from psutil.tests import print_sysinfo; print_sysinfo()"
167 cd .tests/ && $(PYTHON_ENV_VARS) PYTEST_ADDOPTS="-k 'not test_memleaks.py'" $(PYTHON) -m pytest --pyargs psutil.tests
168 cd .tests/ && $(PYTHON_ENV_VARS) PYTEST_ADDOPTS="-k test_memleaks.py" $(PYTHON) -m pytest --pyargs psutil.tests
169
170 lint-ci: ## Run all linters on GitHub CI.
171 python3 -m pip install -U black ruff rstcheck toml-sort sphinx
172 curl -fsSL https://dprint.dev/install.sh | sh
173 ${MAKE} lint-all
174
175 # ===================================================================
176 # Linters
177 # ===================================================================
178
179 ruff: ## Run ruff linter.
180 @git ls-files '*.py' | xargs $(PYTHON) -m ruff check --output-format=concise
181
182 black: ## Run black formatter.
183 @git ls-files '*.py' | xargs $(PYTHON) -m black --check --safe
184
185 dprint:
186 @$(DPRINT) check --list-different
187
188 lint-c: ## Run C linter.
189 @git ls-files '*.c' '*.h' | xargs $(PYTHON) scripts/internal/clinter.py
190
191 lint-rst: ## Run linter for .rst files.
192 @git ls-files '*.rst' | xargs rstcheck --config=pyproject.toml
193
194 lint-toml: ## Run linter for pyproject.toml.
195 @git ls-files '*.toml' | xargs toml-sort --check
196
197 lint-all: ## Run all linters
198 ${MAKE} black
199 ${MAKE} ruff
200 ${MAKE} dprint
201 ${MAKE} lint-c
202 ${MAKE} lint-rst
203 ${MAKE} lint-toml
204
205 # --- not mandatory linters (just run from time to time)
206
207 pylint: ## Python pylint
208 @git ls-files '*.py' | xargs $(PYTHON) -m pylint --rcfile=pyproject.toml --jobs=0 $(ARGS)
209
210 vulture: ## Find unused code
211 @git ls-files '*.py' | xargs $(PYTHON) -m vulture $(ARGS)
212
213 # ===================================================================
214 # Fixers
215 # ===================================================================
216
217 fix-black:
218 @git ls-files '*.py' | xargs $(PYTHON) -m black
219
220 fix-ruff:
221 @git ls-files '*.py' | xargs $(PYTHON) -m ruff check --fix --output-format=concise $(ARGS)
222
223 fix-toml: ## Fix pyproject.toml
224 @git ls-files '*.toml' | xargs toml-sort
225
226 fix-dprint:
227 @$(DPRINT) fmt
228
229 fix-all: ## Run all code fixers.
230 ${MAKE} fix-ruff
231 ${MAKE} fix-black
232 ${MAKE} fix-toml
233 ${MAKE} fix-dprint
234
235 # ===================================================================
236 # Distribution
237 # ===================================================================
238
239 sdist: ## Create tar.gz source distribution.
240 ${MAKE} generate-manifest
241 $(PYTHON_ENV_VARS) $(PYTHON) setup.py sdist
242
243 download-wheels: ## Download latest wheels hosted on github.
244 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/download_wheels.py --tokenfile=~/.github.token
245 ${MAKE} print-dist
246
247 create-wheels: ## Create .whl files
248 $(PYTHON_ENV_VARS) $(PYTHON) setup.py bdist_wheel
249 ${MAKE} check-wheels
250
251 check-sdist: ## Check sanity of source distribution.
252 $(PYTHON_ENV_VARS) $(PYTHON) -m virtualenv --clear --no-wheel --quiet build/venv
253 $(PYTHON_ENV_VARS) build/venv/bin/python -m pip install -v --isolated --quiet dist/*.tar.gz
254 $(PYTHON_ENV_VARS) build/venv/bin/python -c "import os; os.chdir('build/venv'); import psutil"
255 $(PYTHON) -m twine check --strict dist/*.tar.gz
256
257 check-wheels: ## Check sanity of wheels.
258 $(PYTHON) -m abi3audit --verbose --strict dist/*-abi3-*.whl
259 $(PYTHON) -m twine check --strict dist/*.whl
260
261 pre-release: ## Check if we're ready to produce a new release.
262 ${MAKE} clean
263 ${MAKE} sdist
264 ${MAKE} check-sdist
265 ${MAKE} install
266 @$(PYTHON) -c \
267 "import requests, sys; \
268 from packaging.version import parse; \
269 from psutil import __version__; \
270 res = requests.get('https://pypi.org/pypi/psutil/json', timeout=5); \
271 versions = sorted(res.json()['releases'], key=parse, reverse=True); \
272 sys.exit('version %r already exists on PYPI' % __version__) if __version__ in versions else 0"
273 @$(PYTHON) -c \
274 "from psutil import __version__ as ver; \
275 doc = open('docs/index.rst').read(); \
276 history = open('HISTORY.rst').read(); \
277 assert ver in doc, '%r not found in docs/index.rst' % ver; \
278 assert ver in history, '%r not found in HISTORY.rst' % ver; \
279 assert 'XXXX' not in history, 'XXXX found in HISTORY.rst';"
280 ${MAKE} download-wheels
281 ${MAKE} check-wheels
282 ${MAKE} print-hashes
283 ${MAKE} print-dist
284
285 release: ## Upload a new release.
286 ${MAKE} check-sdist
287 ${MAKE} check-wheels
288 $(PYTHON) -m twine upload dist/*.tar.gz
289 $(PYTHON) -m twine upload dist/*.whl
290 ${MAKE} git-tag-release
291
292 generate-manifest: ## Generates MANIFEST.in file.
293 $(PYTHON) scripts/internal/generate_manifest.py > MANIFEST.in
294
295 print-dist: ## Print downloaded wheels / tar.gs
296 $(PYTHON) scripts/internal/print_dist.py
297
298 git-tag-release: ## Git-tag a new release.
299 git tag -a release-`python3 -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD`
300 git push --follow-tags
301
302 # ===================================================================
303 # Printers
304 # ===================================================================
305
306 print-announce: ## Print announce of new release.
307 @$(PYTHON) scripts/internal/print_announce.py
308
309 print-timeline: ## Print releases' timeline.
310 @$(PYTHON) scripts/internal/print_timeline.py
311
312 print-access-denied: ## Print AD exceptions
313 ${MAKE} build
314 @$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/print_access_denied.py
315
316 print-api-speed: ## Benchmark all API calls
317 ${MAKE} build
318 @$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/print_api_speed.py $(ARGS)
319
320 print-downloads: ## Print PYPI download statistics
321 $(PYTHON) scripts/internal/print_downloads.py
322
323 print-hashes: ## Prints hashes of files in dist/ directory
324 $(PYTHON) scripts/internal/print_hashes.py dist/
325
326 print-sysinfo: ## Prints system info
327 $(PYTHON) -c "from psutil.tests import print_sysinfo; print_sysinfo()"
328
329 # ===================================================================
330 # Misc
331 # ===================================================================
332
333 grep-todos: ## Look for TODOs in the source files.
334 git grep -EIn "TODO|FIXME|XXX"
335
336 bench-oneshot: ## Benchmarks for oneshot() ctx manager (see #799).
337 ${MAKE} build
338 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/bench_oneshot.py
339
340 bench-oneshot-2: ## Same as above but using perf module (supposed to be more precise)
341 ${MAKE} build
342 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/bench_oneshot_2.py
343
344 check-broken-links: ## Look for broken links in source files.
345 git ls-files | xargs $(PYTHON) -Wa scripts/internal/check_broken_links.py
346
347 check-manifest: ## Inspect MANIFEST.in file.
348 $(PYTHON) -m check_manifest -v $(ARGS)
349
350 help: ## Display callable targets.
351 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'