Ejemplo n.º 1
0
 def install_editable(self, ireq: shims.InstallRequirement) -> None:
     setup_path = ireq.setup_py_path
     paths = self.environment.get_paths()
     install_script = importlib.import_module(
         "pdm._editable_install").__file__.rstrip("co")
     install_args = [
         self.environment.python_executable,
         "-u",
         install_script,
         setup_path,
         paths["prefix"],
     ]
     with self.environment.activate(), cd(ireq.unpacked_source_directory):
         try:
             result = subprocess.run(install_args,
                                     capture_output=True,
                                     check=True)
         except subprocess.CalledProcessError as ex:
             result = ex
     context.io.echo(result.stdout, verbosity=context.io.DETAIL)
     if result.stderr:
         context.io.echo(result.stderr,
                         err=True,
                         verbosity=context.io.DETAIL)
     if result.returncode:
         raise result from None
Ejemplo n.º 2
0
 def install(self):
     with vistir.cd(self.working_directory), _suppress_distutils_logs():
         # Access from Setuptools to ensure things are patched correctly.
         setuptools.dist.distutils.core.run_setup(
             self.setup_py,
             ["develop", "--no-deps"],
         )
Ejemplo n.º 3
0
    def convert_package_paths(self) -> Dict[str, Union[List, Dict]]:
        """Return a {package_dir, packages, package_data, exclude_package_data} dict.
        """
        package_dir = {}
        packages = []
        py_modules = []
        package_data = {"": ["*"]}
        exclude_package_data = {}

        with vistir.cd(self.project.root.as_posix()):
            if not self.includes:
                if os.path.isdir("src"):
                    package_dir[""] = "src"
                    packages = setuptools.find_packages("src")
                else:
                    packages = setuptools.find_packages(exclude=["tests", "tests.*"])
                if not packages:
                    py_modules = [path[:-3] for path in glob.glob("*.py")]
            else:
                packages_set = set()
                includes = self.includes
                for include in includes[:]:
                    if include.replace("\\", "/").endswith("/*"):
                        include = include[:-2]
                    if "*" not in include and os.path.isdir(include):
                        temp = setuptools.find_packages(include)
                        if os.path.exists(include + "/__init__.py"):
                            temp.append(include)
                        elif temp:
                            package_dir[""] = include
                        packages_set.update(temp)
                        includes.remove(include)
                packages[:] = list(packages_set)
                for include in includes:
                    for path in glob.glob(include):
                        if "/" not in path.lstrip("./") and path.endswith(".py"):
                            # Only include top level py modules
                            py_modules.append(path.lstrip("./")[:-3])
                    if include.endswith(".py"):
                        continue
                    for package in packages:
                        relpath = os.path.relpath(include, package)
                        if not relpath.startswith(".."):
                            package_data.setdefault(package, []).append(relpath)
                for exclude in self.excludes or []:
                    for package in packages:
                        relpath = os.path.relpath(exclude, package)
                        if not relpath.startswith(".."):
                            exclude_package_data.setdefault(package, []).append(relpath)
            if packages and py_modules:
                raise ProjectError(
                    "Can't specify packages and py_modules at the same time."
                )
        return {
            "package_dir": package_dir,
            "packages": packages,
            "py_modules": py_modules,
            "package_data": package_data,
            "exclude_package_data": exclude_package_data,
        }
Ejemplo n.º 4
0
 def install_editable(self, ireq: shims.InstallRequirement) -> None:
     setup_path = ireq.setup_py_path
     paths = self.environment.get_paths()
     install_script = importlib.import_module(
         "pdm._editable_install").__file__.rstrip("co")
     install_args = [
         self.environment.python_executable,
         "-u",
         install_script,
         setup_path,
         paths["prefix"],
     ]
     with self.environment.activate(), cd(ireq.unpacked_source_directory):
         capture_output = context.io.verbosity < context.io.DETAIL
         subprocess.run(install_args,
                        capture_output=capture_output,
                        check=True)
Ejemplo n.º 5
0
    def lock(self):
        """Lock specified (abstract) requirements into (concrete) candidates.

        The locking procedure consists of four stages:

        * Resolve versions and dependency graph (powered by ResolveLib).
        * Walk the graph to determine "why" each candidate came to be, i.e.
          what top-level requirements result in a given candidate.
        * Populate hashes for resolved candidates.
        * Populate markers based on dependency specifications of each
          candidate, and the dependency graph.
        """
        provider = self.get_provider()
        reporter = self.get_reporter()
        resolver = resolvelib.Resolver(provider, reporter)

        with vistir.cd(self.project.root):
            state = resolver.resolve(self.requirements)

        traces = trace_graph(state.graph)

        hash_cache = HashCache()
        for r in state.mapping.values():
            if not r.hashes:
                r.hashes = get_hashes(hash_cache, r)

        set_metadata(
            state.mapping, traces,
            provider.fetched_dependencies,
            provider.collected_requires_pythons,
        )

        lockfile = plette.Lockfile.with_meta_from(self.project.pipfile)
        lockfile["default"] = _collect_derived_entries(
            state, traces, self.default_requirements,
        )
        lockfile["develop"] = _collect_derived_entries(
            state, traces, self.develop_requirements,
        )
        self.project.lockfile = lockfile
Ejemplo n.º 6
0

# This hackery is needed because some files may have 0600 permissions or
# whatever and tarfile will break in this case
def extract_tar(path):
    tar = tarfile.open(path, 'r:gz', errorlevel=1)
    for file_ in tar:
        try:
            tar.extract(file_)
        except IOError as e:
            os.remove(file_.name)
            tar.extract(file_)
        finally:
            os.chmod(file_.name, file_.mode)
    tar.close()


with cd(temp_dir):
    urllib.request.urlretrieve(TIMBUCTOO_GUI_URL, basename)
    extract_tar(basename)

    with cd(EXPECTED_FILE_NAME):
        subprocess.check_call(["npm", "install"], stdout=subprocess.DEVNULL)
        subprocess.check_call(["npm", "run", "build"],
                              stdout=subprocess.DEVNULL)

        with cd("build"):
            with tarfile.open(fileobj=sys.stdout.buffer, mode='w|') as tar:
                for path in os.listdir():
                    tar.add(path, recursive=True)