summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-05-01 13:37:37 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-05-01 13:37:37 +0200
commit6f4e38220d9da33931ff9a307d20025a6916c258 (patch)
treef625ae05775d3cd872670152c871e08eb6ef0c13
parent8d8a7804d159e5b80378000b57bbfbaf63ce6e8f (diff)
downloadpsutil-6f4e38220d9da33931ff9a307d20025a6916c258.tar.gz
Drastically improve "make test/build" speed.
Doing "make install" before any test is slow and not really necessary. Instead do "make build", and remove the part import setuptools and test psutil can be imported (do that in make install instead). This way I went down from 0.8 secs (install phase before starting the test) to 0.3 secs!
-rw-r--r--.cirrus.yml4
-rw-r--r--Makefile44
-rwxr-xr-xscripts/internal/purge_installation.py2
-rwxr-xr-xscripts/internal/winmake.py28
4 files changed, 39 insertions, 39 deletions
diff --git a/.cirrus.yml b/.cirrus.yml
index 4b8676bc..a0b8f1f0 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -6,7 +6,7 @@ freebsd_13_py3_task:
install_script:
- pkg install -y python3 gcc py37-pip
script:
- - python3 -m pip install --user setuptools concurrencytest
+ - python3 -m pip install --user setuptools
- make clean
- make install
- make test
@@ -22,7 +22,7 @@ freebsd_11_py2_task:
install_script:
- pkg install -y python gcc py27-pip
script:
- - python2.7 -m pip install --user setuptools ipaddress mock concurrencytest
+ - python2.7 -m pip install --user setuptools ipaddress mock
- make clean
- make install
- make test
diff --git a/Makefile b/Makefile
index 86727ca7..2b2a98ef 100644
--- a/Makefile
+++ b/Makefile
@@ -71,17 +71,17 @@ clean: ## Remove all build files.
_:
build: _ ## Compile (in parallel) without installing.
- # make sure setuptools is installed (needed for 'develop' / edit mode)
- $(PYTHON) -c "import setuptools"
@# "build_ext -i" copies compiled *.so files in ./psutil directory in order
@# to allow "import psutil" when using the interactive interpreter from
@# within this directory.
PYTHONWARNINGS=all $(PYTHON) setup.py build_ext -i $(BUILD_OPTS)
- $(PYTHON) -c "import psutil" # make sure it actually worked
install: ## Install this package as current user in "edit" mode.
+ # make sure setuptools is installed (needed for 'develop' / edit mode)
+ $(PYTHON) -c "import setuptools"
${MAKE} build
PYTHONWARNINGS=all $(PYTHON) setup.py develop $(INSTALL_OPTS)
+ $(PYTHON) -c "import psutil" # make sure it actually worked
uninstall: ## Uninstall this package via pip.
cd ..; $(PYTHON) -m pip uninstall -y -v psutil || true
@@ -117,63 +117,63 @@ setup-dev-env: ## Install GIT hooks, pip, test deps (also upgrades them).
# ===================================================================
test: ## Run all tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS)
test-parallel: ## Run all tests in parallel.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) --parallel
test-process: ## Run process-related API tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_process.py
test-system: ## Run system-related API tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_system.py
test-misc: ## Run miscellaneous tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_misc.py
test-testutils: ## Run test utils tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_testutils.py
test-unicode: ## Test APIs dealing with strings.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_unicode.py
test-contracts: ## APIs sanity tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_contracts.py
test-connections: ## Test net_connections() and Process.connections().
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_connections.py
test-posix: ## POSIX specific tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_posix.py
test-platform: ## Run specific platform tests only.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(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
test-memleaks: ## Memory leak tests.
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_memory_leaks.py
test-by-name: ## e.g. make test-by-name ARGS=psutil.tests.test_system.TestSystemAPIs
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS)
test-failed: ## Re-run tests which failed on last run
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS) --last-failed
test-coverage: ## Run test coverage.
- ${MAKE} install
+ ${MAKE} build
# Note: coverage options are controlled by .coveragerc file
rm -rf .coverage htmlcov
$(TEST_PREFIX) $(PYTHON) -m coverage run $(TSCRIPT)
@@ -284,11 +284,11 @@ print-timeline: ## Print releases' timeline.
@$(PYTHON) scripts/internal/print_timeline.py
print-access-denied: ## Print AD exceptions
- ${MAKE} install
+ ${MAKE} build
@$(TEST_PREFIX) $(PYTHON) scripts/internal/print_access_denied.py
print-api-speed: ## Benchmark all API calls
- ${MAKE} install
+ ${MAKE} build
@$(TEST_PREFIX) $(PYTHON) scripts/internal/print_api_speed.py $(ARGS)
# ===================================================================
@@ -299,11 +299,11 @@ grep-todos: ## Look for TODOs in the source files.
git grep -EIn "TODO|FIXME|XXX"
bench-oneshot: ## Benchmarks for oneshot() ctx manager (see #799).
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) scripts/internal/bench_oneshot.py
bench-oneshot-2: ## Same as above but using perf module (supposed to be more precise)
- ${MAKE} install
+ ${MAKE} build
$(TEST_PREFIX) $(PYTHON) scripts/internal/bench_oneshot_2.py
check-broken-links: ## Look for broken links in source files.
diff --git a/scripts/internal/purge_installation.py b/scripts/internal/purge_installation.py
index 50c00463..8a9597f0 100755
--- a/scripts/internal/purge_installation.py
+++ b/scripts/internal/purge_installation.py
@@ -30,7 +30,7 @@ def rmpath(path):
def main():
locations = [site.getusersitepackages()]
- locations.extend(site.getsitepackages())
+ locations += site.getsitepackages()
for root in locations:
if os.path.isdir(root):
for name in os.listdir(root):
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index eebd1692..c7091ac4 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -399,7 +399,7 @@ def lint():
def test(name=""):
"""Run tests"""
- install()
+ build()
test_setup()
sh("%s %s %s" % (PYTHON, RUNNER_PY, name))
@@ -407,7 +407,7 @@ def test(name=""):
def coverage():
"""Run coverage tests."""
# Note: coverage options are controlled by .coveragerc file
- install()
+ build()
test_setup()
sh("%s -m coverage run %s" % (PYTHON, RUNNER_PY))
sh("%s -m coverage report" % PYTHON)
@@ -417,70 +417,70 @@ def coverage():
def test_process():
"""Run process tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_process.py" % PYTHON)
def test_system():
"""Run system tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_system.py" % PYTHON)
def test_platform():
"""Run windows only tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_windows.py" % PYTHON)
def test_misc():
"""Run misc tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_misc.py" % PYTHON)
def test_unicode():
"""Run unicode tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_unicode.py" % PYTHON)
def test_connections():
"""Run connections tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_connections.py" % PYTHON)
def test_contracts():
"""Run contracts tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_contracts.py" % PYTHON)
def test_by_name(name):
"""Run test by name"""
- install()
+ build()
test_setup()
sh("%s -m unittest -v %s" % (PYTHON, name))
def test_failed():
"""Re-run tests which failed on last run."""
- install()
+ build()
test_setup()
sh("%s %s --last-failed" % (PYTHON, RUNNER_PY))
def test_memleaks():
"""Run memory leaks tests"""
- install()
+ build()
test_setup()
sh("%s psutil\\tests\\test_memory_leaks.py" % PYTHON)
@@ -509,14 +509,14 @@ def bench_oneshot_2():
def print_access_denied():
"""Print AD exceptions raised by all Process methods."""
- install()
+ build()
test_setup()
sh("%s -Wa scripts\\internal\\print_access_denied.py" % PYTHON)
def print_api_speed():
"""Benchmark all API calls."""
- install()
+ build()
test_setup()
sh("%s -Wa scripts\\internal\\print_api_speed.py" % PYTHON)