From e978fe43ea9c182dc7878f5a9e3e6b97271bef3a Mon Sep 17 00:00:00 2001 From: Arcadiy Ivanov Date: Thu, 10 Sep 2020 00:11:14 -0400 Subject: [PATCH] Introduce `--no-venvs` option Short-circuits all VEnv management logic defaulting to incorrect 0.11 behaviors Also fix test names fixes #746 --- src/cmdlinetest/test_help.t | 1 + .../python/smoke_analyze_tests.py | 2 +- ...oke_install_dependencies_no_venvs_tests.py | 30 +++++++++++ .../smoke_install_dependencies_tests.py | 2 +- ...phinx_pyb_quickstart_with_api_doc_tests.py | 2 +- .../python/smoke_sphinx_quickstart_tests.py | 2 +- .../python/smoke_vendorize_tests.py | 2 +- src/main/python/pybuilder/cli.py | 12 ++++- src/main/python/pybuilder/core.py | 3 +- .../pybuilder/plugins/python/core_plugin.py | 50 ++++++++++--------- src/main/python/pybuilder/reactor.py | 43 +++++++++------- 11 files changed, 101 insertions(+), 48 deletions(-) create mode 100644 src/integrationtest/python/smoke_install_dependencies_no_venvs_tests.py diff --git a/src/cmdlinetest/test_help.t b/src/cmdlinetest/test_help.t index 207c0ee7a..7eddb8041 100644 --- a/src/cmdlinetest/test_help.t +++ b/src/cmdlinetest/test_help.t @@ -51,6 +51,7 @@ Usage: Exclude any task dependencies (dangerous, may break the build in unexpected ways) --reset-plugins Reset plugins directory prior to running the build + --no-venvs Disables the use of Python Virtual Environments Output Options: Modifies the messages printed during a build. diff --git a/src/integrationtest/python/smoke_analyze_tests.py b/src/integrationtest/python/smoke_analyze_tests.py index 408bc2d23..32ef9c52f 100644 --- a/src/integrationtest/python/smoke_analyze_tests.py +++ b/src/integrationtest/python/smoke_analyze_tests.py @@ -3,7 +3,7 @@ from smoke_itest_support import SmokeIntegrationTestSupport -class CleanSmokeTest(SmokeIntegrationTestSupport): +class AnalyzeSmokeTest(SmokeIntegrationTestSupport): def test_smoke_analyze_publish_no_integration_no_coverage(self): self.smoke_test("-v", "-X", "analyze", "publish", "--force-exclude", "run_integration_tests", diff --git a/src/integrationtest/python/smoke_install_dependencies_no_venvs_tests.py b/src/integrationtest/python/smoke_install_dependencies_no_venvs_tests.py new file mode 100644 index 000000000..9efdd94a1 --- /dev/null +++ b/src/integrationtest/python/smoke_install_dependencies_no_venvs_tests.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# +# This file is part of PyBuilder +# +# Copyright 2011-2020 PyBuilder Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from smoke_itest_support import SmokeIntegrationTestSupport + + +class InstallDependenciesNoVenvsSmokeTest(SmokeIntegrationTestSupport): + def test_clean(self): + self.smoke_test("-v", "-X", "--no-venvs", "install_dependencies") + + +if __name__ == "__main__": + unittest.main() diff --git a/src/integrationtest/python/smoke_install_dependencies_tests.py b/src/integrationtest/python/smoke_install_dependencies_tests.py index a6691fd7f..b995aebba 100644 --- a/src/integrationtest/python/smoke_install_dependencies_tests.py +++ b/src/integrationtest/python/smoke_install_dependencies_tests.py @@ -21,7 +21,7 @@ from smoke_itest_support import SmokeIntegrationTestSupport -class CleanSmokeTest(SmokeIntegrationTestSupport): +class InstallDependenciesSmokeTest(SmokeIntegrationTestSupport): def test_clean(self): self.smoke_test("-v", "-X", "install_dependencies") diff --git a/src/integrationtest/python/smoke_sphinx_pyb_quickstart_with_api_doc_tests.py b/src/integrationtest/python/smoke_sphinx_pyb_quickstart_with_api_doc_tests.py index 40d40273d..108200a4f 100644 --- a/src/integrationtest/python/smoke_sphinx_pyb_quickstart_with_api_doc_tests.py +++ b/src/integrationtest/python/smoke_sphinx_pyb_quickstart_with_api_doc_tests.py @@ -22,7 +22,7 @@ from smoke_itest_support import SmokeIntegrationTestSupport -class SphinxSmokeTest(SmokeIntegrationTestSupport): +class SphinxWithApiSmokeTest(SmokeIntegrationTestSupport): def test_smoke_sphinx_pyb_quickstart_with_api_doc(self): self.smoke_test("-v", "-X", "-P", "sphinx_run_apidoc=True", "sphinx_pyb_quickstart", "sphinx_generate_documentation") diff --git a/src/integrationtest/python/smoke_sphinx_quickstart_tests.py b/src/integrationtest/python/smoke_sphinx_quickstart_tests.py index 39e03491e..ecf33c64d 100644 --- a/src/integrationtest/python/smoke_sphinx_quickstart_tests.py +++ b/src/integrationtest/python/smoke_sphinx_quickstart_tests.py @@ -22,7 +22,7 @@ from smoke_itest_support import SmokeIntegrationTestSupport -class SphinxSmokeTest(SmokeIntegrationTestSupport): +class SphinxQuickstartSmokeTest(SmokeIntegrationTestSupport): def test_smoke_sphinx_quickstart(self): self.smoke_test("-v", "-X", "sphinx_quickstart", "sphinx_generate_documentation") diff --git a/src/integrationtest/python/smoke_vendorize_tests.py b/src/integrationtest/python/smoke_vendorize_tests.py index 090b0ae95..198144496 100644 --- a/src/integrationtest/python/smoke_vendorize_tests.py +++ b/src/integrationtest/python/smoke_vendorize_tests.py @@ -21,7 +21,7 @@ from smoke_itest_support import SmokeIntegrationTestSupport -class SphinxSmokeTest(SmokeIntegrationTestSupport): +class VendorizeSmokeTest(SmokeIntegrationTestSupport): PROJECT_FILES = list(SmokeIntegrationTestSupport.PROJECT_FILES) + ["docs"] def test_smoke_analyze_publish_no_integration_no_coverage(self): diff --git a/src/main/python/pybuilder/cli.py b/src/main/python/pybuilder/cli.py index a40f21bba..8d6343329 100644 --- a/src/main/python/pybuilder/cli.py +++ b/src/main/python/pybuilder/cli.py @@ -168,6 +168,12 @@ def error(msg): default=False, help="Reset plugins directory prior to running the build") + project_group.add_option("--no-venvs", + action="store_true", + dest="no_venvs", + default=False, + help="Disables the use of Python Virtual Environments") + parser.add_option_group(project_group) output_group = optparse.OptionGroup( @@ -427,7 +433,8 @@ def main(*args): exclude_optional_tasks=options.exclude_optional_tasks, exclude_tasks=options.exclude_tasks, exclude_all_optional=options.exclude_all_optional, - offline=options.offline + offline=options.offline, + no_venvs=options.no_venvs ) if options.list_tasks: print_list_of_tasks(reactor, quiet=options.very_quiet) @@ -457,7 +464,8 @@ def main(*args): exclude_tasks=options.exclude_tasks, exclude_all_optional=options.exclude_all_optional, reset_plugins=options.reset_plugins, - offline=options.offline + offline=options.offline, + no_venvs=options.no_venvs ) if options.verbose or options.debug: diff --git a/src/main/python/pybuilder/core.py b/src/main/python/pybuilder/core.py index c14e7c6bc..d89e5b8e2 100644 --- a/src/main/python/pybuilder/core.py +++ b/src/main/python/pybuilder/core.py @@ -421,11 +421,12 @@ class Project(object): as well as some convenience methods to access these properties. """ - def __init__(self, basedir, version="1.0.dev0", name=None, offline=False): + def __init__(self, basedir, version="1.0.dev0", name=None, offline=False, no_venvs=False): self.name = name self._version = None self._dist_version = None self.offline = offline + self.no_venvs = no_venvs self.version = version self.basedir = ap(basedir) if not self.name: diff --git a/src/main/python/pybuilder/plugins/python/core_plugin.py b/src/main/python/pybuilder/plugins/python/core_plugin.py index fdd11a7aa..8223ff9b1 100644 --- a/src/main/python/pybuilder/plugins/python/core_plugin.py +++ b/src/main/python/pybuilder/plugins/python/core_plugin.py @@ -72,31 +72,35 @@ def create_venvs(logger, project, reactor): logger.debug("Creating log directory '%s'", log_dir) mkdir(log_dir) - venv_dependencies_map = project.get_property("venv_dependencies") - if "build" not in venv_dependencies_map: - venv_dependencies_map["build"] = as_list(project.build_dependencies) + as_list(project.dependencies) - if "test" not in venv_dependencies_map: - venv_dependencies_map["test"] = as_list(project.dependencies) - per = reactor.python_env_registry system_env = per["system"] - clear = project.get_property("refresh_venvs") or system_env.is_pypy - for venv_name in project.get_property("venv_names"): - venv_dir = project.expand_path("$dir_target/venv", venv_name, - system_env.versioned_dir_name) - logger.info("Creating target '%s' VEnv in '%s'%s", venv_name, venv_dir, " (refreshing)" if clear else "") - per[venv_name] = current_env = PythonEnv(venv_dir, reactor).create_venv(with_pip=True, - symlinks=system_env.venv_symlinks, - clear=clear, - offline=project.offline) - venv_dependencies = venv_dependencies_map.get(venv_name) - if venv_dependencies: - install_log_path = project.expand_path("$dir_install_logs", "venv_%s_install_logs" % venv_name) - constraints_file_name = project.get_property("install_dependencies_constraints") - current_env.install_dependencies(venv_dependencies, - install_log_path=install_log_path, - local_mapping={}, - constraints_file_name=constraints_file_name) + if not project.no_venvs: + venv_dependencies_map = project.get_property("venv_dependencies") + if "build" not in venv_dependencies_map: + venv_dependencies_map["build"] = as_list(project.build_dependencies) + as_list(project.dependencies) + if "test" not in venv_dependencies_map: + venv_dependencies_map["test"] = as_list(project.dependencies) + + clear = project.get_property("refresh_venvs") or system_env.is_pypy + for venv_name in project.get_property("venv_names"): + venv_dir = project.expand_path("$dir_target/venv", venv_name, + system_env.versioned_dir_name) + logger.info("Creating target '%s' VEnv in '%s'%s", venv_name, venv_dir, " (refreshing)" if clear else "") + per[venv_name] = current_env = PythonEnv(venv_dir, reactor).create_venv(with_pip=True, + symlinks=system_env.venv_symlinks, + clear=clear, + offline=project.offline) + venv_dependencies = venv_dependencies_map.get(venv_name) + if venv_dependencies: + install_log_path = project.expand_path("$dir_install_logs", "venv_%s_install_logs" % venv_name) + constraints_file_name = project.get_property("install_dependencies_constraints") + current_env.install_dependencies(venv_dependencies, + install_log_path=install_log_path, + local_mapping={}, + constraints_file_name=constraints_file_name) + else: + for venv_name in project.get_property("venv_names"): + per[venv_name] = system_env def list_packages(project): diff --git a/src/main/python/pybuilder/reactor.py b/src/main/python/pybuilder/reactor.py index b1b06b556..6282cfa26 100644 --- a/src/main/python/pybuilder/reactor.py +++ b/src/main/python/pybuilder/reactor.py @@ -182,7 +182,8 @@ def prepare_build(self, exclude_tasks=None, exclude_all_optional=False, reset_plugins=False, - offline=False): + offline=False, + no_venvs=False): if not property_overrides: property_overrides = {} Reactor._set_current_instance(self) @@ -190,11 +191,16 @@ def prepare_build(self, project_directory, project_descriptor = self.verify_project_directory( project_directory, project_descriptor) + if no_venvs: + self.logger.warn("Python Virtual Environments are DISABLED!") + self.logger.warn("This will revert to INCORRECT PyBuilder v0.11 behaviors!") + self.logger.warn("Coverage results may be unreliable!") + self.logger.debug("Loading project module from %s", project_descriptor) - self.project = Project(basedir=project_directory, offline=offline) + self.project = Project(basedir=project_directory, offline=offline, no_venvs=no_venvs) - self._setup_plugin_directory(reset_plugins) + self._setup_plugin_directory(reset_plugins, no_venvs) self._setup_deferred_plugin_import() @@ -499,22 +505,25 @@ def python_env_registry(self): def pybuilder_venv(self): return self._python_env_registry["pybuilder"] - def _setup_plugin_directory(self, reset_plugins): + def _setup_plugin_directory(self, reset_plugins, no_venvs): per = self.python_env_registry system_env = per["system"] - plugin_dir = self._plugin_dir = np(jp(self.project.basedir, ".pybuilder", "plugins", - system_env.versioned_dir_name)) - - self.logger.debug("Setting up plugins VEnv at '%s'%s", plugin_dir, " (resetting)" if reset_plugins else "") - plugin_env = per["pybuilder"] = PythonEnv(plugin_dir, self).create_venv(with_pip=True, - symlinks=system_env.venv_symlinks, - upgrade=True, - clear=(reset_plugins or - system_env.is_pypy), - offline=self.project.offline) - - prepend_env_to_path(plugin_env, sys.path) - patch_mp_pyb_env(plugin_env) + + if not no_venvs: + plugin_dir = self._plugin_dir = np(jp(self.project.basedir, ".pybuilder", "plugins", + system_env.versioned_dir_name)) + + self.logger.debug("Setting up plugins VEnv at '%s'%s", plugin_dir, " (resetting)" if reset_plugins else "") + plugin_env = per["pybuilder"] = PythonEnv(plugin_dir, self).create_venv(with_pip=True, + symlinks=system_env.venv_symlinks, + upgrade=True, + clear=(reset_plugins or + system_env.is_pypy), + offline=self.project.offline) + prepend_env_to_path(plugin_env, sys.path) + patch_mp_pyb_env(plugin_env) + else: + per["pybuilder"] = system_env def _setup_deferred_plugin_import(self): self._old_import = __import__