def effective_package(self, template): """ :param str template: Template describing how to name delivered files, example: {meta}/{name}-{version} """ folder = os.path.join(self.dist_folder, template.format(name=self.package_spec.dashed, version=self.desired.version)) clean_folder(folder) python = system.target_python(package_spec=self.package_spec) if not python.has_builtin_venv or self.relocatable: venv = "virtualenv==16.7.7" else: venv = "venv" vrun(self.package_spec, venv, folder) bin_folder = os.path.join(folder, "bin") pip = os.path.join(bin_folder, "pip") spec = self.source_folder if self.source_folder else "%s==%s" % (self.package_spec.dashed, self.desired.version) runez.run(pip, "install", "-i", system.SETTINGS.index, "-f", self.build_folder, spec) if self.relocatable: python = system.target_python(package_spec=self.package_spec).executable vrun(self.package_spec, "virtualenv", "--relocatable", "--python=%s" % python, folder) runez.run(os.path.join(bin_folder, "python"), "-mcompileall") self.packaged.append(folder) self.executables = [os.path.join(bin_folder, name) for name in self.entry_points]
def effective_package(self, template): """ :param str template: Template describing how to name delivered files, example: {meta}/{name}-{version} """ folder = os.path.join( self.dist_folder, template.format(name=self.name, version=self.version)) runez.delete(folder, logger=None) runez.ensure_folder(folder, folder=True, logger=None) vrun(self.name, "virtualenv", folder) bin_folder = os.path.join(folder, "bin") pip = os.path.join(bin_folder, "pip") spec = self.source_folder if self.source_folder else "%s==%s" % ( self.name, self.version) runez.run(pip, "install", "-i", system.SETTINGS.index, "-f", self.build_folder, spec) if self.relocatable: python = system.target_python(package_name=self.name).executable vrun(self.name, "virtualenv", "--relocatable", "--python=%s" % python, folder) self.packaged.append(folder) self.executables = [ os.path.join(bin_folder, name) for name in self.entry_points ]
def pex_build(self, name, destination): """ Run pex build :param str name: Name of entry point :param str destination: Path to file where to produce pex :return str: None if successful, error message otherwise """ runez.ensure_folder(self.build_folder, folder=True) runez.delete(destination) args = ["--cache-dir", self.build_folder, "--repo", self.build_folder] args.extend([ "-c%s" % name, "-o%s" % destination, "%s==%s" % (self.name, self.version) ]) python = system.target_python(package_name=self.name) shebang = python.shebang( universal=system.is_universal(self.build_folder)) if shebang: args.append("--python-shebang") args.append(shebang) vrun(self.name, self.specced_command(), *args, path_env=C_COMPILATION_HELP)
def _update_dynamic_fields(self): """Update dynamically determined fields""" self.delivery = DELIVERERS.resolved_name(self._package_spec, default=self._base and self._base.delivery) self.packager = PACKAGERS.resolved_name(self._package_spec, default=self._base and self._base.packager) # Record which python was used, as specified self.python = system.target_python(package_spec=self._package_spec).text self.pickley = runez.get_version(pickley) self.timestamp = int(time.time())
def vrun(package_name, command, *args, **kwargs): """ Run command + args from an on-the-fly create virtualenv, for associated pypi 'package_name'. This allows us to run commands like 'pex ...' with pex installed when/if needed :param str package_name: Associated pypi package the run is for :param str command: Command to run (pip, pex, etc...) :param args: Command line args :param kwargs: Optional named args to pass-through to runez.run_program() """ python = system.target_python(package_name=package_name) folder = system.SETTINGS.meta.full_path(".%s" % python.short_name) with SoftLock(folder, timeout=system.SETTINGS.install_timeout, invalid=system.SETTINGS.install_timeout, keep=10) as lock: shared = SharedVenv(lock, python) return shared._run_from_venv(command, *args, **kwargs)
def settings(diagnostics): """ Show settings """ if diagnostics: prefix = getattr(sys, "prefix", None) base_prefix = getattr(sys, "base_prefix", None) print("python : %s" % short(system.target_python(desired=system.INVOKER, fatal=None), meta=False)) print("sys.executable : %s" % short(sys.executable, meta=False)) print("sys.prefix : %s" % short(prefix, meta=False)) if base_prefix: print("sys.base_prefix: %s" % short(base_prefix, meta=False)) if not system.SETTINGS.meta.path.startswith( system.PICKLEY_PROGRAM_PATH): print("pickley : %s" % short(system.PICKLEY_PROGRAM_PATH, meta=False)) print("") print(system.SETTINGS.represented())
def test_python_installation(_, __, ___, ____, temp_base): system.DESIRED_PYTHON = "/dev/null/foo" p = system.target_python(fatal=False) assert not p.is_valid assert p.shebang() == "/dev/null/foo" system.DESIRED_PYTHON = None assert system.target_python(fatal=False).is_valid assert not system.PythonInstallation("").is_valid p = system.PythonInstallation("foo") assert str(p) == "python 'foo'" assert not p.is_valid assert p.problem == "No python installation 'foo' found" assert p.program_name == "python 'foo'" p = system.PythonInstallation("pythonx") assert not p.is_valid # assert p.problem == "pythonx is not installed" assert p.program_name == "pythonx" p = system.PythonInstallation("/usr/bin/python") assert str(p) == "/usr/bin/python [2.7]" assert p.is_valid assert p.problem is None assert p.program_name == "python2.7" assert p.short_name == "py27" assert p.executable == "/usr/bin/python" assert p.shebang(universal=True) == "/usr/bin/env python" assert p.shebang() == "/usr/bin/python" p = system.PythonInstallation("3.6") assert str(p) == "/test/python3.6/bin/python [3.6]" assert p.is_valid assert p.problem is None assert p.program_name == "python3.6" assert p.short_name == "py36" assert p.executable == "/test/python3.6/bin/python" assert p.shebang() == "/usr/bin/env python3.6" system.SETTINGS.cli.contents["python_installs"] = temp_base runez.touch("foo") runez.touch("python3.5") runez.touch("python3.7") p = system.PythonInstallation("python3") assert not p.is_valid assert p.problem == "'/test/python3' is not a valid python installation" assert p.program_name == "python3" p = system.PythonInstallation("py3.7") assert not p.is_valid assert p.problem == "python3.7 is not installed" runez.delete("python3.7") runez.touch("3.7.0/bin/python") runez.make_executable("3.7.0/bin/python") p = system.PythonInstallation("3.7") assert p.is_valid assert p.short_name == "py37" assert p.executable == os.path.join(temp_base, "3.7.0/bin/python")