Skip to content

Commit

Permalink
#1058: have Makefile use PYTHONWARNINGS=all by default for (almost) a…
Browse files Browse the repository at this point in the history
…ll commands
  • Loading branch information
giampaolo committed May 10, 2017
1 parent 3ed70c1 commit d63a1e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
56 changes: 28 additions & 28 deletions Makefile
Expand Up @@ -63,11 +63,11 @@ _:

# Compile without installing.
build: _
$(PYTHON) setup.py build
PYTHONWARNINGS=all $(PYTHON) setup.py build
@# copies compiled *.so files in ./psutil directory in order to allow
@# "import psutil" when using the interactive interpreter from within
@# this directory.
$(PYTHON) setup.py build_ext -i
PYTHONWARNINGS=all $(PYTHON) setup.py build_ext -i
rm -rf tmp

# Install this package + GIT hooks. Install is done:
Expand All @@ -77,7 +77,7 @@ install:
${MAKE} build
# make sure setuptools is installed (needed for 'develop' / edit mode)
$(PYTHON) -c "import setuptools"
$(PYTHON) setup.py develop $(INSTALL_OPTS)
PYTHONWARNINGS=all $(PYTHON) setup.py develop $(INSTALL_OPTS)
rm -rf tmp

# Uninstall this package via pip.
Expand All @@ -86,7 +86,7 @@ uninstall:

# Install PIP (only if necessary).
install-pip:
$(PYTHON) -c \
PYTHONWARNINGS=all $(PYTHON) -c \
"import sys, ssl, os, pkgutil, tempfile, atexit; \
sys.exit(0) if pkgutil.find_loader('pip') else None; \
pyexc = 'from urllib.request import urlopen' if sys.version_info[0] == 3 else 'from urllib2 import urlopen'; \
Expand Down Expand Up @@ -118,65 +118,65 @@ setup-dev-env:
# Run all tests.
test:
${MAKE} install
$(PYTHON) $(TSCRIPT)
PYTHONWARNINGS=all $(PYTHON) $(TSCRIPT)

# Run process-related API tests.
test-process:
${MAKE} install
$(PYTHON) -m unittest -v psutil.tests.test_process
PYTHONWARNINGS=all $(PYTHON) -m unittest -v psutil.tests.test_process

# Run system-related API tests.
test-system:
${MAKE} install
$(PYTHON) -m unittest -v psutil.tests.test_system
PYTHONWARNINGS=all $(PYTHON) -m unittest -v psutil.tests.test_system

# Run miscellaneous tests.
test-misc:
${MAKE} install
$(PYTHON) psutil/tests/test_misc.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_misc.py

# Test APIs dealing with strings.
test-unicode:
${MAKE} install
$(PYTHON) psutil/tests/test_unicode.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_unicode.py

# APIs sanity tests.
test-contracts:
${MAKE} install
$(PYTHON) psutil/tests/test_contracts.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_contracts.py

# Test net_connections() and Process.connections().
test-connections:
${MAKE} install
$(PYTHON) psutil/tests/test_connections.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_connections.py

# POSIX specific tests.
test-posix:
${MAKE} install
$(PYTHON) psutil/tests/test_posix.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_posix.py

# Run specific platform tests only.
test-platform:
${MAKE} install
$(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS") if getattr(psutil, x)][0])'`.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS") if getattr(psutil, x)][0])'`.py

# Memory leak tests.
test-memleaks:
${MAKE} install
$(PYTHON) psutil/tests/test_memory_leaks.py
PYTHONWARNINGS=all $(PYTHON) psutil/tests/test_memory_leaks.py

# Run a specific test by name, e.g.
# make test-by-name psutil.tests.test_system.TestSystemAPIs.test_cpu_times
test-by-name:
${MAKE} install
@$(PYTHON) -m unittest -v $(ARGS)
@PYTHONWARNINGS=all $(PYTHON) -m unittest -v $(ARGS)

# Run test coverage.
coverage:
${MAKE} install
# Note: coverage options are controlled by .coveragerc file
rm -rf .coverage htmlcov
$(PYTHON) -m coverage run $(TSCRIPT)
PYTHONWARNINGS=all $(PYTHON) -m coverage run $(TSCRIPT)
$(PYTHON) -m coverage report
@echo "writing results to htmlcov/index.html"
$(PYTHON) -m coverage html
Expand All @@ -197,7 +197,7 @@ flake8:
@git ls-files | grep \\.py$ | xargs $(PYTHON) -m flake8

