14
14
from pants .backend .python .dependency_inference .rules import (
15
15
ImportOwnerStatus ,
16
16
PythonImportDependenciesInferenceFieldSet ,
17
- ResolvedParsedPythonDependencies ,
18
17
ResolvedParsedPythonDependenciesRequest ,
18
+ resolve_parsed_dependencies ,
19
19
)
20
20
from pants .backend .python .framework .django .detect_apps import DjangoApps
21
21
from pants .backend .python .subsystems .setup import PythonSetup
22
22
from pants .backend .python .target_types import EntryPoint
23
23
from pants .backend .python .util_rules import pex
24
24
from pants .backend .python .util_rules .interpreter_constraints import InterpreterConstraints
25
- from pants .backend .python .util_rules .pex import PexRequest , VenvPex , VenvPexProcess
25
+ from pants .backend .python .util_rules .pex import PexRequest , VenvPexProcess , create_venv_pex
26
26
from pants .base .specs import FileGlobSpec , RawSpecs
27
27
from pants .core .util_rules .source_files import SourceFilesRequest
28
- from pants .core .util_rules .stripped_source_files import StrippedSourceFiles
28
+ from pants .core .util_rules .stripped_source_files import strip_source_roots
29
29
from pants .engine .fs import CreateDigest , FileContent
30
- from pants .engine .internals .native_engine import Digest
31
- from pants .engine .internals . selectors import Get
32
- from pants .engine .process import ProcessResult
33
- from pants .engine .rules import collect_rules , rule
34
- from pants .engine .target import InferDependenciesRequest , InferredDependencies , Targets
30
+ from pants .engine .internals .graph import resolve_targets
31
+ from pants .engine .intrinsics import create_digest
32
+ from pants .engine .process import execute_process_or_raise
33
+ from pants .engine .rules import collect_rules , implicitly , rule
34
+ from pants .engine .target import InferDependenciesRequest , InferredDependencies
35
35
from pants .engine .unions import UnionRule
36
36
from pants .util .logging import LogLevel
37
37
from pants .util .resources import read_resource
@@ -53,34 +53,36 @@ async def _django_migration_dependencies(
53
53
python_setup : PythonSetup ,
54
54
django_apps : DjangoApps ,
55
55
) -> InferredDependencies :
56
- stripped_sources = await Get (
57
- StrippedSourceFiles , SourceFilesRequest ([request .field_set .source ])
56
+ stripped_sources = await strip_source_roots (
57
+ ** implicitly ( SourceFilesRequest ([request .field_set .source ]) )
58
58
)
59
59
assert len (stripped_sources .snapshot .files ) == 1
60
60
61
61
file_content = FileContent ("__visitor.py" , read_resource (__name__ , _visitor_resource ))
62
- visitor_digest = await Get (Digest , CreateDigest ([file_content ]))
63
- venv_pex = await Get (
64
- VenvPex ,
65
- PexRequest (
66
- output_filename = "__visitor.pex" ,
67
- internal_only = True ,
68
- main = EntryPoint ("__visitor" ),
69
- interpreter_constraints = InterpreterConstraints .create_from_compatibility_fields (
70
- [request .field_set .interpreter_constraints ], python_setup = python_setup
71
- ),
72
- sources = visitor_digest ,
73
- ),
62
+ visitor_digest = await create_digest (CreateDigest ([file_content ]))
63
+ venv_pex = await create_venv_pex (
64
+ ** implicitly (
65
+ PexRequest (
66
+ output_filename = "__visitor.pex" ,
67
+ internal_only = True ,
68
+ main = EntryPoint ("__visitor" ),
69
+ interpreter_constraints = InterpreterConstraints .create_from_compatibility_fields (
70
+ [request .field_set .interpreter_constraints ], python_setup = python_setup
71
+ ),
72
+ sources = visitor_digest ,
73
+ )
74
+ )
74
75
)
75
- process_result = await Get (
76
- ProcessResult ,
77
- VenvPexProcess (
78
- venv_pex ,
79
- argv = [stripped_sources .snapshot .files [0 ]],
80
- description = f"Determine Django app dependencies for { request .field_set .address } " ,
81
- input_digest = stripped_sources .snapshot .digest ,
82
- level = LogLevel .DEBUG ,
83
- ),
76
+ process_result = await execute_process_or_raise (
77
+ ** implicitly (
78
+ VenvPexProcess (
79
+ venv_pex ,
80
+ argv = [stripped_sources .snapshot .files [0 ]],
81
+ description = f"Determine Django app dependencies for { request .field_set .address } " ,
82
+ input_digest = stripped_sources .snapshot .digest ,
83
+ level = LogLevel .DEBUG ,
84
+ )
85
+ )
84
86
)
85
87
# See in script for where we explicitly encoded as utf8. Even though utf8 is the
86
88
# default for decode(), we make that explicit here for emphasis.
@@ -92,8 +94,7 @@ async def _django_migration_dependencies(
92
94
]
93
95
resolve = request .field_set .resolve .normalized_value (python_setup )
94
96
95
- resolved_dependencies = await Get (
96
- ResolvedParsedPythonDependencies ,
97
+ resolved_dependencies = await resolve_parsed_dependencies (
97
98
ResolvedParsedPythonDependenciesRequest (
98
99
request .field_set ,
99
100
ParsedPythonDependencies (
@@ -104,6 +105,7 @@ async def _django_migration_dependencies(
104
105
),
105
106
resolve ,
106
107
),
108
+ ** implicitly (),
107
109
)
108
110
109
111
return InferredDependencies (
@@ -136,8 +138,7 @@ async def _django_app_implicit_dependencies(
136
138
137
139
resolve = request .field_set .resolve .normalized_value (python_setup )
138
140
139
- resolved_dependencies = await Get (
140
- ResolvedParsedPythonDependencies ,
141
+ resolved_dependencies = await resolve_parsed_dependencies (
141
142
ResolvedParsedPythonDependenciesRequest (
142
143
request .field_set ,
143
144
ParsedPythonDependencies (
@@ -149,6 +150,7 @@ async def _django_app_implicit_dependencies(
149
150
),
150
151
resolve ,
151
152
),
153
+ ** implicitly (),
152
154
)
153
155
154
156
spec_paths = [
@@ -158,13 +160,13 @@ async def _django_app_implicit_dependencies(
158
160
for address in result .address
159
161
]
160
162
161
- targets = await Get (
162
- Targets ,
163
- RawSpecs ,
164
- RawSpecs . create (
165
- specs = [ FileGlobSpec ( f" { spec_path } /*.py" ) for spec_path in spec_paths ] ,
166
- description_of_origin = "Django implicit dependency detection" ,
167
- ),
163
+ targets = await resolve_targets (
164
+ ** implicitly (
165
+ RawSpecs . create (
166
+ specs = [ FileGlobSpec ( f" { spec_path } /*.py" ) for spec_path in spec_paths ],
167
+ description_of_origin = "Django implicit dependency detection" ,
168
+ )
169
+ )
168
170
)
169
171
170
172
return InferredDependencies (sorted (target .address for target in targets ))
@@ -188,9 +190,9 @@ async def infer_django_dependencies(
188
190
189
191
190
192
def rules ():
191
- return [
193
+ return (
192
194
* collect_rules (),
193
195
* pex .rules (),
194
196
* dependency_inference .rules .rules (),
195
197
UnionRule (InferDependenciesRequest , InferDjangoDependencies ),
196
- ]
198
+ )
0 commit comments