Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""acquire a source distribution (either by loading a local file or triggering a build)"""
if not config.option.sdistonly and (config.sdistsrc or config.option.installpkg):
path = get_local_package(config)
else:
try:
path = build_package(config, session)
except tox.exception.InvocationError as exception:
error("FAIL could not package project - v = {!r}".format(exception))
return None
sdist_file = config.distshare.join(path.basename)
if sdist_file != path:
info("copying new sdistfile to {!r}".format(str(sdist_file)))
try:
sdist_file.dirpath().ensure(dir=1)
except py.error.Error:
warning("could not copy distfile to {}".format(sdist_file.dirpath()))
else:
path.copy(sdist_file)
return path
def ensure_pip_os_environ_ok(self, env):
for key in ("PIP_RESPECT_VIRTUALENV", "PIP_REQUIRE_VIRTUALENV", "__PYVENV_LAUNCHER__"):
env.pop(key, None)
if all("PYTHONPATH" not in i for i in (self.envconfig.passenv, self.envconfig.setenv)):
# If PYTHONPATH not explicitly asked for, remove it.
if "PYTHONPATH" in env:
if sys.version_info < (3, 4) or bool(env["PYTHONPATH"]):
# https://docs.python.org/3/whatsnew/3.4.html#changes-in-python-command-behavior
# In a posix shell, setting the PATH environment variable to an empty value is
# equivalent to not setting it at all.
reporter.warning(
"Discarding $PYTHONPATH from environment, to override "
"specify PYTHONPATH in 'passenv' in your configuration."
)
env.pop("PYTHONPATH")
# installing packages at user level may mean we're not installing inside the venv
env["PIP_USER"] = "0"
# installing without dependencies may lead to broken packages
env["PIP_NO_DEPS"] = "0"
def _check_external_allowed_and_warn(self, path):
if not self.is_allowed_external(path):
reporter.warning(
"test command found but not installed in testenv\n"
" cmd: {}\n"
" env: {}\n"
"Maybe you forgot to specify a dependency? "
"See also the whitelist_externals envconfig setting.\n\n"
"DEPRECATION WARNING: this will be an error in tox 4 and above!".format(
path, self.envconfig.envdir
)
if p.check():
return p
if not p.dirpath().check(dir=1):
raise tox.exception.MissingDirectory(p.dirpath())
reporter.info("determining {}".format(p))
candidates = p.dirpath().listdir(p.basename)
if len(candidates) == 0:
raise MissingDependency(package_spec)
if len(candidates) > 1:
version_package = []
for filename in candidates:
version = get_version_from_filename(filename.basename)
if version is not None:
version_package.append((version, filename))
else:
reporter.warning("could not determine version of: {}".format(str(filename)))
if not version_package:
raise tox.exception.MissingDependency(package_spec)
version_package.sort()
_, package_with_largest_version = version_package[-1]
return package_with_largest_version
else:
return candidates[0]
else:
ignore_ret = False
try:
self._pcall(
argv,
cwd=cwd,
action=action,
redirect=redirect,
ignore_ret=ignore_ret,
is_test_command=True,
)
except tox.exception.InvocationError as err:
if ignore_outcome:
msg = "command failed but result from testenv is ignored\ncmd:"
reporter.warning("{} {}".format(msg, err))
self.status = "ignored failed command"
continue # keep processing commands
reporter.error(str(err))
self.status = "commands failed"
if not ignore_errors:
break # Don't process remaining commands
except KeyboardInterrupt:
self.status = "keyboardinterrupt"
raise
def wheel_build_package(config, session, venv):
if config.isolated_build:
reporter.warning("Disabling isolated_build, not supported with wheels.")
return wheel_build(config, session, venv)