Ejemplo n.º 1
0
    def _pep517_metadata(cls, path):  # type (Path) -> PackageInfo
        """
        Helper method to use PEP-517 library to build and read package metadata.

        :param path: Path to package source to build and read metadata for.
        """
        info = None
        try:
            info = cls.from_setup_files(path)
            if info.requires_dist is not None:
                return info
        except PackageInfoError:
            pass

        with temporary_directory() as tmp_dir:
            # TODO: cache PEP 517 build environment corresponding to each project venv
            venv_dir = Path(tmp_dir) / ".venv"
            EnvManager.build_venv(venv_dir.as_posix())
            venv = VirtualEnv(venv_dir, venv_dir)

            dest_dir = Path(tmp_dir) / "dist"
            dest_dir.mkdir()

            try:
                venv.run("python", "-m", "pip", "install",
                         "--disable-pip-version-check", "--ignore-installed",
                         *PEP517_META_BUILD_DEPS)
                venv.run(
                    "python",
                    "-",
                    input_=PEP517_META_BUILD.format(source=path.as_posix(),
                                                    dest=dest_dir.as_posix()),
                )
                return cls.from_metadata(dest_dir)
            except EnvCommandError as e:
                # something went wrong while attempting pep517 metadata build
                # fallback to egg_info if setup.py available
                cls._log("PEP517 build failed: {}".format(e), level="debug")
                setup_py = path / "setup.py"
                if not setup_py.exists():
                    raise PackageInfoError(path)

                cwd = Path.cwd()
                os.chdir(path.as_posix())
                try:
                    venv.run("python", "setup.py", "egg_info")
                    return cls.from_metadata(path)
                except EnvCommandError:
                    raise PackageInfoError(path)
                finally:
                    os.chdir(cwd.as_posix())

        if info:
            cls._log(
                "Falling back to parsed setup.py file for {}".format(path),
                "debug")
            return info

        # if we reach here, everything has failed and all hope is lost
        raise PackageInfoError(path)
Ejemplo n.º 2
0
    def __init__(
        self,
        name,  # type: str
        path,  # type: Path
        category="main",  # type: str
        optional=False,  # type: bool
        base=None,  # type: Path
        extras=None,  # type: Union[List[str], FrozenSet[str]]
    ):
        self._path = path
        self._base = base or Path.cwd()
        self._full_path = path

        if not self._path.is_absolute():
            try:
                self._full_path = self._base.joinpath(self._path).resolve()
            except FileNotFoundError:
                raise ValueError("Directory {} does not exist".format(self._path))

        if not self._full_path.exists():
            raise ValueError("File {} does not exist".format(self._path))

        if self._full_path.is_dir():
            raise ValueError("{} is a directory, expected a file".format(self._path))

        super(FileDependency, self).__init__(
            name,
            "*",
            category=category,
            optional=optional,
            allows_prereleases=True,
            source_type="file",
            source_url=self._full_path.as_posix(),
            extras=extras,
        )
Ejemplo n.º 3
0
def executable():
    global _executable

    if _executable is not None:
        return _executable

    if WINDOWS and PY36:
        # Finding git via where.exe
        where = "%WINDIR%\\System32\\where.exe"
        paths = decode(
            subprocess.check_output([where, "git"], shell=True,
                                    encoding="oem")).split("\n")
        for path in paths:
            if not path:
                continue

            path = Path(path.strip())
            try:
                path.relative_to(Path.cwd())
            except ValueError:
                _executable = str(path)

                break
    else:
        _executable = "git"

    if _executable is None:
        raise RuntimeError("Unable to find a valid git executable")

    return _executable
Ejemplo n.º 4
0
    def __init__(
        self,
        name,  # type: str
        path,  # type: Path
        category="main",  # type: str
        optional=False,  # type: bool
        base=None,  # type: Path
        develop=False,  # type: bool
        extras=None,  # type: Union[List[str], FrozenSet[str]]
    ):
        self._path = path
        self._base = base or Path.cwd()
        self._full_path = path

        if not self._path.is_absolute():
            try:
                self._full_path = self._base.joinpath(self._path).resolve()
            except FileNotFoundError:
                raise ValueError("Directory {} does not exist".format(self._path))

        self._develop = develop
        self._supports_poetry = False

        if not self._full_path.exists():
            raise ValueError("Directory {} does not exist".format(self._path))

        if self._full_path.is_file():
            raise ValueError("{} is a file, expected a directory".format(self._path))

        # Checking content to determine actions
        setup = self._full_path / "setup.py"
        self._supports_poetry = PyProjectTOML(
            self._full_path / "pyproject.toml"
        ).is_poetry_project()

        if not setup.exists() and not self._supports_poetry:
            raise ValueError(
                "Directory {} does not seem to be a Python package".format(
                    self._full_path
                )
            )

        super(DirectoryDependency, self).__init__(
            name,
            "*",
            category=category,
            optional=optional,
            allows_prereleases=True,
            source_type="directory",
            source_url=self._full_path.as_posix(),
            extras=extras,
        )
Ejemplo n.º 5
0
def get_vcs(directory):  # type: (Path) -> Git
    working_dir = Path.cwd()
    os.chdir(str(directory.resolve()))

    try:
        git_dir = decode(
            subprocess.check_output(["git", "rev-parse", "--show-toplevel"],
                                    stderr=subprocess.STDOUT)).strip()

        vcs = Git(Path(git_dir))

    except (subprocess.CalledProcessError, OSError):
        vcs = None
    finally:
        os.chdir(str(working_dir))

    return vcs
Ejemplo n.º 6
0
    def checkout_output(cmd, *args, **kwargs):
        if Path(cmd[0]).name == "where.exe":
            return "\n".join(
                [str(Path.cwd().joinpath("git.exe")), "C:\\Git\\cmd\\git.exe"])

        return b""