def test_to_pep_508_in_extras() -> None:
    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git")
    dependency.in_extras.append("foo")

    expected = (
        'poetry @ git+https://github.com/python-poetry/poetry.git ; extra == "foo"'
    )
    assert dependency.to_pep_508() == expected

    dependency = VCSDependency("poetry",
                               "git",
                               "https://github.com/python-poetry/poetry.git",
                               extras=["bar"])
    dependency.in_extras.append("foo")

    expected = (
        'poetry[bar] @ git+https://github.com/python-poetry/poetry.git ; extra == "foo"'
    )

    assert dependency.to_pep_508() == expected

    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git",
                               "b;ar;")
    dependency.in_extras.append("foo;")

    expected = (
        "poetry @ git+https://github.com/python-poetry/poetry.git@b;ar; ; extra =="
        ' "foo;"')

    assert dependency.to_pep_508() == expected
Esempio n. 2
0
def test_to_pep_508_in_extras():
    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git")
    dependency.in_extras.append("foo")

    expected = 'poetry @ git+https://github.com/python-poetry/poetry.git@master ; extra == "foo"'
    assert expected == dependency.to_pep_508()

    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git")
    dependency.in_extras.append("foo")
    dependency.extras.append("bar")

    expected = 'poetry[bar] @ git+https://github.com/python-poetry/poetry.git@master ; extra == "foo"'

    assert expected == dependency.to_pep_508()

    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git",
                               "b;ar;")
    dependency.in_extras.append("foo;")

    expected = 'poetry @ git+https://github.com/python-poetry/poetry.git@b;ar; ; extra == "foo;"'

    assert expected == dependency.to_pep_508()
Esempio n. 3
0
def test_to_pep_508():
    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git")

    expected = "poetry @ git+https://github.com/python-poetry/poetry.git@master"

    assert expected == dependency.to_pep_508()
Esempio n. 4
0
def test_to_pep_508_ssh():
    dependency = VCSDependency("poetry", "git",
                               "[email protected]:sdispater/poetry.git")

    expected = "poetry @ git+ssh://[email protected]/sdispater/poetry.git@master"

    assert expected == dependency.to_pep_508()
def test_to_pep_508() -> None:
    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git")

    expected = "poetry @ git+https://github.com/python-poetry/poetry.git"

    assert dependency.to_pep_508() == expected
def test_to_pep_508_ssh() -> None:
    dependency = VCSDependency("poetry", "git",
                               "[email protected]:sdispater/poetry.git")

    expected = "poetry @ git+ssh://[email protected]/sdispater/poetry.git"

    assert dependency.to_pep_508() == expected
Esempio n. 7
0
def test_to_pep_508_with_extras():
    dependency = VCSDependency("poetry", "git",
                               "https://github.com/python-poetry/poetry.git")
    dependency.extras.append("foo")

    expected = "poetry[foo] @ git+https://github.com/python-poetry/poetry.git@master"

    assert expected == dependency.to_pep_508()
def test_to_pep_508_with_extras() -> None:
    dependency = VCSDependency(
        "poetry",
        "git",
        "https://github.com/python-poetry/poetry.git",
        extras=["foo", "bar"],
    )

    expected = "poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git"

    assert dependency.to_pep_508() == expected
Esempio n. 9
0
    def _export_requirements_txt(
        self,
        cwd,
        output,
        with_hashes=True,
        dev=False,
        extras=None,
        with_credentials=False,
    ):  # type: (Path, Union[IO, str], bool, bool, bool) -> None
        indexes = set()
        content = ""
        packages = self._poetry.locker.locked_repository(dev).packages

        # Build a set of all packages required by our selected extras
        extra_package_names = set(
            get_extra_package_names(
                packages, self._poetry.locker.lock_data.get("extras", {}),
                extras or ()))

        for package in sorted(packages, key=lambda p: p.name):
            # If a package is optional and we haven't opted in to it, continue
            if package.optional and package.name not in extra_package_names:
                continue

            if package.source_type == "git":
                dependency = VCSDependency(
                    package.name,
                    package.source_type,
                    package.source_url,
                    package.source_reference,
                )
                dependency.marker = package.marker
                line = "-e git+{}@{}#egg={}".format(package.source_url,
                                                    package.source_reference,
                                                    package.name)
            elif package.source_type in ["directory", "file", "url"]:
                url = package.source_url
                if package.source_type == "file":
                    dependency = FileDependency(
                        package.name,
                        Path(package.source_url),
                        base=self._poetry.locker.lock.path.parent,
                    )
                    url = Path(
                        os.path.relpath(
                            url, self._poetry.locker.lock.path.parent.as_posix(
                            ))).as_posix()
                elif package.source_type == "directory":
                    dependency = DirectoryDependency(
                        package.name,
                        Path(package.source_url),
                        base=self._poetry.locker.lock.path.parent,
                    )
                    url = Path(
                        os.path.relpath(
                            url, self._poetry.locker.lock.path.parent.as_posix(
                            ))).as_posix()
                else:
                    dependency = URLDependency(package.name,
                                               package.source_url)

                dependency.marker = package.marker

                line = "{}".format(url)
                if package.develop and package.source_type == "directory":
                    line = "-e " + line
            else:
                dependency = package.to_dependency()
                line = "{}=={}".format(package.name, package.version)

            requirement = dependency.to_pep_508()
            if ";" in requirement:
                line += "; {}".format(requirement.split(";")[1].strip())

            if (package.source_type not in {"git", "directory", "file", "url"}
                    and package.source_url):
                indexes.add(package.source_url)

            if package.files and with_hashes:
                hashes = []
                for f in package.files:
                    h = f["hash"]
                    algorithm = "sha256"
                    if ":" in h:
                        algorithm, h = h.split(":")

                        if algorithm not in self.ALLOWED_HASH_ALGORITHMS:
                            continue

                    hashes.append("{}:{}".format(algorithm, h))

                if hashes:
                    line += " \\\n"
                    for i, h in enumerate(hashes):
                        line += "    --hash={}{}".format(
                            h, " \\\n" if i < len(hashes) - 1 else "")

            line += "\n"
            content += line

        if indexes:
            # If we have extra indexes, we add them to the beginning of the output
            indexes_header = ""
            for index in sorted(indexes):
                repository = [
                    r for r in self._poetry.pool.repositories
                    if r.url == index.rstrip("/")
                ][0]
                if (self._poetry.pool.has_default()
                        and repository is self._poetry.pool.repositories[0]):
                    url = (repository.authenticated_url
                           if with_credentials else repository.url)
                    indexes_header = "--index-url {}\n".format(url)
                    continue

                url = (repository.authenticated_url
                       if with_credentials else repository.url)
                indexes_header += "--extra-index-url {}\n".format(url)

            content = indexes_header + "\n" + content

        self._output(content, cwd, output)