def get_local_package(config): path = config.option.installpkg if not path: path = config.sdistsrc py_path = py.path.local(resolve_package(path)) info("using package {!r}, skipping 'sdist' activity ".format(str(py_path))) return py_path
def get_latest_version_of_package(package_spec): if not os.path.isabs(str(package_spec)): return package_spec p = py.path.local(package_spec) 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]
def get_package(session): """"Perform the package operation""" config = session.config if config.skipsdist: info("skipping sdist step") return None lock_file = session.config.toxworkdir.join("{}.lock".format(session.config.isolated_build_env)) with hold_lock(lock_file, verbosity0): package = acquire_package(config, session) session_package = create_session_view(package, config.temp_dir) return session_package, package
def get_package(session: session.Session, venv: VirtualEnv) -> Tuple[py.path.local, py.path.local]: config = session.config if config.skipsdist: reporter.info("skipping sdist step") return None lock_file = session.config.toxworkdir.join("{}.lock".format( session.config.isolated_build_env)) with hold_lock(lock_file, reporter.verbosity0): package = acquire_package(config, venv) session_package = create_session_view(package, config.temp_dir) return session_package, package
def locate_via_py(*parts): ver = "-{}".format(".".join(parts)) py_exe = distutils.spawn.find_executable("py") if py_exe: cmd = py_exe, ver, VERSION_QUERY_SCRIPT proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True ) out, err = proc.communicate() if not proc.returncode: try: result = json.loads(out) except ValueError as exception: failure = exception else: return result["executable"] else: failure = "exit code {}".format(proc.returncode) reporter.info("{!r} cmd {!r} out {!r} err {!r} ".format(failure, cmd, out, err))
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
def subcommand_test(self): if self.config.skipsdist: reporter.info("skipping sdist step") else: for venv in self.venv_dict.values(): if not venv.envconfig.skip_install: venv.package = self.hook.tox_package(session=self, venv=venv) if not venv.package: return 2 venv.envconfig.setenv[str("TOX_PACKAGE")] = str(venv.package) if self.config.option.sdistonly: return within_parallel = PARALLEL_ENV_VAR_KEY_PRIVATE in os.environ try: if not within_parallel and self.config.option.parallel != PARALLEL_OFF: run_parallel(self.config, self.venv_dict) else: run_sequential(self.config, self.venv_dict) finally: retcode = self._summary() return retcode
def build_image(venv, context, action): create_docker_file(context, venv) # host -> Linux access local pip generator = CLIENT.api.build(path=str(context), rm=True, network_mode="host") image_id = None while True: output = None try: output = next(generator) message = "" for fragment in output.decode().split("\r\n"): if fragment: msg = json.loads(fragment) if "stream" in msg: msg = msg["stream"] match = re.search( r"(^Successfully built |sha256:)([0-9a-f]+)$", msg) if match: image_id = match.group(2) else: msg = fragment message += msg message = "".join(message).strip("\n") reporter.verbosity1(message) except StopIteration: reporter.info("Docker image build complete.") break except ValueError: # pragma: no cover reporter.error( "Error parsing output from docker image build: {}".format( output)) # pragma: no cover if image_id is None: raise InvocationError("docker image build failed") # pragma: no cover _BUILT_IMAGES.add(image_id) return image_id
def ensure_empty_dir(path): if path.check(): reporter.info(" removing {}".format(path)) shutil.rmtree(str(path), ignore_errors=True) path.ensure(dir=1)