Esempio n. 1
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        groups: list[str] = list(options.groups)
        if options.pyproject:
            options.hashes = False
        groups = translate_groups(
            project,
            options.default,
            options.dev,
            options.groups or (),
        )
        requirements: dict[str, Requirement] = {}
        packages: Iterable[Requirement] | Iterable[Candidate]
        for group in groups:
            requirements.update(project.get_dependencies(group))
        if options.pyproject:
            packages = requirements.values()
        else:
            project.core.ui.echo(
                "The exported requirements file is no longer cross-platform. "
                "Using it on other platforms may cause unexpected result.",
                fg="yellow",
                err=True,
            )
            candidates = resolve_candidates_from_lockfile(
                project, requirements.values()
            )
            packages = candidates.values()

        content = FORMATS[options.format].export(
            project, packages, options
        )  # type: ignore
        if options.output:
            Path(options.output).write_text(content)
        else:
            project.core.ui.echo(content)
Esempio n. 2
0
def test_resolve_candidates_to_install(project):
    project.lockfile = {
        "package": [
            {
                "name": "pytest",
                "version": "4.6.0",
                "summary": "pytest module",
                "dependencies":
                ["py>=3.0", "configparser; sys_platform=='win32'"],
            },
            {
                "name": "configparser",
                "version": "1.2.0",
                "summary": "configparser module",
                "dependencies": ["backports"],
            },
            {
                "name": "py",
                "version": "3.6.0",
                "summary": "py module",
            },
            {
                "name": "backports",
                "version": "2.2.0",
                "summary": "backports module",
            },
        ]
    }
    project.environment.marker_environment["sys_platform"] = "linux"
    reqs = [parse_requirement("pytest")]
    result = resolve_candidates_from_lockfile(project, reqs)
    assert result["pytest"].version == "4.6.0"
    assert result["py"].version == "3.6.0"
    assert "configparser" not in result
    assert "backports" not in result

    project.environment.marker_environment["sys_platform"] = "win32"
    result = resolve_candidates_from_lockfile(project, reqs)
    assert result["pytest"].version == "4.6.0"
    assert result["py"].version == "3.6.0"
    assert result["configparser"].version == "1.2.0"
    assert result["backports"].version == "2.2.0"