예제 #1
0
파일: rules.py 프로젝트: zomglings/pants
def rules():
    return [
        *collect_rules(),
        UnionRule(TypecheckRequest, MyPyRequest),
        *pants_bin.rules(),
        *pex_from_targets.rules(),
    ]
예제 #2
0
def create_rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        rules=[
            *core_target_types_rules(),
            *dependencies.rules(),
            *docker_binary.rules(),
            *docker_build_args.rules(),
            *docker_build_context.rules(),
            *docker_build_env.rules(),
            *dockerfile.rules(),
            *dockerfile_parser.rules(),
            *package_image.rules(),
            *package_pex_binary.rules(),
            *pex_from_targets.rules(),
            *shell_target_types_rules(),
            *target_types_rules.rules(),
            package.find_all_packageable_targets,
            QueryRule(BuiltPackage, [PexBinaryFieldSet]),
            QueryRule(DockerBuildContext, (DockerBuildContextRequest, )),
        ],
        target_types=[
            DockerImageTarget,
            FilesGeneratorTarget,
            PexBinary,
            ShellSourcesGeneratorTarget,
            ShellSourceTarget,
        ],
    )
    return rule_runner
예제 #3
0
def rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        rules=[
            *repl_rules(),
            *ipython_subsystem_rules(),
            *python_repl.rules(),
            *pex_from_targets.rules(),
            *local_dists.rules(),
            *target_types_rules(),
            QueryRule(Process, (PexProcess, )),
        ],
        target_types=[
            PythonSourcesGeneratorTarget,
            ProtobufSourceTarget,
            PythonSourceTarget,
            PythonRequirementTarget,
        ],
    )
    rule_runner.write_files({
        "src/python/foo.proto":
        'syntax = "proto3";message Foo {}',
        "src/python/lib.py":
        "from foo import Foo\nclass SomeClass:\n  pass\n",
        "src/python/BUILD":
        ("protobuf_source(name='proto', source='foo.proto')\n"
         "python_sources(dependencies=[':proto'])"),
    })
    return rule_runner
예제 #4
0
def rules():
    return [
        *collect_rules(),
        UnionRule(AWSLambdaFieldSet, PythonAwsLambdaFieldSet),
        UnionRule(PackageFieldSet, PythonAwsLambdaFieldSet),
        *pex_from_targets.rules(),
    ]
예제 #5
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(),
    )
예제 #6
0
def test_runtime_package_dependencies() -> None:
    rule_runner = RuleRunner(
        rules=[
            build_runtime_package_dependencies,
            *pex_from_targets.rules(),
            *package_pex_binary.rules(),
            *python_target_type_rules(),
            QueryRule(BuiltPackageDependencies,
                      [BuildPackageDependenciesRequest]),
        ],
        target_types=[PythonSourcesGeneratorTarget, PexBinary],
    )
    rule_runner.set_options(args=[],
                            env_inherit={"PATH", "PYENV_ROOT", "HOME"})

    rule_runner.write_files({
        "src/py/main.py":
        "",
        "src/py/BUILD":
        dedent("""\
                python_sources()
                pex_binary(name='main', entry_point='main.py')
                """),
    })
    # Include an irrelevant target that cannot be built with `./pants package`.
    input_field = RuntimePackageDependenciesField(["src/py", "src/py:main"],
                                                  Address("fake"))
    result = rule_runner.request(
        BuiltPackageDependencies,
        [BuildPackageDependenciesRequest(input_field)])
    assert len(result) == 1
    built_package = result[0]
    snapshot = rule_runner.request(Snapshot, [built_package.digest])
    assert snapshot.files == ("src.py/main.pex", )
예제 #7
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            build_runtime_package_dependencies,
            create_or_update_coverage_config,
            *pytest_runner.rules(),
            *pytest_subsystem_rules(),
            *pex_from_targets.rules(),
            *dependency_inference_rules.rules(),
            *distdir.rules(),
            *config_files.rules(),
            *package_pex_binary.rules(),
            get_filtered_environment,
            *target_types_rules.rules(),
            *local_dists.rules(),
            *setup_py.rules(),
            *setuptools_rules(),
            QueryRule(TestResult, (PythonTestFieldSet, )),
            QueryRule(TestDebugRequest, (PythonTestFieldSet, )),
        ],
        target_types=[
            PexBinary,
            PythonSourcesGeneratorTarget,
            PythonTestsGeneratorTarget,
            PythonTestUtilsGeneratorTarget,
            PythonRequirementTarget,
            PythonDistribution,
        ],
        objects={"python_artifact": PythonArtifact},
    )
