Skip to content

Commit

Permalink
Merge pull request #747 from arcivanov/issue_746
Browse files Browse the repository at this point in the history
Introduce `--no-venvs` option
  • Loading branch information
arcivanov committed Sep 10, 2020
2 parents 6c63ce0 + e978fe4 commit 6f939df
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/cmdlinetest/test_help.t
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/integrationtest/python/smoke_analyze_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion src/integrationtest/python/smoke_vendorize_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 10 additions & 2 deletions src/main/python/pybuilder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/pybuilder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
50 changes: 27 additions & 23 deletions src/main/python/pybuilder/plugins/python/core_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
43 changes: 26 additions & 17 deletions src/main/python/pybuilder/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,25 @@ 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)

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()

Expand Down Expand Up @@ -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__
Expand Down

0 comments on commit 6f939df

Please sign in to comment.