bitter-ability-32190
03/08/2023, 7:35 PMrule_runner
... š§µbitter-ability-32190
03/08/2023, 7:37 PM@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>)
bitter-ability-32190
03/08/2023, 7:38 PMclass _DoThingInNonlocalEnv:
pass
bitter-ability-32190
03/08/2023, 7:39 PMrule_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>
bitter-ability-32190
03/08/2023, 7:39 PMbitter-ability-32190
03/08/2023, 7:42 PMancient-vegetable-10556
03/08/2023, 7:43 PMancient-vegetable-10556
03/08/2023, 7:54 PMancient-vegetable-10556
03/08/2023, 7:55 PMbitter-ability-32190
03/08/2023, 8:17 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 PMancient-vegetable-10556
03/08/2023, 8:19 PMancient-vegetable-10556
03/08/2023, 8:22 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.ancient-vegetable-10556
03/08/2023, 8:22 PMPythonBuildStandAloneBinary
, and making download_python_binary
return that instead?ancient-vegetable-10556
03/08/2023, 8:23 PMEnvironmentTarget
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 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 PMbitter-ability-32190
03/08/2023, 10:32 PMbitter-ability-32190
03/08/2023, 10:32 PMancient-vegetable-10556
03/08/2023, 10:33 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.
witty-crayon-22786
03/08/2023, 10:36 PMancient-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
injectedwitty-crayon-22786
03/08/2023, 10:42 PM> 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 AMbitter-ability-32190
03/09/2023, 3:26 AMwitty-crayon-22786
03/09/2023, 3:49 AMbitter-ability-32190
03/09/2023, 3:49 AMbitter-ability-32190
03/09/2023, 3:53 AMQueryRule(ReturnType, [EnvironmentName, _DoThingInNonlocalEnv])
bitter-ability-32190
03/09/2023, 3:53 AMwitty-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 PMbitter-ability-32190
03/09/2023, 6:01 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 PMwitty-crayon-22786
03/09/2023, 6:02 PM