def wheel_build_pep517(config, session, venv): pyproject = config.setupdir.join("pyproject.toml") if not pyproject.check(): reporter.error( "No pyproject.toml file found. The expected location is: {}". format(pyproject)) raise SystemExit(1) with session.newaction(venv.name, "packaging") as action: venv.update(action=action) ensure_empty_dir(config.distdir) venv.test( name="wheel-make", commands=[[ "pip", "wheel", config.setupdir, "--no-deps", "--use-pep517", "--wheel-dir", config.distdir ]], redirect=False, ignore_outcome=False, ignore_errors=False, display_hash_seed=False, ) try: dists = config.distdir.listdir() except py.error.ENOENT: reporter.error( "No dist directory found. Please check pyproject.toml, e.g with:\n" " pip wheel . --use-pep517") raise SystemExit(1) else: if not dists: reporter.error( "No distributions found in the dist directory found. Please check pyproject.toml, e.g with:\n" " pip wheel . --use-pep517") raise SystemExit(1) return dists[0]
def cleanup_for_venv(venv): within_parallel = PARALLEL_ENV_VAR_KEY in os.environ # if the directory exists and it doesn't look like a virtualenv, produce # an error if venv.path.exists(): dir_items = set(os.listdir(str(venv.path))) - {".lock", "log"} dir_items = {p for p in dir_items if not p.startswith(".tox-")} else: dir_items = set() if not ( # doesn't exist => OK not venv.path.exists() # does exist, but it's empty => OK or not 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"}): 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 tox_testenv_create(venv, action): config_interpreter = venv.getsupportedinterpreter() args = [sys.executable, "-m", "virtualenv"] if venv.envconfig.sitepackages: args.append("--system-site-packages") if venv.envconfig.alwayscopy: args.append("--always-copy") if NO_DOWNLOAD: args.append("--no-download") # add interpreter explicitly, to prevent using default (virtualenv.ini) args.extend(["--python", str(config_interpreter)]) within_parallel = PARALLEL_ENV_VAR_KEY in os.environ 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) basepath = venv.path.dirpath() basepath.ensure(dir=1) args.append(venv.path.basename) if not _SKIP_VENV_CREATION: venv._pcall( args, venv=False, action=action, cwd=basepath, redirect=reporter.verbosity() < reporter.Verbosity.DEBUG, ) return True # Return non-None to indicate plugin has completed
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", ) raise SystemExit(1) with session.newaction("GLOB", "packaging") as action: action.setactivity("sdist-make", setup) ensure_empty_dir(config.distdir) build_log = action.popen( [ sys.executable, setup, "sdist", "--formats=zip", "--dist-dir", config.distdir, ], cwd=config.setupdir, returnout=True, ) reporter.verbosity2(build_log) try: return config.distdir.listdir()[0] except py.error.ENOENT: # check if empty or comment only data = [] 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 sdist", ) raise SystemExit(1)
def cleanup_for_venv(venv): within_parallel = PARALLEL_ENV_VAR_KEY in os.environ 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 tox_runtest_pre(venv): venv.status = 0 ensure_empty_dir(venv.envconfig.envtmpdir) venv.envconfig.envtmpdir.ensure(dir=1) venv.test( name="run-test-pre", commands=venv.envconfig.commands_pre, redirect=False, ignore_outcome=False, ignore_errors=False, display_hash_seed=True, )
def wheel_build_legacy(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: with patch(venv, "is_allowed_external", partial(wheel_is_allowed_external, venv=venv)): 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 ]], redirect=False, ignore_outcome=False, ignore_errors=False, display_hash_seed=False, ) try: dists = config.distdir.listdir() except py.error.ENOENT: # check if empty or comment only data = [] 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 main(args): setup_reporter(args) try: config = load_config(args) config.logdir.ensure(dir=1) ensure_empty_dir(config.logdir) with set_os_env_var("TOX_WORK_DIR", config.toxworkdir): session = build_session(config) exit_code = session.runcommand() if exit_code is None: exit_code = 0 raise SystemExit(exit_code) except tox.exception.BadRequirement: raise SystemExit(1) except KeyboardInterrupt: raise SystemExit(2)
def tox_testenv_create(venv, action): config_interpreter = venv.getsupportedinterpreter() args = [sys.executable, "-m", "virtualenv"] if venv.envconfig.sitepackages: args.append("--system-site-packages") if venv.envconfig.alwayscopy: args.append("--always-copy") if NO_DOWNLOAD: args.append("--no-download") # add interpreter explicitly, to prevent using default (virtualenv.ini) args.extend(["--python", str(config_interpreter)]) ensure_empty_dir(venv.path) basepath = venv.path.dirpath() basepath.ensure(dir=1) args.append(venv.path.basename) venv._pcall(args, venv=False, action=action, cwd=basepath) return True # Return non-None to indicate plugin has completed
def acquire_package(config: config.Config, venv: VirtualEnv) -> py.path.local: target_dir: py.path.local = config.toxworkdir.join( config.isolated_build_env) ensure_empty_dir(target_dir) args = [ venv.envconfig.config.option.pdm, "build", "--no-wheel", "-d", target_dir, ] with venv.new_action("buildpkg") as action: venv._pcall(args, cwd=venv.envconfig.config.toxinidir, venv=False, action=action) path = next(target_dir.visit("*.tar.gz")) action.setactivity("buildpkg", path) return path
def main(args): setup_reporter(args) try: config = load_config(args) update_default_reporter(config.option.quiet_level, config.option.verbose_level) reporter.using("tox.ini: {}".format(config.toxinipath)) config.logdir.ensure(dir=1) ensure_empty_dir(config.logdir) with set_os_env_var("TOX_WORK_DIR", config.toxworkdir): retcode = build_session(config).runcommand() if retcode is None: retcode = 0 raise SystemExit(retcode) except KeyboardInterrupt: raise SystemExit(2) except (tox.exception.MinVersionError, tox.exception.MissingRequirement) as exception: reporter.error(str(exception)) raise SystemExit(1)
def make_sdist(config, session): setup = config.setupdir.join("setup.py") if not setup.check(): reporter.error( "No setup.py file found. The expected location is:\n" " {}\n" "You can\n" " 1. Create one:\n" " https://packaging.python.org/tutorials/distributing-packages/#setup-py\n" " 2. Configure tox to avoid running sdist:\n" " https://tox.readthedocs.io/en/latest/example/general.html" "#avoiding-expensive-sdist".format(setup) ) raise SystemExit(1) with session.newaction("GLOB", "packaging") as action: action.setactivity("sdist-make", setup) ensure_empty_dir(config.distdir) build_log = action.popen( [sys.executable, setup, "sdist", "--formats=zip", "--dist-dir", config.distdir], cwd=config.setupdir, returnout=True, ) reporter.verbosity2(build_log) try: return config.distdir.listdir()[0] except py.error.ENOENT: # check if empty or comment only data = [] 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 sdist" ) raise SystemExit(1)