From d63a1e3d90e168b195442ae2b4e95db1e30d7370 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 10 May 2017 16:32:03 +0200 Subject: #1058: have Makefile use PYTHONWARNINGS=all by default for (almost) all commands --- Makefile | 56 ++++++++++++++++++++++++------------------------ psutil/tests/__init__.py | 5 ----- setup.py | 11 ++++++---- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 953225e3..12469d4c 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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. @@ -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'; \ @@ -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 @@ -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 @@ -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(); \ @@ -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 @@ -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: @@ -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 diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 85075d12..22ccc52d 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -103,11 +103,6 @@ __all__ = [ ] -# Enable all warnings by default. -if 'PYTHONWARNINGS' not in os.environ: - warnings.simplefilter('always') - - # =================================================================== # --- constants # =================================================================== diff --git a/setup.py b/setup.py index c4f3bcbc..05c212ab 100755 --- a/setup.py +++ b/setup.py @@ -16,10 +16,13 @@ import platform 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__)) -- cgit v1.2.1