late-lifeguard-85949
02/07/2025, 12:58 AMnative_engine.IntrinsicError: Get(InterpreterConstraints, InterpreterConstraintsRequest, InterpreterConstraintsRequest(addresses=Addresses([Address(src/******/__init__.py:lib), Address(src/******/app.py:lib), Address(src/******/conf.py:lib), Address(src/******/schemas.py:lib), Address(src/******/__init__.py:lib), Address(src/******/cli.py:lib), Address(src/******/core.py:lib), Addr
ess(src/******/cors.py:lib), Address(src/******/models.py:lib)]), hardcoded_interpreter_constraints=None)) was not detected in your @rule body at rule compile time. Was the `Get` constructor called in a non async-function, or was it inside an async function defined after the @rule? Make sure the `Get` is defined before or inside the @rule body.
late-lifeguard-85949
02/07/2025, 12:59 AMcreate_python_repl_request
as the cause.
I'm able to fix my problem by simply copying the whole rules function code into my module which isn't a big problem - but obviously nicer to simply leverage the existing code.wide-midnight-78598
02/07/2025, 12:59 AMwide-midnight-78598
02/07/2025, 1:00 AM@rule_helper
I think, but now is just async def whatever()
late-lifeguard-85949
02/07/2025, 1:00 AMlate-lifeguard-85949
02/07/2025, 1:00 AMimport logging
from dataclasses import dataclass
from typing import ClassVar
from pants.backend.python.goals.repl import PythonRepl, create_python_repl_request
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.util_rules.pex_environment import PexEnvironment
from pants.core.goals.package import BuiltPackage, BuiltPackageArtifact, OutputPathField, PackageFieldSet
from pants.core.util_rules.environments import EnvironmentField
from pants.engine.env_vars import CompleteEnvironmentVars
from pants.engine.fs import CreateDigest, Digest, FileContent
from pants.engine.process import Process, ProcessResult
from pants.engine.rules import Get, collect_rules, rule
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Dependencies,
DependenciesRequest,
DictStringToStringField,
Field,
StringField,
Target,
Targets,
)
from pants.engine.unions import UnionRule
from pants.util.logging import LogLevel
logger = logging.getLogger(__name__)
class GeneratorFunction(StringField):
alias = "generator_function"
required = True
class GeneratorEnvironmentField(DictStringToStringField):
alias = "generator_environment"
required = False
class GeneratedFile(Target):
alias = "generated_file"
core_fields: ClassVar[tuple[type[Field], ...]] = (
*COMMON_TARGET_FIELDS,
GeneratorFunction,
GeneratorEnvironmentField,
OutputPathField,
EnvironmentField,
Dependencies,
)
@dataclass(frozen=True)
class GeneratedFileFieldSet(PackageFieldSet):
required_fields = (GeneratorFunction, OutputPathField)
generator_function: GeneratorFunction
generator_environment: GeneratorEnvironmentField
output_path: OutputPathField
dependencies: Dependencies
@rule(level=<http://LogLevel.INFO|LogLevel.INFO>)
async def package_generated_file(
field_set: GeneratedFileFieldSet,
pex_env: PexEnvironment,
python_setup: PythonSetup,
complete_env: CompleteEnvironmentVars,
) -> BuiltPackage:
targets = await Get(Targets, DependenciesRequest(field_set.dependencies))
repl_impl = PythonRepl(targets=targets)
# Because we're (ab)using another rule here that we need to call the inner
# function of the rule, rather than just the rule itself due to issues passing
# python setup to rule.
repl_request = await create_python_repl_request.__wrapped__(repl_impl, pex_env, python_setup)
env = {**complete_env, **repl_request.extra_env, **(field_set.generator_environment.value or {})}
process_result = await Get(
ProcessResult,
Process(
argv=(*repl_request.args, *field_set.generator_function.value.split(" ")),
env=env,
description=f"Generating file using {GeneratorFunction.alias}",
input_digest=repl_request.digest,
immutable_input_digests=repl_request.immutable_input_digests,
append_only_caches=repl_request.append_only_caches,
),
)
output_path = field_set.output_path.value_or_default(file_ending="")
generated_digest = await Get(Digest, CreateDigest([FileContent(output_path, process_result.stdout)]))
artefact = BuiltPackageArtifact(output_path)
return BuiltPackage(digest=generated_digest, artifacts=(artefact,))
def rules():
return (
*collect_rules(),
UnionRule(PackageFieldSet, GeneratedFileFieldSet),
)
def target_types():
return [
GeneratedFile,
]
late-lifeguard-85949
02/07/2025, 1:00 AMcreate_python_repl_request
herelate-lifeguard-85949
02/07/2025, 1:01 AMwide-midnight-78598
02/07/2025, 1:01 AMawait create_python_repl_request.__wrapped__(repl_impl, pex_env, python_setup)
Yeah, I dont know what that is. Supposed to be a Get
I'm guessing, unless you're using the newer call-by-name, which has its own quirklslate-lifeguard-85949
02/07/2025, 1:03 AMlate-lifeguard-85949
02/07/2025, 1:03 AMlate-lifeguard-85949
02/07/2025, 1:04 AMwide-midnight-78598
02/07/2025, 1:07 AMGet()
wide-midnight-78598
02/07/2025, 1:07 AMlate-lifeguard-85949
02/07/2025, 1:09 AMwide-midnight-78598
02/07/2025, 1:14 AMlate-lifeguard-85949
02/07/2025, 1:16 AMlate-lifeguard-85949
02/07/2025, 1:17 AMlate-lifeguard-85949
02/07/2025, 1:18 AMlate-lifeguard-85949
02/07/2025, 1:18 AMwide-midnight-78598
02/07/2025, 1:18 AMlate-lifeguard-85949
02/07/2025, 1:19 AMwide-midnight-78598
02/07/2025, 1:20 AMwide-midnight-78598
02/07/2025, 1:20 AMwide-midnight-78598
02/07/2025, 1:21 AMlate-lifeguard-85949
02/07/2025, 1:24 AMlate-lifeguard-85949
02/07/2025, 1:24 AMwide-midnight-78598
02/07/2025, 1:25 AMpex_binary
out of it, in case you need to run a python file like a script.
What I’m trying to think of is the least-code way to do what you wantlate-lifeguard-85949
02/07/2025, 1:26 AMwide-midnight-78598
02/07/2025, 1:28 AMarchive
- maybe this could work with a python package too, but I’ve just never done itlate-lifeguard-85949
02/07/2025, 1:30 AMlate-lifeguard-85949
02/07/2025, 1:31 AMwide-midnight-78598
02/07/2025, 1:31 AMlate-lifeguard-85949
02/07/2025, 1:31 AMlate-lifeguard-85949
02/07/2025, 1:32 AM