예제 #8
0
def rules():
    return [
        *collect_rules(),
        UnionRule(DistBuildEnvironmentRequest,
                  MyPycDistBuildEnvironmentRequest),
        PythonDistribution.register_plugin_field(UsesMyPycField),
        *pex_from_targets.rules(),
    ]
예제 #9
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *pex_from_targets.rules(),
            QueryRule(PexRequest, (PexFromTargetsRequest, )),
        ],
        target_types=[PythonSourcesGeneratorTarget, PythonRequirementTarget],
    )
예제 #10
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *pex_from_targets.rules(),
            QueryRule(PexRequest, (PexFromTargetsRequest, )),
        ],
        target_types=[PythonLibrary, PythonRequirementLibrary],
    )
예제 #11
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *repl_rules(),
            *python_repl.rules(),
            *pex_from_targets.rules(),
            QueryRule(Process, (PexProcess, )),
        ],
        target_types=[PythonLibrary, ProtobufLibrary],
    )
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *package_pex_binary.rules(),
            *pex_from_targets.rules(),
            *target_types_rules.rules(),
            *core_target_types_rules(),
            QueryRule(BuiltPackage, [PexBinaryFieldSet]),
        ],
        target_types=[PexBinary, Files, RelocatedFiles, Resources],
    )
예제 #13
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *export.rules(),
            *pex_from_targets.rules(),
            *target_types_rules.rules(),
            *distdir.rules(),
            QueryRule(Targets, [AddressSpecs]),
            QueryRule(ExportResults, [ExportVenvsRequest]),
        ],
        target_types=[PythonRequirementTarget],
    )
예제 #14
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *context_rules(),
            *core_target_types_rules(),
            *package_pex_binary.rules(),
            *pex_from_targets.rules(),
            *target_types_rules.rules(),
            QueryRule(BuiltPackage, [PexBinaryFieldSet]),
            QueryRule(DockerBuildContext, (DockerBuildContextRequest, )),
        ],
        target_types=[DockerImage, Files, PexBinary],
    )
예제 #15
0
def rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        preserve_tmpdirs=True,
        rules=[
            *config_files_rules(),
            *pex_from_targets.rules(),
            *rules(),
            QueryRule(PublishProcesses, [PublishPythonPackageRequest]),
        ],
        target_types=[PythonSourcesGeneratorTarget, PythonDistribution],
        objects={"python_artifact": PythonArtifact},
    )
    return set_options(rule_runner)
예제 #16
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            create_coverage_config,
            *pytest_runner.rules(),
            *pex_from_targets.rules(),
            *dependency_inference_rules.rules(),  # For conftest detection.
            *distdir.rules(),
            *binary.rules(),
            *package_pex_binary.rules(),
            get_filtered_environment,
            QueryRule(TestResult, (PythonTestFieldSet,)),
            QueryRule(TestDebugRequest, (PythonTestFieldSet,)),
        ],
        target_types=[PexBinary, PythonLibrary, PythonTests, PythonRequirementLibrary],
    )
예제 #17
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *pex_from_targets.rules(),
            *target_types_rules.rules(),
            QueryRule(PexRequest, (PexFromTargetsRequest,)),
            QueryRule(GlobalRequirementConstraints, ()),
            QueryRule(ChosenPythonResolve, [ChosenPythonResolveRequest]),
        ],
        target_types=[
            PythonSourcesGeneratorTarget,
            PythonRequirementTarget,
            PythonSourceTarget,
            PythonTestTarget,
        ],
    )
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *shunit2_test_runner.rules(),
            *source_files.rules(),
            *pex_from_targets.rules(),
            *package_pex_binary.rules(),
            *python_target_type_rules(),
            build_runtime_package_dependencies,
            get_filtered_environment,
            QueryRule(TestResult, [Shunit2FieldSet]),
            QueryRule(TestDebugRequest, [Shunit2FieldSet]),
            QueryRule(Shunit2Runner, [Shunit2RunnerRequest]),
        ],
        target_types=[ShellLibrary, Shunit2Tests, PythonLibrary, PexBinary],
    )
예제 #19
0
def rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        target_types=[
            PythonSourcesGeneratorTarget, PythonSourceTarget, FileTarget,
            ResourceTarget
        ],
        rules=[
            *pex_from_targets.rules(),
            *rules(),
            QueryRule(DockerComponent, [DockerPythonSourcesFS]),
            QueryRule(DockerComponent, [DockerFilesFS]),
            QueryRule(DockerComponent, [DockerResourcesFS]),
            QueryRule(DockerComponent, [DockerRelocatedFilesFS]),
        ],
    )
    return rule_runner
