wide-midnight-78598
11/17/2022, 7:54 PMclass CowsayTool(NpxToolBase):
options_scope = "cowsay"
name = "Cowsay"
# Intentionally older version.
default_version = "cowsay@1.4.0"
help = "The Cowsay utility for printing cowsay messages"
I want to ensure that the version option is present, but the create_subsystem
utility doesn't seem to do any checking to see if fields exist or not: cowsaytool = create_subsystem(CowsayTool, versionXYZ="cowsay@1.5.0")
My hope was to do something like this: rule_runner.set_options(["--backend-packages=['pants.backend.experimental.javascript']", "--cowsay-version='cowsay@1.5.0'"])
and then somehow get the subsystem and verify that the version was picked up correctly.
Would I only be able to do this via the run_pants
mechanism (which seems heavy for what I want)witty-crayon-22786
11/17/2022, 8:12 PMrule_runner.set_options(..)
rule_runner.request(MySubsystem, [])
wide-midnight-78598
11/17/2022, 8:16 PMrule_runner.request(MySubsystem, [])๐คฏ
return RuleRunner(
rules=[
*nodejs.rules(),
*CowsayTool.rules(),
QueryRule(ProcessResult, [nodejs.NpxProcess]),
],
)
Exception: No installed QueryRules return the type CowsayTool. Try registering QueryRule(CowsayTool for EnvironmentName).
witty-crayon-22786
11/17/2022, 8:21 PMwide-midnight-78598
11/17/2022, 8:24 PM@pytest.fixture
def rule_runner() -> RuleRunner:
return RuleRunner(
rules=[
*nodejs.rules(),
*CowsayTool.rules(),
QueryRule(CowsayTool, []),
],
)
def test_installing(rule_runner: RuleRunner):
rule_runner.set_options(["--backend-packages=['pants.backend.experimental.javascript']", "--cowsay-version=cowsay@1.5.0"])
tool = rule_runner.request(CowsayTool, [])
assert tool.default_version == "cowsay@1.4.0"
assert tool.version == "cowsay@1.5.0"
SubsystemRule(CowsayTool),
complains that this usage is deprecated
*CowsayTool.rules()
gets a typecheck error because of missing the cls
*Subsystem.rules(CowsayTool),
fails on : TypeError: rules() takes 1 positional argument but 2 were given
Using SubsystemRule for now, as it seems to pass at leastwitty-crayon-22786
11/17/2022, 8:31 PMancient-vegetable-10556
11/17/2022, 8:35 PM@memoized_classmethod
CowsayTool.rules()
and shoving a # type: ignore[ERROR_CODE]
at the end of the line for now.wide-midnight-78598
11/17/2022, 8:46 PMancient-vegetable-10556
11/17/2022, 8:47 PM@memoized
so that it works with @classmethod
and @staticmethod
, or to get a mypy plugin to understand the situationwide-midnight-78598
11/17/2022, 8:48 PMancient-vegetable-10556
11/17/2022, 8:48 PMignore
as tightly scoped as possible is the best practicewide-midnight-78598
11/17/2022, 8:49 PM), # type: ignore[call-arg]
?ancient-vegetable-10556
11/17/2022, 8:49 PM# type: ignore
would be a bad idea ๐wide-midnight-78598
11/17/2022, 8:49 PM