Beispiel #1
0
def rules():
    return (
        *ancestor_files.rules(),
        *coverage_py.rules(),
        *dependency_inference_rules.rules(),
        *export.rules(),
        *ipython.rules(),
        *local_dists.rules(),
        *lockfile.rules(),
        *package_pex_binary.rules(),
        *pex.rules(),
        *pex_cli.rules(),
        *pex_environment.rules(),
        *pex_from_targets.rules(),
        *pytest.rules(),
        *pytest_runner.rules(),
        *python_native_code.rules(),
        *python_sources.rules(),
        *repl.rules(),
        *run_pex_binary.rules(),
        *setup_py.rules(),
        *setuptools.rules(),
        *tailor.rules(),
        *target_types_rules.rules(),
        # Macros.
        *deprecation_fixers.rules(),
        *pipenv_requirements.rules(),
        *poetry_requirements.rules(),
        *python_requirements.rules(),
    )
Beispiel #2
0
def rules():
    return (
        *coverage_py.rules(),
        *lockfile.rules(),
        *tailor.rules(),
        *ancestor_files.rules(),
        *local_dists.rules(),
        *python_sources.rules(),
        *dependency_inference_rules.rules(),
        *pex.rules(),
        *pex_cli.rules(),
        *pex_environment.rules(),
        *pex_from_targets.rules(),
        *pytest_runner.rules(),
        *package_pex_binary.rules(),
        *python_native_code.rules(),
        *repl.rules(),
        *run_pex_binary.rules(),
        *target_types_rules.rules(),
        *setup_py.rules(),
        *setuptools.rules(),
        *ipython.rules(),
        *pytest.rules(),
    )
Beispiel #3
0
def test_setup_lockfile_interpreter_constraints() -> None:
    rule_runner = RuleRunner(
        rules=[
            *setuptools.rules(),
            QueryRule(PythonLockfileRequest, [SetuptoolsLockfileSentinel]),
        ],
        target_types=[PythonLibrary, PythonDistribution],
        objects={"setup_py": PythonArtifact},
    )

    global_constraint = "==3.9.*"
    rule_runner.set_options(
        ["--setuptools-lockfile=lockfile.txt"],
        env={
            "PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS":
            f"['{global_constraint}']"
        },
    )

    def assert_ics(build_file: str, expected: list[str]) -> None:
        rule_runner.write_files({"project/BUILD": build_file})
        lockfile_request = rule_runner.request(PythonLockfileRequest,
                                               [SetuptoolsLockfileSentinel()])
        assert lockfile_request.interpreter_constraints == InterpreterConstraints(
            expected)

    # If no dependencies for python_distribution, fall back to global python-setup constraints.
    assert_ics("python_distribution(provides=setup_py(name='dist'))",
               [global_constraint])

    assert_ics(
        dedent("""\
            python_library(name="lib")
            python_distribution(
                name="dist",
                dependencies=[":lib"],
                provides=setup_py(name="dist"),
            )
            """),
        [global_constraint],
    )
    assert_ics(
        dedent("""\
            python_library(name="lib", interpreter_constraints=["==2.7.*"])
            python_distribution(
                name="dist",
                dependencies=[":lib"],
                provides=setup_py(name="dist"),
            )
            """),
        ["==2.7.*"],
    )
    assert_ics(
        dedent("""\
            python_library(name="lib", interpreter_constraints=["==2.7.*", "==3.5.*"])
            python_distribution(
                name="dist",
                dependencies=[":lib"],
                provides=setup_py(name="dist"),
            )
            """),
        ["==2.7.*", "==3.5.*"],
    )

    # If no python_distribution targets in repo, fall back to global python-setup constraints.
    assert_ics("python_library()", [global_constraint])

    # If there are multiple distinct ICs in the repo, we OR them. This is because setup_py.py will
    # build each Python distribution independently.
    assert_ics(
        dedent("""\
            python_library(name="lib1", interpreter_constraints=["==2.7.*"])
            python_distribution(
                name="dist1",
                dependencies=[":lib1"],
                provides=setup_py(name="dist"),
            )

            python_library(name="lib2", interpreter_constraints=["==3.5.*"])
            python_distribution(
                name="dist2",
                dependencies=[":lib2"],
                provides=setup_py(name="dist"),
            )
            """),
        ["==2.7.*", "==3.5.*"],
    )
    assert_ics(
        dedent("""\
            python_library(name="lib1", interpreter_constraints=["==2.7.*", "==3.5.*"])
            python_distribution(
                name="dist1",
                dependencies=[":lib1"],
                provides=setup_py(name="dist"),
            )

            python_library(name="lib2", interpreter_constraints=[">=3.5"])
            python_distribution(
                name="dist2",
                dependencies=[":lib2"],
                provides=setup_py(name="dist"),
            )
            """),
        ["==2.7.*", "==3.5.*", ">=3.5"],
    )
    assert_ics(
        dedent("""\
            python_library(name="lib1")
            python_distribution(
                name="dist1",
                dependencies=[":lib1"],
                provides=setup_py(name="dist"),
            )

            python_library(name="lib2", interpreter_constraints=["==2.7.*"])
            python_distribution(
                name="dist2",
                dependencies=[":lib2"],
                provides=setup_py(name="dist"),
            )

            python_library(name="lib3", interpreter_constraints=[">=3.6"])
            python_distribution(
                name="dist3",
                dependencies=[":lib3"],
                provides=setup_py(name="dist"),
            )
            """),
        ["==2.7.*", global_constraint, ">=3.6"],
    )