6
6
from typing import Tuple , cast
7
7
8
8
from pants .backend .python .target_types import (
9
- PexAlwaysWriteCache ,
10
- PexEmitWarnings ,
11
- PexIgnoreErrors ,
12
- PexInheritPath ,
13
- PexShebang ,
14
- PexZipSafe ,
15
- PythonBinaryDefaults ,
16
- PythonBinarySources ,
17
- PythonEntryPoint ,
9
+ PexAlwaysWriteCacheField ,
10
+ PexBinaryDefaults ,
11
+ PexBinarySources ,
12
+ PexEmitWarningsField ,
13
+ PexEntryPointField ,
14
+ PexIgnoreErrorsField ,
15
+ PexInheritPathField ,
18
16
)
19
- from pants .backend .python .target_types import PythonPlatforms as PythonPlatformsField
17
+ from pants .backend .python .target_types import PexPlatformsField as PythonPlatformsField
18
+ from pants .backend .python .target_types import PexShebangField , PexZipSafeField
20
19
from pants .backend .python .util_rules .pex import PexPlatforms , TwoStepPex
21
20
from pants .backend .python .util_rules .pex_from_targets import (
22
21
PexFromTargetsRequest ,
40
39
41
40
42
41
@dataclass (frozen = True )
43
- class PythonBinaryFieldSet (PackageFieldSet , BinaryFieldSet , RunFieldSet ):
44
- required_fields = (PythonEntryPoint , PythonBinarySources )
42
+ class PexBinaryFieldSet (PackageFieldSet , BinaryFieldSet , RunFieldSet ):
43
+ required_fields = (PexEntryPointField , PexBinarySources )
45
44
46
- sources : PythonBinarySources
47
- entry_point : PythonEntryPoint
45
+ sources : PexBinarySources
46
+ entry_point : PexEntryPointField
48
47
49
48
output_path : OutputPathField
50
- always_write_cache : PexAlwaysWriteCache
51
- emit_warnings : PexEmitWarnings
52
- ignore_errors : PexIgnoreErrors
53
- inherit_path : PexInheritPath
54
- shebang : PexShebang
55
- zip_safe : PexZipSafe
49
+ always_write_cache : PexAlwaysWriteCacheField
50
+ emit_warnings : PexEmitWarningsField
51
+ ignore_errors : PexIgnoreErrorsField
52
+ inherit_path : PexInheritPathField
53
+ shebang : PexShebangField
54
+ zip_safe : PexZipSafeField
56
55
platforms : PythonPlatformsField
57
56
58
- def generate_additional_args (
59
- self , python_binary_defaults : PythonBinaryDefaults
60
- ) -> Tuple [str , ...]:
57
+ def generate_additional_args (self , pex_binary_defaults : PexBinaryDefaults ) -> Tuple [str , ...]:
61
58
args = []
62
59
if self .always_write_cache .value is True :
63
60
args .append ("--always-write-cache" )
64
- if self .emit_warnings .value_or_global_default (python_binary_defaults ) is False :
61
+ if self .emit_warnings .value_or_global_default (pex_binary_defaults ) is False :
65
62
args .append ("--no-emit-warnings" )
66
63
if self .ignore_errors .value is True :
67
64
args .append ("--ignore-errors" )
@@ -75,9 +72,9 @@ def generate_additional_args(
75
72
76
73
77
74
@rule (level = LogLevel .DEBUG )
78
- async def package_python_binary (
79
- field_set : PythonBinaryFieldSet ,
80
- python_binary_defaults : PythonBinaryDefaults ,
75
+ async def package_pex_binary (
76
+ field_set : PexBinaryFieldSet ,
77
+ pex_binary_defaults : PexBinaryDefaults ,
81
78
global_options : GlobalOptions ,
82
79
) -> BuiltPackage :
83
80
entry_point = field_set .entry_point .value
@@ -97,7 +94,7 @@ async def package_python_binary(
97
94
SourceRootRequest ,
98
95
SourceRootRequest .for_file (entry_point_path ),
99
96
)
100
- entry_point = PythonBinarySources .translate_source_file_to_entry_point (
97
+ entry_point = PexBinarySources .translate_source_file_to_entry_point (
101
98
os .path .relpath (entry_point_path , source_root .path )
102
99
)
103
100
@@ -115,22 +112,22 @@ async def package_python_binary(
115
112
entry_point = entry_point ,
116
113
platforms = PexPlatforms .create_from_platforms_field (field_set .platforms ),
117
114
output_filename = output_filename ,
118
- additional_args = field_set .generate_additional_args (python_binary_defaults ),
115
+ additional_args = field_set .generate_additional_args (pex_binary_defaults ),
119
116
)
120
117
),
121
118
)
122
119
return BuiltPackage (two_step_pex .pex .digest , (BuiltPackageArtifact (output_filename ),))
123
120
124
121
125
122
@rule (level = LogLevel .DEBUG )
126
- async def create_python_binary (field_set : PythonBinaryFieldSet ) -> CreatedBinary :
123
+ async def create_pex_binary (field_set : PexBinaryFieldSet ) -> CreatedBinary :
127
124
pex = await Get (BuiltPackage , PackageFieldSet , field_set )
128
125
return CreatedBinary (pex .digest , cast (str , pex .artifacts [0 ].relpath ))
129
126
130
127
131
128
def rules ():
132
129
return [
133
130
* collect_rules (),
134
- UnionRule (PackageFieldSet , PythonBinaryFieldSet ),
135
- UnionRule (BinaryFieldSet , PythonBinaryFieldSet ),
131
+ UnionRule (PackageFieldSet , PexBinaryFieldSet ),
132
+ UnionRule (BinaryFieldSet , PexBinaryFieldSet ),
136
133
]
0 commit comments