Debian Codegraph @

Makefile

raw ◀ ▶
Source reconstructed at patch state 1 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 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest --ignore=psutil/tests/test_memleaks.py --ignore=psutil/tests/test_sudo.py $(ARGS)
95
96 test-parallel: ## Run all tests in parallel.
97 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest --ignore=psutil/tests/test_memleaks.py -p xdist -n auto --dist loadgroup $(ARGS)
98
99 test-process: ## Run process-related API tests.
100 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_process.py
101
102 test-process-all: ## Run tests which iterate over all process PIDs.
103 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_process_all.py
104
105 test-system: ## Run system-related API tests.
106 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_system.py
107
108 test-misc: ## Run miscellaneous tests.
109 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_misc.py
110
111 test-scripts: ## Run scripts tests.
112 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_scripts.py
113
114 test-testutils: ## Run test utils tests.
115 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_testutils.py
116
117 test-unicode: ## Test APIs dealing with strings.
118 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_unicode.py
119
120 test-contracts: ## APIs sanity tests.
121 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_contracts.py
122
123 test-connections: ## Test psutil.net_connections() and Process.net_connections().
124 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_connections.py
125
126 test-posix: ## POSIX specific tests.
127 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_posix.py
128
129 test-platform: ## Run specific platform tests only.
130 $(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
131
132 test-memleaks: ## Memory leak tests.
133 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest $(ARGS) psutil/tests/test_memleaks.py
134
135 test-last-failed: ## Re-run tests which failed on last run
136 $(PYTHON_ENV_VARS) $(PYTHON) -m pytest --last-failed $(ARGS)
137
138 test-coverage: ## Run test coverage.
139 # Note: coverage options are controlled by .coveragerc file
140 rm -rf .coverage htmlcov
141 $(PYTHON_ENV_VARS) $(PYTHON) -m coverage run -m pytest --ignore=psutil/tests/test_memleaks.py $(ARGS)
142 $(PYTHON) -m coverage report
143 @echo "writing results to htmlcov/index.html"
144 $(PYTHON) -m coverage html
145 $(PYTHON) -m webbrowser -t htmlcov/index.html
146
147 test-sudo: ## Run tests requiring root privileges.
148 # Use unittest runner because pytest may not be installed as root.
149 $(SUDO) $(PYTHON_ENV_VARS) $(PYTHON) -m unittest -v psutil.tests.test_sudo
150
151 test-ci: ## Run tests on GitHub CI.
152 ${MAKE} install-sysdeps
153 PIP_BREAK_SYSTEM_PACKAGES=1 ${MAKE} install-pydeps-test
154 ${MAKE} print-sysinfo
155 $(PYTHON) -m pip list
156 ${MAKE} test
157 ${MAKE} test-memleaks
158 ${MAKE} test-sudo
159
160 test-cibuildwheel: ## Run tests from cibuildwheel.
161 # testing the wheels means we can't use other test targets which are rebuilding the python extensions
162 # we also need to run the tests from another folder for pytest not to use the sources but only what's been installed
163 ${MAKE} install-sysdeps
164 mkdir -p .tests
165 cd .tests/ && python -c "from psutil.tests import print_sysinfo; print_sysinfo()"
166 cd .tests/ && $(PYTHON_ENV_VARS) PYTEST_ADDOPTS="-k 'not test_memleaks.py'" $(PYTHON) -m pytest --pyargs psutil.tests
167 cd .tests/ && $(PYTHON_ENV_VARS) PYTEST_ADDOPTS="-k test_memleaks.py" $(PYTHON) -m pytest --pyargs psutil.tests
168
169 lint-ci: ## Run all linters on GitHub CI.
170 python3 -m pip install -U black ruff rstcheck toml-sort sphinx
171 curl -fsSL https://dprint.dev/install.sh | sh
172 ${MAKE} lint-all
173
174 # ===================================================================
175 # Linters
176 # ===================================================================
177
178 ruff: ## Run ruff linter.
179 @git ls-files '*.py' | xargs $(PYTHON) -m ruff check --output-format=concise
180
181 black: ## Run black formatter.
182 @git ls-files '*.py' | xargs $(PYTHON) -m black --check --safe
183
184 dprint:
185 @$(DPRINT) check --list-different
186
187 lint-c: ## Run C linter.
188 @git ls-files '*.c' '*.h' | xargs $(PYTHON) scripts/internal/clinter.py
189
190 lint-rst: ## Run linter for .rst files.
191 @git ls-files '*.rst' | xargs rstcheck --config=pyproject.toml
192
193 lint-toml: ## Run linter for pyproject.toml.
194 @git ls-files '*.toml' | xargs toml-sort --check
195
196 lint-all: ## Run all linters
197 ${MAKE} black
198 ${MAKE} ruff
199 ${MAKE} dprint
200 ${MAKE} lint-c
201 ${MAKE} lint-rst
202 ${MAKE} lint-toml
203
204 # --- not mandatory linters (just run from time to time)
205
206 pylint: ## Python pylint
207 @git ls-files '*.py' | xargs $(PYTHON) -m pylint --rcfile=pyproject.toml --jobs=0 $(ARGS)
208
209 vulture: ## Find unused code
210 @git ls-files '*.py' | xargs $(PYTHON) -m vulture $(ARGS)
211
212 # ===================================================================
213 # Fixers
214 # ===================================================================
215
216 fix-black:
217 @git ls-files '*.py' | xargs $(PYTHON) -m black
218
219 fix-ruff:
220 @git ls-files '*.py' | xargs $(PYTHON) -m ruff check --fix --output-format=concise $(ARGS)
221
222 fix-toml: ## Fix pyproject.toml
223 @git ls-files '*.toml' | xargs toml-sort
224
225 fix-dprint:
226 @$(DPRINT) fmt
227
228 fix-all: ## Run all code fixers.
229 ${MAKE} fix-ruff
230 ${MAKE} fix-black
231 ${MAKE} fix-toml
232 ${MAKE} fix-dprint
233
234 # ===================================================================
235 # Distribution
236 # ===================================================================
237
238 sdist: ## Create tar.gz source distribution.
239 ${MAKE} generate-manifest
240 $(PYTHON_ENV_VARS) $(PYTHON) setup.py sdist
241
242 download-wheels: ## Download latest wheels hosted on github.
243 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/download_wheels.py --tokenfile=~/.github.token
244 ${MAKE} print-dist
245
246 create-wheels: ## Create .whl files
247 $(PYTHON_ENV_VARS) $(PYTHON) setup.py bdist_wheel
248 ${MAKE} check-wheels
249
250 check-sdist: ## Check sanity of source distribution.
251 $(PYTHON_ENV_VARS) $(PYTHON) -m virtualenv --clear --no-wheel --quiet build/venv
252 $(PYTHON_ENV_VARS) build/venv/bin/python -m pip install -v --isolated --quiet dist/*.tar.gz
253 $(PYTHON_ENV_VARS) build/venv/bin/python -c "import os; os.chdir('build/venv'); import psutil"
254 $(PYTHON) -m twine check --strict dist/*.tar.gz
255
256 check-wheels: ## Check sanity of wheels.
257 $(PYTHON) -m abi3audit --verbose --strict dist/*-abi3-*.whl
258 $(PYTHON) -m twine check --strict dist/*.whl
259
260 pre-release: ## Check if we're ready to produce a new release.
261 ${MAKE} clean
262 ${MAKE} sdist
263 ${MAKE} check-sdist
264 ${MAKE} install
265 @$(PYTHON) -c \
266 "import requests, sys; \
267 from packaging.version import parse; \
268 from psutil import __version__; \
269 res = requests.get('https://pypi.org/pypi/psutil/json', timeout=5); \
270 versions = sorted(res.json()['releases'], key=parse, reverse=True); \
271 sys.exit('version %r already exists on PYPI' % __version__) if __version__ in versions else 0"
272 @$(PYTHON) -c \
273 "from psutil import __version__ as ver; \
274 doc = open('docs/index.rst').read(); \
275 history = open('HISTORY.rst').read(); \
276 assert ver in doc, '%r not found in docs/index.rst' % ver; \
277 assert ver in history, '%r not found in HISTORY.rst' % ver; \
278 assert 'XXXX' not in history, 'XXXX found in HISTORY.rst';"
279 ${MAKE} download-wheels
280 ${MAKE} check-wheels
281 ${MAKE} print-hashes
282 ${MAKE} print-dist
283
284 release: ## Upload a new release.
285 ${MAKE} check-sdist
286 ${MAKE} check-wheels
287 $(PYTHON) -m twine upload dist/*.tar.gz
288 $(PYTHON) -m twine upload dist/*.whl
289 ${MAKE} git-tag-release
290
291 generate-manifest: ## Generates MANIFEST.in file.
292 $(PYTHON) scripts/internal/generate_manifest.py > MANIFEST.in
293
294 print-dist: ## Print downloaded wheels / tar.gs
295 $(PYTHON) scripts/internal/print_dist.py
296
297 git-tag-release: ## Git-tag a new release.
298 git tag -a release-`python3 -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD`
299 git push --follow-tags
300
301 # ===================================================================
302 # Printers
303 # ===================================================================
304
305 print-announce: ## Print announce of new release.
306 @$(PYTHON) scripts/internal/print_announce.py
307
308 print-timeline: ## Print releases' timeline.
309 @$(PYTHON) scripts/internal/print_timeline.py
310
311 print-access-denied: ## Print AD exceptions
312 ${MAKE} build
313 @$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/print_access_denied.py
314
315 print-api-speed: ## Benchmark all API calls
316 ${MAKE} build
317 @$(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/print_api_speed.py $(ARGS)
318
319 print-downloads: ## Print PYPI download statistics
320 $(PYTHON) scripts/internal/print_downloads.py
321
322 print-hashes: ## Prints hashes of files in dist/ directory
323 $(PYTHON) scripts/internal/print_hashes.py dist/
324
325 print-sysinfo: ## Prints system info
326 $(PYTHON) -c "from psutil.tests import print_sysinfo; print_sysinfo()"
327
328 # ===================================================================
329 # Misc
330 # ===================================================================
331
332 grep-todos: ## Look for TODOs in the source files.
333 git grep -EIn "TODO|FIXME|XXX"
334
335 bench-oneshot: ## Benchmarks for oneshot() ctx manager (see #799).
336 ${MAKE} build
337 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/bench_oneshot.py
338
339 bench-oneshot-2: ## Same as above but using perf module (supposed to be more precise)
340 ${MAKE} build
341 $(PYTHON_ENV_VARS) $(PYTHON) scripts/internal/bench_oneshot_2.py
342
343 check-broken-links: ## Look for broken links in source files.
344 git ls-files | xargs $(PYTHON) -Wa scripts/internal/check_broken_links.py
345
346 check-manifest: ## Inspect MANIFEST.in file.
347 $(PYTHON) -m check_manifest -v $(ARGS)
348
349 help: ## Display callable targets.
350 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'