bitter-ability-32190
03/08/2023, 7:35 PMrule_runner
... š§µ@rule
async def my_rule(
env_tgt: EnvironmentTarget
) -> ReturnType:
if env_tgt.val is None or isinstance(env_tgt.val, LocalEnvironmentTarget):
return ReturnType(<local>)
result = await Get(
ReturnType,
_DoThingInNonlocalEnv()
)
return result
@rule
async def do_the_thing_in_docker(
_: _DoThingInNonlocalEnv, platform: Platform, tar_binary: TarBinary
) -> ReturnType:
return ReturnType(<docker>)
class _DoThingInNonlocalEnv:
pass
rule_runner.write_files(
{
"BUILD": "local_environment(name='local')",
}
)
rule_runner.set_options(["--environments-preview-names={'local': '//:local'}"])
result = rule_runner.request(ReturnType, [_DoThingInNonlocalEnv()])
assert result <is docker result>
ancient-vegetable-10556
03/08/2023, 7:43 PMbitter-ability-32190
03/08/2023, 8:17 PMancient-vegetable-10556
03/08/2023, 8:18 PMbitter-ability-32190
03/08/2023, 8:18 PMancient-vegetable-10556
03/08/2023, 8:18 PMEnvironmentTarget
can be resolved automatically if thereās an EnvironmentName
param in the relevant subgraph, and in this case, there is. Thatād mean thereās two rules that fulfil the params you pass in.PythonBuildStandAloneBinary
, and making download_python_binary
return that instead?EnvironmentTarget
and update get_python_for_scripts
to take that wrapper type instead of EnvironmentTarget
bitter-ability-32190
03/08/2023, 8:25 PMancient-vegetable-10556
03/08/2023, 8:25 PMbitter-ability-32190
03/08/2023, 8:25 PMancient-vegetable-10556
03/08/2023, 8:26 PMbitter-ability-32190
03/08/2023, 8:27 PMancient-vegetable-10556
03/08/2023, 8:27 PMbitter-ability-32190
03/08/2023, 8:30 PMancient-vegetable-10556
03/08/2023, 8:30 PMbitter-ability-32190
03/08/2023, 8:31 PMancient-vegetable-10556
03/08/2023, 8:33 PMbitter-ability-32190
03/08/2023, 10:32 PMancient-vegetable-10556
03/08/2023, 10:33 PMbitter-ability-32190
03/08/2023, 10:34 PMancient-vegetable-10556
03/08/2023, 10:35 PMEnvironmentName
/`EnvironmentTarget` has difficult-to-grok consequences.witty-crayon-22786
03/08/2023, 10:35 PMItās superfluousyes, this. values which are not used by declared queries will be ignored.
ancient-vegetable-10556
03/08/2023, 10:36 PMEnvironmentName
(or EnvironmentTarget
)witty-crayon-22786
03/08/2023, 10:38 PMRuleRunner(.., inherent_environment=None)
, all queries used in a RuleRunner
implicitly get a default EnvironmentName
injected> Itās superfluous
yes, this. values which are not used by declared queries will be ignored.more on this: this is at least in part because goal rules all have a static
Query
which provides them with everything that they _might_ need, and run_goal_rule
always passes all params that they might need. the matching from āwhich parameters you passedā to āquery to useā does a subset match. that could probably be changed with some finagling.bitter-ability-32190
03/09/2023, 3:26 AMwitty-crayon-22786
03/09/2023, 3:49 AMbitter-ability-32190
03/09/2023, 3:49 AMQueryRule(ReturnType, [EnvironmentName, _DoThingInNonlocalEnv])
witty-crayon-22786
03/09/2023, 5:49 PMRuleRunner(.., inherent_environment=..)
means that you end up with a query like QueryRule(ReturnType, [EnvironmentName, _DoThingInNonlocalEnv])
(because it rewrites your queries)⦠itās then using the rule which requires the fewest number of parameters to solve.
so disabling the inherent_environment would fix this, but youād have to actually explicitly pass the EnvironmentName for other things you were trying to executeancient-vegetable-10556
03/09/2023, 5:50 PMbitter-ability-32190
03/09/2023, 5:54 PMinherent_environment=None
, then in the query rule passing the name type, and in the runner request also passing the name.
Same issuewitty-crayon-22786
03/09/2023, 6:02 PM