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", )
def rule_runner() -> RuleRunner: return RuleRunner(rules=[ *docformatter_rules(), QueryRule(LintResults, (DocformatterRequest, )), QueryRule(FmtResult, (DocformatterRequest, )), QueryRule(SourceFiles, (SourceFilesRequest, )), ])
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *config_files.rules(), *coursier_fetch_rules(), *coursier_setup_rules(), *dep_inference_rules(), *external_tool_rules(), *java_parser_launcher_rules(), *java_parser_rules(), *java_target_rules(), *java_util_rules(), *javac_rules(), *junit_rules(), *source_files.rules(), *util_rules(), QueryRule(Addresses, [DependenciesRequest]), QueryRule(ExplicitlyProvidedDependencies, [DependenciesRequest]), QueryRule(InferredDependencies, [InferJavaImportDependencies]), QueryRule(Targets, [UnparsedAddressInputs]), ], target_types=[JavaSourcesGeneratorTarget, JunitTestsGeneratorTarget], bootstrap_args=["--javac-jdk=system" ], # TODO(#12293): use a fixed JDK version. )
def test_find_putative_targets() -> None: rule_runner = RuleRunner( rules=[ *tailor_rules(), QueryRule(PutativeTargets, (PutativeProtobufTargetsRequest, AllOwnedSources)), ], target_types=[], ) for path in [ "protos/foo/f.proto", "protos/foo/bar/baz1.proto", "protos/foo/bar/baz2.proto", "protos/foo/bar/baz3.proto", ]: rule_runner.create_file(path) pts = rule_runner.request( PutativeTargets, [PutativeProtobufTargetsRequest(), AllOwnedSources(["protos/foo/bar/baz1.proto"])], ) assert ( PutativeTargets( [ PutativeTarget.for_target_type(ProtobufLibrary, "protos/foo", "foo", ["f.proto"]), PutativeTarget.for_target_type( ProtobufLibrary, "protos/foo/bar", "bar", ["baz2.proto", "baz3.proto"] ), ] ) == pts )
def rule_runner() -> RuleRunner: rule_runner = RuleRunner( rules=[ *config_files.rules(), *classpath.rules(), *coursier_fetch_rules(), *coursier_setup_rules(), *external_tool_rules(), *source_files.rules(), *scalac_rules(), *util_rules(), *jdk_rules(), *target_types.rules(), *protobuf_target_types_rules(), *stripped_source_files.rules(), *scala_protobuf_rules(), QueryRule(HydratedSources, [HydrateSourcesRequest]), QueryRule(GeneratedSources, [GenerateScalaFromProtobufRequest]), QueryRule(DigestContents, (Digest,)), ], target_types=[ ScalaSourceTarget, ScalaSourcesGeneratorTarget, ProtobufSourcesGeneratorTarget, ], ) rule_runner.set_options( [], env_inherit=PYTHON_BOOTSTRAP_ENV, ) return rule_runner
def rule_runner() -> RuleRunner: return RuleRunner( target_types=[PythonRequirementTarget], context_aware_object_factories={ PantsRequirementCAOF.alias: PantsRequirementCAOF }, )
def rule_runner() -> RuleRunner: rule_runner = RuleRunner( rules=[ *awslambda_python_rules(), *awslambda_python_subsystem_rules(), *core_target_types_rules(), *package_pex_binary.rules(), *python_target_types_rules(), *target_rules(), QueryRule(BuiltPackage, (PythonAwsLambdaFieldSet, )), ], target_types=[ FileTarget, FilesGeneratorTarget, PexBinary, PythonAWSLambda, PythonRequirementTarget, PythonRequirementTarget, PythonSourcesGeneratorTarget, RelocatedFiles, ResourcesGeneratorTarget, ], ) rule_runner.set_options([], env_inherit={"PATH", "PYENV_ROOT", "HOME"}) return rule_runner
def test_streaming_workunits_expanded_specs(run_tracker: RunTracker) -> None: rule_runner = RuleRunner( target_types=[PythonSourcesGeneratorTarget], rules=[ QueryRule(ProcessResult, (Process, )), ], ) rule_runner.set_options(["--backend-packages=pants.backend.python"]) rule_runner.write_files({ "src/python/somefiles/BUILD": "python_sources()", "src/python/somefiles/a.py": "print('')", "src/python/somefiles/b.py": "print('')", "src/python/others/BUILD": "python_sources()", "src/python/others/a.py": "print('')", "src/python/others/b.py": "print('')", }) specs = SpecsParser().parse_specs( ["src/python/somefiles::", "src/python/others/b.py"], convert_dir_literal_to_address_literal=False, description_of_origin="tests", ) class Callback(WorkunitsCallback): @property def can_finish_async(self) -> bool: return False def __call__(self, **kwargs) -> None: context = kwargs["context"] assert isinstance(context, StreamingWorkunitContext) expanded = context.get_expanded_specs() targets = expanded.targets assert len(targets.keys()) == 2 assert targets["src/python/others/b.py"] == [ TargetInfo(filename="src/python/others/b.py") ] assert set(targets["src/python/somefiles"]) == { TargetInfo(filename="src/python/somefiles/a.py"), TargetInfo(filename="src/python/somefiles/b.py"), } handler = StreamingWorkunitHandler( scheduler=rule_runner.scheduler, run_tracker=run_tracker, callbacks=[Callback()], report_interval_seconds=0.01, max_workunit_verbosity=LogLevel.INFO, specs=specs, options_bootstrapper=create_options_bootstrapper( ["--backend-packages=pants.backend.python"]), allow_async_completion=False, ) stdout_process = Process(argv=("/bin/bash", "-c", "/bin/echo 'stdout output'"), description="Stdout process") with handler: rule_runner.request(ProcessResult, [stdout_process])
def test_setup_lockfile_interpreter_constraints() -> None: rule_runner = RuleRunner( rules=[ *subsystem_rules(), QueryRule(PythonLockfileRequest, [IPythonLockfileSentinel]) ], target_types=[PythonSourcesGeneratorTarget, GenericTarget], ) global_constraint = "==3.9.*" rule_runner.set_options( ["--ipython-lockfile=lockfile.txt"], env={ "PANTS_PYTHON_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, [IPythonLockfileSentinel()]) assert lockfile_request.interpreter_constraints == InterpreterConstraints( expected) assert_ics("python_sources()", [global_constraint]) assert_ics("python_sources(interpreter_constraints=['==2.7.*'])", ["==2.7.*"]) assert_ics( "python_sources(interpreter_constraints=['==2.7.*', '==3.5.*'])", ["==2.7.*", "==3.5.*"]) # If no Python targets in repo, fall back to global [python] constraints. assert_ics("target()", [global_constraint]) # If there are multiple distinct ICs in the repo, we OR them. Even though the user might AND # them by running `./pants repl ::`, they could also run on more precise subsets like # `./pants repl py2::` and then `./pants repl py3::` assert_ics( dedent("""\ python_sources(name='a', interpreter_constraints=['==2.7.*']) python_sources(name='b', interpreter_constraints=['==3.5.*']) """), ["==2.7.*", "==3.5.*"], ) assert_ics( dedent("""\ python_sources(name='a', interpreter_constraints=['==2.7.*', '==3.5.*']) python_sources(name='b', interpreter_constraints=['>=3.5']) """), ["==2.7.*", "==3.5.*", ">=3.5"], ) assert_ics( dedent("""\ python_sources(name='a') python_sources(name='b', interpreter_constraints=['==2.7.*']) python_sources(name='c', interpreter_constraints=['>=3.6']) """), ["==2.7.*", global_constraint, ">=3.6"], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *tailor.rules(), QueryRule(PutativeTargets, (PutativeJSTargetsRequest, AllOwnedSources)), ], target_types=[JSSourcesGeneratorTarget], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *peek.rules(), QueryRule(TargetDatas, [AddressSpecs]), ], target_types=[FilesGeneratorTarget, GenericTarget], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *python_requirements.rules(), QueryRule(_TargetParametrizations, [Address]), ], target_types=[PythonRequirementsTargetGenerator], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *pylint_rules(), QueryRule(LintResults, (PylintRequest, )), ], target_types=[PythonLibrary, PythonRequirementLibrary], )
def rule_runner() -> RuleRunner: runner = RuleRunner(rules=dependee_rules(), target_types=[MockTarget]) runner.write_files({ "base/BUILD": "tgt()", "intermediate/BUILD": "tgt(dependencies=['base'])", "leaf/BUILD": "tgt(dependencies=['intermediate'])", }) return runner
def new_rule_runner() -> RuleRunner: return RuleRunner( rules=[ QueryRule(ProcessResult, [Process]), QueryRule(FallibleProcessResult, [Process]), QueryRule(InteractiveProcess, [InteractiveProcessRequest]), ], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *archive_rules(), QueryRule(Digest, [CreateArchive]), QueryRule(ExtractedArchive, [Digest]), ], )
def rule_runner() -> RuleRunner: return RuleRunner(rules=[ enrich_fmt_result, format_python_target, *black_rules(), *isort_rules(), QueryRule(LanguageFmtResults, (PythonFmtTargets, )), ])
def rule_runner() -> RuleRunner: return RuleRunner(rules=[ *filter_empty_sources_rules(), QueryRule(FieldSetsWithSources, (FieldSetsWithSourcesRequest, OptionsBootstrapper)), QueryRule(TargetsWithSources, (TargetsWithSourcesRequest, OptionsBootstrapper)), ])
def rule_runner() -> RuleRunner: return RuleRunner( rules=rules(), target_types=[ PythonSourcesGeneratorTarget, PythonRequirementTarget, SpecialDepsTarget ], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[QueryRule(Targets, (Specs, ))], target_types=[PythonRequirementLibrary, PythonRequirementsFile], context_aware_object_factories={ "pipenv_requirements": PipenvRequirements }, )
def address_specs_rule_runner() -> RuleRunner: return RuleRunner( rules=[ QueryRule(AddressesWithOrigins, (AddressSpecs, OptionsBootstrapper)) ], target_types=[MockTgt], )
def test_strict_equals() -> None: rule_runner = RuleRunner( rules=[boolean_and_int, QueryRule(A, [int, bool])]) # With the default implementation of `__eq__` for boolean and int, `1 == True`. But in the # engine, that behavior would be surprising and would cause both of these Params to intern # to the same value, triggering an error. Instead, the engine additionally includes the # type of a value in equality. assert A() == rule_runner.request(A, [1, True])
def rule_runner() -> RuleRunner: return RuleRunner(rules=[ *external_tool.rules(), *tool.rules(), *process.rules(), *unittest.rules(), QueryRule(ProcessResult, (HelmProcess, )), ])
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *tailor_rules(), QueryRule(PutativeTargets, (PutativeWsdlTargetsRequest, AllOwnedSources)), ], target_types=[], )
def rule_runner() -> RuleRunner: return RuleRunner( preserve_tmpdirs=True, rules=[ *util_rules(), QueryRule(FileDigest, (ExtractFileDigest, )), ], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *pex_from_targets.rules(), QueryRule(PexRequest, (PexFromTargetsRequest, )), ], target_types=[PythonSourcesGeneratorTarget, PythonRequirementTarget], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=( *pipenv_requirements.rules(), QueryRule(_TargetParametrizations, [Address]), ), target_types=[PipenvRequirementsTargetGenerator], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *pex_from_targets.rules(), QueryRule(PexRequest, (PexFromTargetsRequest, )), ], target_types=[PythonLibrary, PythonRequirementLibrary], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *awslambda_python_rules(), *target_rules(), QueryRule(BuiltPackage, (PythonAwsLambdaFieldSet, )), ], target_types=[PythonAWSLambda, PythonLibrary], )
def rule_runner() -> RuleRunner: return RuleRunner( rules=[ *tailor.rules(), *source_files.rules(), QueryRule(PutativeTargets, (PutativePythonTargetsRequest, )), ], target_types=[PythonLibrary, PythonTests], )