1# Shortcuts for various tasks (UNIX only). 2# To use a specific Python version run: 3# $ make install PYTHON=python3.3 4 5# You can set these variables from the command line. 6PYTHON = python 7TSCRIPT = test/test_psutil.py 8 9all: test 10 11clean: 12 rm -f `find . -type f -name \*.py[co]` 13 rm -f `find . -type f -name \*.so` 14 rm -f `find . -type f -name .\*~` 15 rm -f `find . -type f -name \*.orig` 16 rm -f `find . -type f -name \*.bak` 17 rm -f `find . -type f -name \*.rej` 18 rm -rf `find . -type d -name __pycache__` 19 rm -rf *.core 20 rm -rf *.egg-info 21 rm -rf *\$testfile* 22 rm -rf .coverage 23 rm -rf .tox 24 rm -rf build 25 rm -rf dist 26 rm -rf docs/_build 27 rm -rf htmlcov 28 29build: clean 30 $(PYTHON) setup.py build 31 @# copies *.so files in ./psutil directory in order to allow 32 @# "import psutil" when using the interactive interpreter from within 33 @# this directory. 34 $(PYTHON) setup.py build_ext -i 35 36# useful deps which are nice to have while developing / testing 37setup-dev-env: 38 python -c "import urllib2; \ 39 r = urllib2.urlopen('https://bootstrap.pypa.io/get-pip.py'); \ 40 open('/tmp/get-pip.py', 'w').write(r.read());" 41 $(PYTHON) /tmp/get-pip.py --user 42 rm /tmp/get-pip.py 43 $(PYTHON) -m pip install --user --upgrade pip 44 $(PYTHON) -m pip install --user --upgrade \ 45 coverage \ 46 flake8 \ 47 ipaddress \ 48 ipdb \ 49 mock==1.0.1 \ 50 nose \ 51 pep8 \ 52 pyflakes \ 53 sphinx \ 54 sphinx-pypi-upload \ 55 unittest2 \ 56 57install: build 58 $(PYTHON) setup.py install --user 59 60uninstall: 61 cd ..; $(PYTHON) -m pip uninstall -y -v psutil 62 63test: install 64 $(PYTHON) $(TSCRIPT) 65 66test-process: install 67 $(PYTHON) -m unittest -v test.test_psutil.TestProcess 68 69test-system: install 70 $(PYTHON) -m unittest -v test.test_psutil.TestSystemAPIs 71 72test-memleaks: install 73 $(PYTHON) test/test_memory_leaks.py 74 75# Run a specific test by name; e.g. "make test-by-name disk_" will run 76# all test methods containing "disk_" in their name. 77# Requires "pip install nose". 78test-by-name: install 79 @$(PYTHON) -m nose test/test_psutil.py test/_* --nocapture -v -m $(filter-out $@,$(MAKECMDGOALS)) 80 81# Same as above but for test_memory_leaks.py script. 82test-memleaks-by-name: install 83 @$(PYTHON) -m nose test/test_memory_leaks.py --nocapture -v -m $(filter-out $@,$(MAKECMDGOALS)) 84 85coverage: install 86 # Note: coverage options are controlled by .coveragerc file 87 rm -rf .coverage htmlcov 88 $(PYTHON) -m coverage run $(TSCRIPT) 89 $(PYTHON) -m coverage report 90 @echo "writing results to htmlcov/index.html" 91 $(PYTHON) -m coverage html 92 $(PYTHON) -m webbrowser -t htmlcov/index.html 93 94pep8: 95 @git ls-files | grep \\.py$ | xargs $(PYTHON) -m pep8 96 97pyflakes: 98 @export PYFLAKES_NODOCTEST=1 && \ 99 git ls-files | grep \\.py$ | xargs $(PYTHON) -m pyflakes 100 101flake8: 102 @git ls-files | grep \\.py$ | xargs $(PYTHON) -m flake8 103 104# Upload source tarball on https://pypi.python.org/pypi/psutil. 105upload-src: clean 106 $(PYTHON) setup.py sdist upload 107 108# Build and upload doc on https://pythonhosted.org/psutil/. 109# Requires "pip install sphinx-pypi-upload". 110upload-doc: 111 cd docs; make html 112 $(PYTHON) setup.py upload_sphinx --upload-dir=docs/_build/html 113 114# git-tag a new release 115git-tag-release: 116 git tag -a release-`python -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD` 117 echo "done; now run 'git push --follow-tags' to push the new tag on the remote repo" 118 119# install GIT pre-commit hook 120install-git-hooks: 121 ln -sf ../../.git-pre-commit .git/hooks/pre-commit 122 chmod +x .git/hooks/pre-commit 123