예제 #20
0
def rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        rules=[
            *config_files_rules(),
            *pex_from_targets.rules(),
            *rules(),
            QueryRule(PublishProcesses, [PublishToPyPiRequest]),
        ],
        target_types=[PythonSourcesGeneratorTarget, PythonDistribution],
        objects={"python_artifact": PythonArtifact},
    )
    rule_runner.set_options(
        [],
        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
        env={"TWINE_PASSWORD_PYPI": "secret"},
    )
    return rule_runner
예제 #21
0
def rules():
    return (
        *coverage_py.rules(),
        *tailor.rules(),
        *ancestor_files.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(),
    )
예제 #22
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            build_runtime_package_dependencies,
            create_or_update_coverage_config,
            *pytest_runner.rules(),
            *pex_from_targets.rules(),
            *dependency_inference_rules.rules(),
            *distdir.rules(),
            *config_files.rules(),
            *package_pex_binary.rules(),
            get_filtered_environment,
            *target_types_rules.rules(),
            QueryRule(TestResult, (PythonTestFieldSet, )),
            QueryRule(TestDebugRequest, (PythonTestFieldSet, )),
        ],
        target_types=[
            PexBinary, PythonLibrary, PythonTests, PythonRequirementLibrary
        ],
    )
예제 #23
0
def rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        rules=[
            *package_pex_binary.rules(),
            *pex_from_targets.rules(),
            *target_types_rules.rules(),
            *core_target_types_rules(),
            QueryRule(BuiltPackage, [PexBinaryFieldSet]),
        ],
        target_types=[
            FileTarget,
            FilesGeneratorTarget,
            PexBinary,
            PythonRequirementTarget,
            PythonSourcesGeneratorTarget,
            RelocatedFiles,
            ResourcesGeneratorTarget,
        ],
    )
    rule_runner.set_options([], env_inherit={"PATH", "PYENV_ROOT", "HOME"})
    return rule_runner
예제 #24
0
def rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        rules=[
            *repl_rules(),
            *ipython_subsystem_rules(),
            *python_repl.rules(),
            *pex_from_targets.rules(),
            *local_dists.rules(),
            QueryRule(Process, (PexProcess, )),
        ],
        target_types=[PythonLibrary, ProtobufLibrary],
    )
    rule_runner.write_files({
        "src/python/foo.proto":
        'syntax = "proto3";message Foo {}',
        "src/python/lib.py":
        "from foo import Foo\nclass SomeClass:\n  pass\n",
        "src/python/BUILD":
        ("protobuf_library(name='proto')\npython_library(dependencies=[':proto'])"
         ),
    })
    return rule_runner
예제 #25
0
파일: rules.py 프로젝트: nadeemnazeer/pants
def rules():
    return [
        *collect_rules(),
        UnionRule(LintRequest, PylintRequest),
        *pex_from_targets.rules(),
    ]
예제 #26
0
파일: rules.py 프로젝트: codealchemy/pants
def rules():
    return [
        *collect_rules(),
        UnionRule(PackageFieldSet, PythonGoogleCloudFunctionFieldSet),
        *pex_from_targets.rules(),
    ]
예제 #27
0
def test_url_assets(asset_type) -> None:
    rule_runner = RuleRunner(
        rules=[
            *target_type_rules(),
            *pex_from_targets.rules(),
            *package_pex_binary.rules(),
            *run_pex_binary.rules(),
            *python_target_type_rules.rules(),
            *run.rules(),
        ],
        target_types=[
            FileTarget, ResourceTarget, PythonSourceTarget, PexBinary
        ],
        objects={"http_source": HTTPSource},
    )
    http_source_info = (
        'url="https://raw.githubusercontent.com/python/cpython/7e46ae33bd522cf8331052c3c8835f9366599d8d/Lib/antigravity.py",'
        "len=500,"
        'sha256="8a5ee63e1b79ba2733e7ff4290b6eefea60e7f3a1ccb6bb519535aaf92b44967"'
    )
    rule_runner.write_files({
        "assets/BUILD":
        dedent(f"""\
                {asset_type}(
                    name='antigravity',
                    source=http_source(
                        {http_source_info},
                    ),
                )
                {asset_type}(
                    name='antigravity_renamed',
                    source=http_source(
                        {http_source_info},
                        filename="antigravity_renamed.py",
                    ),
                )
                """),
        "app/app.py":
        textwrap.dedent("""\
                import pathlib

                assets_path = pathlib.Path(__file__).parent.parent / "assets"
                for path in assets_path.iterdir():
                    print(path.name)
                    assert "https://xkcd.com/353/" in path.read_text()
                """),
        "app/BUILD":
        textwrap.dedent("""\
                python_source(
                    source="app.py",
                    dependencies=[
                        "assets:antigravity",
                        "assets:antigravity_renamed",
                    ]
                )
                pex_binary(name="app.py", entry_point='app.py')
                """),
    })
    with mock_console(rule_runner.options_bootstrapper) as (console,
                                                            stdout_reader):
        rule_runner.run_goal_rule(
            run.Run,
            args=["app/app.py"],
            env_inherit={"PATH", "PYENV_ROOT", "HOME"},
        )
        stdout = stdout_reader.get_stdout()
        assert "antigravity.py" in stdout
        assert "antigravity_renamed.py" in stdout
