예제 #1
0
def test_parse_multi_reqs() -> None:
    toml_str = """[tool.poetry]
    name = "poetry_tinker"
    version = "0.1.0"
    description = ""
    authors = ["Liam Wilson <*****@*****.**>"]

    [tool.poetry.dependencies]
    python = "^3.8"
    junk = {url = "https://github.com/myrepo/junk.whl", extras = ["security"]}
    poetry = {git = "https://github.com/python-poetry/poetry.git", tag = "v1.1.1"}
    requests = {extras = ["security","random"], version = "^2.25.1", python = ">2.7"}
    foo = [{version = ">=1.9", python = "^2.7"},{version = "^2.0", python = "3.4 || 3.5"}]

    [tool.poetry.dependencies.black]
    version = "19.10b0"
    python = "3.6"
    markers = "platform_python_implementation == 'CPython'"

    [tool.poetry.group.mygroup.dependencies]
    myrequirement = "1.2.3"

    [tool.poetry.group.mygroup2.dependencies]
    myrequirement2 = "1.2.3"

    [tool.poetry.dev-dependencies]
    isort = ">=5.5.1,<5.6"

    [build-system]
    requires = ["poetry-core>=1.0.0"]
    build-backend = "poetry.core.masonry.api"
    """
    pyproject_toml = create_pyproject_toml(toml_contents=toml_str)
    retval = parse_pyproject_toml(pyproject_toml)
    actual_reqs = {
        PipRequirement.parse(
            "junk[security]@ https://github.com/myrepo/junk.whl"),
        PipRequirement.parse("myrequirement==1.2.3"),
        PipRequirement.parse("myrequirement2==1.2.3"),
        PipRequirement.parse(
            "poetry@ git+https://github.com/python-poetry/[email protected]"),
        PipRequirement.parse(
            'requests[security, random]<3.0.0,>=2.25.1; python_version > "2.7"'
        ),
        PipRequirement.parse(
            'foo>=1.9; python_version >= "2.7" and python_version < "3.0"'),
        PipRequirement.parse(
            'foo<3.0.0,>=2.0; python_version == "3.4" or python_version == "3.5"'
        ),
        PipRequirement.parse(
            "black==19.10b0; "
            'platform_python_implementation == "CPython" and python_version == "3.6"'
        ),
        PipRequirement.parse("isort<5.6,>=5.5.1"),
    }
    assert retval == actual_reqs
예제 #2
0
    def __call__(
        self,
        *,
        source: str = "pyproject.toml",
        module_mapping: Mapping[str, Iterable[str]] | None = None,
        type_stubs_module_mapping: Mapping[str, Iterable[str]] | None = None,
        overrides: OVERRIDES_TYPE = None,
    ) -> None:
        """
        :param module_mapping: a mapping of requirement names to a list of the modules they provide.
            For example, `{"ansicolors": ["colors"]}`. Any unspecified requirements will use the
            requirement name as the default module, e.g. "Django" will default to
            `modules=["django"]`.
        """
        req_file_tgt = self._parse_context.create_object(
            TargetGeneratorSourcesHelperTarget.alias,
            name=source.replace(os.path.sep, "_"),
            sources=[source],
        )
        requirements_dep = f":{req_file_tgt.name}"

        normalized_module_mapping = normalize_module_mapping(module_mapping)
        normalized_type_stubs_module_mapping = normalize_module_mapping(
            type_stubs_module_mapping)

        dependencies_overrides = flatten_overrides_to_dependency_field(
            overrides,
            macro_name="python_requirements",
            build_file_dir=self._parse_context.rel_path)

        requirements = parse_pyproject_toml(
            PyProjectToml.deprecated_macro_create(self._parse_context, source))
        for parsed_req in requirements:
            normalized_proj_name = canonicalize_project_name(
                parsed_req.project_name)
            self._parse_context.create_object(
                "python_requirement",
                name=parsed_req.project_name,
                requirements=[parsed_req],
                modules=normalized_module_mapping.get(normalized_proj_name),
                type_stub_modules=normalized_type_stubs_module_mapping.get(
                    normalized_proj_name),
                dependencies=[
                    requirements_dep,
                    *dependencies_overrides.get(normalized_proj_name, []),
                ],
            )
예제 #3
0
def test_extended_form() -> None:
    toml_black_str = """
    [tool.poetry.dependencies]
    [tool.poetry.dependencies.black]
    version = "19.10b0"
    python = "3.6"
    markers = "platform_python_implementation == 'CPython'"
    [tool.poetry.dev-dependencies]
    """
    pyproject_toml_black = create_pyproject_toml(toml_contents=toml_black_str)
    retval = parse_pyproject_toml(pyproject_toml_black)
    actual_req = {
        Requirement.parse(
            "black==19.10b0; "
            'platform_python_implementation == "CPython" and python_version == "3.6"'
        )
    }
    assert retval == actual_req
예제 #4
0
 def validate_poetry_requirements(contents: bytes) -> None:
     p = PyProjectToml(PurePath(), PurePath(), contents.decode())
     parse_pyproject_toml(p)