Debian Codegraph @

Makefile

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