예제 #28
0
def test_archive() -> None:
    """Integration test for the `archive` target type.

    This tests some edges:
    * Using both `files` and `relocated_files`.
    * An `archive` containing another `archive`.
    """

    rule_runner = RuleRunner(
        rules=[
            *target_type_rules(),
            *pex_from_targets.rules(),
            *package_pex_binary.rules(),
            *python_target_type_rules.rules(),
            QueryRule(BuiltPackage, [ArchiveFieldSet]),
        ],
        target_types=[
            ArchiveTarget, FilesGeneratorTarget, RelocatedFiles, PexBinary
        ],
    )
    rule_runner.set_options([], env_inherit={"PATH", "PYENV_ROOT", "HOME"})

    rule_runner.write_files({
        "resources/d1.json":
        "{'k': 1}",
        "resources/d2.json":
        "{'k': 2}",
        "resources/BUILD":
        dedent("""\
                files(name='original_files', sources=['*.json'])

                relocated_files(
                    name='relocated_files',
                    files_targets=[':original_files'],
                    src="resources",
                    dest="data",
                )
                """),
        "project/app.py":
        "print('hello world!')",
        "project/BUILD":
        "pex_binary(entry_point='app.py')",
        "BUILD":
        dedent("""\
                archive(
                    name="archive1",
                    packages=["project"],
                    files=["resources:original_files"],
                    format="zip",
                )

                archive(
                    name="archive2",
                    packages=[":archive1"],
                    files=["resources:relocated_files"],
                    format="tar",
                    output_path="output/archive2.tar",
                )
                """),
    })

    def get_archive(target_name: str) -> FileContent:
        tgt = rule_runner.get_target(Address("", target_name=target_name))
        built_package = rule_runner.request(BuiltPackage,
                                            [ArchiveFieldSet.create(tgt)])
        digest_contents = rule_runner.request(DigestContents,
                                              [built_package.digest])
        assert len(digest_contents) == 1
        return digest_contents[0]

    def assert_archive1_is_valid(zip_bytes: bytes) -> None:
        io = BytesIO()
        io.write(zip_bytes)
        with zipfile.ZipFile(io) as zf:
            assert set(zf.namelist()) == {
                "resources/d1.json",
                "resources/d2.json",
                "project/project.pex",
            }
            with zf.open("resources/d1.json", "r") as f:
                assert f.read() == b"{'k': 1}"
            with zf.open("resources/d2.json", "r") as f:
                assert f.read() == b"{'k': 2}"

    archive1 = get_archive("archive1")
    assert_archive1_is_valid(archive1.content)

    archive2 = get_archive("archive2")
    assert archive2.path == "output/archive2.tar"
    io = BytesIO()
    io.write(archive2.content)
    io.seek(0)
    with tarfile.open(fileobj=io, mode="r:") as tf:
        assert set(
            tf.getnames()) == {"data/d1.json", "data/d2.json", "archive1.zip"}

        def get_file(fp: str) -> bytes:
            reader = tf.extractfile(fp)
            assert reader is not None
            return reader.read()

        assert get_file("data/d1.json") == b"{'k': 1}"
        assert get_file("data/d2.json") == b"{'k': 2}"
        assert_archive1_is_valid(get_file("archive1.zip"))
예제 #29
0
파일: rules.py 프로젝트: patricklaw/pants
def rules():
    return [
        *collect_rules(),
        UnionRule(CheckRequest, MyPyRequest),
        *pex_from_targets.rules(),
    ]