Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_sdist(config, session):
setup = config.setupdir.join("setup.py")
pyproject = config.setupdir.join("pyproject.toml")
setup_check = setup.check()
if not setup_check and not pyproject.check():
reporter.error(
"No pyproject.toml or setup.py file found. The expected locations are:\n"
" {pyproject} or {setup}\n"
"You can\n"
" 1. Create one:\n"
" https://tox.readthedocs.io/en/latest/example/package.html\n"
" 2. Configure tox to avoid running sdist:\n"
" https://tox.readthedocs.io/en/latest/example/general.html\n"
" 3. Configure tox to use an isolated_build".format(pyproject=pyproject, setup=setup)
)
raise SystemExit(1)
if not setup_check:
reporter.error(
"pyproject.toml file found.\n"
"To use a PEP 517 build-backend you are required to "
"configure tox to use an isolated_build:\n"
"https://tox.readthedocs.io/en/latest/example/package.html\n"
with open(str(setup)) as fp:
for line in fp:
if line and line[0] == "#":
continue
data.append(line)
if not "".join(data).strip():
reporter.error("setup.py is empty")
raise SystemExit(1)
reporter.error(
"No dist directory found. Please check setup.py, e.g with:\n"
" python setup.py bdist_wheel"
)
raise SystemExit(1)
else:
if not dists:
reporter.error(
"No distributions found in the dist directory found. Please check setup.py, e.g with:\n"
" python setup.py bdist_wheel"
)
raise SystemExit(1)
return dists[0]
def _build_venvs(self):
try:
need_to_run = OrderedDict((v, self.getvenv(v)) for v in self._evaluated_env_list)
try:
venv_order = stable_topological_sort(
OrderedDict((name, v.envconfig.depends) for name, v in need_to_run.items())
)
venvs = OrderedDict((v, need_to_run[v]) for v in venv_order)
return venvs
except ValueError as exception:
reporter.error("circular dependency detected: {}".format(exception))
except LookupError:
pass
except tox.exception.ConfigError as exception:
reporter.error(str(exception))
raise SystemExit(1)
def wheel_build(config, session, venv):
setup = config.setupdir.join("setup.py")
if not setup.check():
reporter.error("No setup.py file found. The expected location is: {}".format(setup))
raise SystemExit(1)
with session.newaction(venv.name, "packaging") as action:
def wheel_is_allowed_external(path, is_allowed_external=venv.is_allowed_external):
if not is_allowed_external(path):
raise RuntimeError("Couldn't find interpreter inside {} for building".format(venv))
return True
with patch(venv, 'is_allowed_external', wheel_is_allowed_external):
venv.update(action=action)
if not (session.config.option.wheel_dirty or venv.envconfig.wheel_dirty):
action.setactivity("wheel-make", "cleaning up build directory ...")
ensure_empty_dir(config.setupdir.join("build"))
ensure_empty_dir(config.distdir)
venv.test(
name="wheel-make",
commands=[["python", setup, "bdist_wheel", "--dist-dir", config.distdir]],
if not (
# doesn't exist => OK
not venv.path.exists()
# does exist, but it's empty => OK
or not dir_items
# tox has marked this as an environment it has created in the past
or ".tox-config1" in dir_items
# it exists and we're on windows with Lib and Scripts => OK
or (INFO.IS_WIN and dir_items > {"Scripts", "Lib"})
# non-windows, with lib and bin => OK
or dir_items > {"bin", "lib"}
# pypy has a different lib folder => OK
or dir_items > {"bin", "lib_pypy"}
):
venv.status = "error"
reporter.error(
"cowardly refusing to delete `envdir` (it does not look like a virtualenv): "
"{}".format(venv.path)
)
raise SystemExit(2)
if within_parallel:
if venv.path.exists():
# do not delete the log folder as that's used by parent
for content in venv.path.listdir():
if not content.basename == "log":
content.remove(rec=1, ignore_errors=True)
else:
ensure_empty_dir(venv.path)
def getvenv(self, name):
if name in self.existing_venvs:
return self.existing_venvs[name]
env_config = self.config.envconfigs.get(name, None)
if env_config is None:
reporter.error("unknown environment {!r}".format(name))
raise LookupError(name)
elif env_config.envdir == self.config.toxinidir:
reporter.error("venv {!r} in {} would delete project".format(name, env_config.envdir))
raise tox.exception.ConfigError("envdir must not equal toxinidir")
env_log = self.resultlog.get_envlog(name)
venv = VirtualEnv(envconfig=env_config, popen=self.popen, env_log=env_log)
self.existing_venvs[name] = venv
return venv
# provide quick enough feedback to the user
# when printing a dot per test
buf.flush()
last_time = time.time()
elif process.poll() is not None:
if process.stdout is not None:
process.stdout.close()
break
else:
time.sleep(0.1)
# the seek updates internal read buffers
input_file_handler.seek(0, 1)
input_file_handler.close()
out, _ = process.communicate() # wait to finish
except KeyboardInterrupt as exception:
reporter.error("got KeyboardInterrupt signal")
main_thread = is_main_thread()
while True:
try:
if main_thread:
# spin up a new thread to disable further interrupt on main thread
stopper = Thread(target=self.handle_interrupt, args=(process,))
stopper.start()
stopper.join()
else:
self.handle_interrupt(process)
except KeyboardInterrupt:
continue
break
raise exception
return out
def acquire_package(config, session):
"""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