Skip to content

Commit e73fd3f

Browse files
committed
[skip ci] stub test
1 parent 6ffb7db commit e73fd3f

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

pants-plugins/pack_metadata/target_types_rules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
# repurposed from pants.backend.python.target_types_rules
1514
import os
1615
from dataclasses import dataclass
1716

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Copyright 2023 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from __future__ import annotations
15+
16+
from textwrap import dedent
17+
18+
import pytest
19+
20+
from pants.backend.python.target_types import (
21+
EntryPoint,
22+
PythonSourceTarget,
23+
PythonSourcesGeneratorTarget,
24+
)
25+
from pants.backend.python.target_types_rules import rules as python_target_types_rules
26+
from pants.engine.addresses import Address
27+
from pants.engine.internals.scheduler import ExecutionError
28+
from pants.engine.target import InferredDependencies
29+
from pants.testutil.rule_runner import QueryRule, RuleRunner
30+
31+
from .target_types_rules import (
32+
InferPacksGlobDependencies,
33+
PacksGlobInferenceFieldSet,
34+
infer_packs_globs_dependencies,
35+
rules as pack_metadata_target_types_rules,
36+
)
37+
from .target_types import PacksGlob, PacksGlobDependencies
38+
39+
40+
def test_infer_packs_globs_dependencies() -> None:
41+
rule_runner = RuleRunner(
42+
rules=[
43+
*python_target_types_rules(),
44+
*pack_metadata_target_types_rules(),
45+
QueryRule(InferredDependencies, (InferPacksGlobDependencies,)),
46+
],
47+
target_types=[
48+
PythonSourceTarget,
49+
PythonSourcesGeneratorTarget,
50+
PacksGlob,
51+
],
52+
)
53+
rule_runner.write_files(
54+
{
55+
"runners/foobar_runner/BUILD": dedent(
56+
"""\
57+
stevedore_extension(
58+
name="runner",
59+
namespace="st2common.runners.runner",
60+
entry_points={
61+
"foobar": "foobar_runner.foobar_runner",
62+
},
63+
)
64+
"""
65+
),
66+
"runners/foobar_runner/foobar_runner/BUILD": "python_sources()",
67+
"runners/foobar_runner/foobar_runner/__init__.py": "",
68+
"runners/foobar_runner/foobar_runner/foobar_runner.py": "",
69+
"runners/foobar_runner/foobar_runner/thing1.py": dedent(
70+
"""\
71+
class ThingBackend:
72+
pass
73+
"""
74+
),
75+
"runners/foobar_runner/foobar_runner/thing2.py": dedent(
76+
"""\
77+
class ThingBackend:
78+
pass
79+
"""
80+
),
81+
}
82+
)
83+
84+
def run_dep_inference(address: Address) -> InferredDependencies:
85+
args = [
86+
"--source-root-patterns=runners/*_runner",
87+
]
88+
rule_runner.set_options(args, env_inherit={"PATH", "PYENV_ROOT", "HOME"})
89+
target = rule_runner.get_target(address)
90+
return rule_runner.request(
91+
InferredDependencies,
92+
[
93+
InferStevedoreExtensionDependencies(
94+
StevedoreEntryPointsInferenceFieldSet.create(target)
95+
)
96+
],
97+
)
98+
99+
assert run_dep_inference(
100+
Address("runners/foobar_runner", target_name="runner")
101+
) == InferredDependencies(
102+
[
103+
Address(
104+
"runners/foobar_runner/foobar_runner",
105+
relative_file_path="foobar_runner.py",
106+
),
107+
],
108+
)
109+
110+
assert run_dep_inference(
111+
Address("runners/foobar_runner", target_name="foobar")
112+
) == InferredDependencies(
113+
[
114+
Address(
115+
"runners/foobar_runner/foobar_runner",
116+
relative_file_path="thing1.py",
117+
),
118+
Address(
119+
"runners/foobar_runner/foobar_runner",
120+
relative_file_path="thing2.py",
121+
),
122+
],
123+
)

0 commit comments

Comments
 (0)