check-manifest:
$(PYTHON) -m check_manifest -v $(ARGS)
PYTHONWARNINGS=all $(PYTHON) -m check_manifest -v $(ARGS)

# ===================================================================
# GIT
Expand All @@ -220,22 +220,22 @@ install-git-hooks:
# Upload source tarball on https://pypi.python.org/pypi/psutil.
upload-src:
${MAKE} clean
$(PYTHON) setup.py sdist upload
PYTHONWARNINGS=all $(PYTHON) setup.py sdist upload

# Download exes/wheels hosted on appveyor.
win-download-exes:
$(PYTHON) scripts/internal/download_exes.py --user giampaolo --project psutil
PYTHONWARNINGS=all $(PYTHON) scripts/internal/download_exes.py --user giampaolo --project psutil

# Upload exes/wheels in dist/* directory to PYPI.
win-upload-exes:
$(PYTHON) -m twine upload dist/*.exe
$(PYTHON) -m twine upload dist/*.whl
PYTHONWARNINGS=all $(PYTHON) -m twine upload dist/*.exe
PYTHONWARNINGS=all $(PYTHON) -m twine upload dist/*.whl

# All the necessary steps before making a release.
pre-release:
${MAKE} clean
${MAKE} install # to import psutil from download_exes.py
$(PYTHON) -c \
PYTHONWARNINGS=all $(PYTHON) -c \
"from psutil import __version__ as ver; \
doc = open('docs/index.rst').read(); \
history = open('HISTORY.rst').read(); \
Expand All @@ -244,18 +244,18 @@ pre-release:
assert 'XXXX' not in history; \
"
${MAKE} win-download-exes
$(PYTHON) setup.py sdist
PYTHONWARNINGS=all $(PYTHON) setup.py sdist

# Create a release: creates tar.gz and exes/wheels, uploads them,
# upload doc, git tag release.
release:
${MAKE} pre-release
$(PYTHON) -m twine upload dist/* # upload tar.gz, exes, wheels on PYPI
PYTHONWARNINGS=all $(PYTHON) -m twine upload dist/* # upload tar.gz, exes, wheels on PYPI
${MAKE} git-tag-release

# Print announce of new release.
print-announce:
@$(PYTHON) scripts/internal/print_announce.py
@PYTHONWARNINGS=all $(PYTHON) scripts/internal/print_announce.py

# ===================================================================
# Misc
Expand All @@ -267,12 +267,12 @@ grep-todos:
# run script which benchmarks oneshot() ctx manager (see #799)
bench-oneshot:
${MAKE} install
$(PYTHON) scripts/internal/bench_oneshot.py
PYTHONWARNINGS=all $(PYTHON) scripts/internal/bench_oneshot.py

# same as above but using perf module (supposed to be more precise)
bench-oneshot-2:
${MAKE} install
$(PYTHON) scripts/internal/bench_oneshot_2.py
PYTHONWARNINGS=all $(PYTHON) scripts/internal/bench_oneshot_2.py

# generate a doc.zip file and manually upload it to PYPI.
doc:
Expand All @@ -282,4 +282,4 @@ doc:

# check whether the links mentioned in some files are valid.
check-broken-links:
git ls-files | grep \\.rst$ | xargs $(PYTHON) scripts/internal/check_broken_links.py
git ls-files | grep \\.rst$ | xargs PYTHONWARNINGS=all $(PYTHON) scripts/internal/check_broken_links.py
5 changes: 0 additions & 5 deletions psutil/tests/__init__.py
Expand Up @@ -103,11 +103,6 @@
]


# Enable all warnings by default.
if 'PYTHONWARNINGS' not in os.environ:
warnings.simplefilter('always')


# ===================================================================
# --- constants
# ===================================================================
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Expand Up @@ -16,10 +16,13 @@
import sys
import tempfile
import warnings
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension

with warnings.catch_warnings():
warnings.simplefilter("ignore")
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension

HERE = os.path.abspath(os.path.dirname(__file__))

Expand Down

0 comments on commit d63a1e3

Please sign in to comment.