16
16
from pex .common import pluralize , safe_mkdtemp , safe_open
17
17
from pex .compatibility import shlex_quote
18
18
from pex .dist_metadata import NamedEntryPoint , parse_entry_point
19
+ from pex .enum import Enum
19
20
from pex .exceptions import production_assert
20
21
from pex .executables import chmod_plus_x
21
22
from pex .fetcher import URLFetcher
@@ -66,7 +67,7 @@ def qualified_binary_name(self, binary_name):
66
67
67
68
68
69
SCIENCE_RELEASES_URL = "https://github.com/a-scie/lift/releases"
69
- MIN_SCIENCE_VERSION = Version ("0.10 .1" )
70
+ MIN_SCIENCE_VERSION = Version ("0.12 .1" )
70
71
SCIENCE_REQUIREMENT = SpecifierSet ("~={min_version}" .format (min_version = MIN_SCIENCE_VERSION ))
71
72
72
73
@@ -80,43 +81,35 @@ def _science_binary_url(suffix=""):
80
81
)
81
82
82
83
83
- PTEX_VERSION = "1.5.0 "
84
- SCIE_JUMP_VERSION = "1.5.0 "
84
+ PTEX_VERSION = "1.5.1 "
85
+ SCIE_JUMP_VERSION = "1.6.1 "
85
86
86
87
87
- @attr .s (frozen = True )
88
- class Filename (object ):
89
- name = attr .ib () # type: str
88
+ class Filenames (Enum ["Filenames.Value" ]):
89
+ class Filename (Enum .Value ):
90
+ def __init__ (self , value ):
91
+ # type: (str) -> None
92
+ Enum .Value .__init__ (self , value )
93
+ self .name = value
90
94
91
- @property
92
- def placeholder (self ):
93
- # type: () -> str
94
- return "{{{name}}}" .format (name = self .name )
95
+ @property
96
+ def placeholder (self ):
97
+ # type: () -> str
98
+ return "{{{name}}}" .format (name = self .name )
95
99
100
+ PTEX = Filename ("ptex" )
101
+ PEX = Filename ("pex" )
102
+ CONFIGURE_BINDING = Filename ("configure-binding.py" )
96
103
97
- @attr .s (frozen = True )
98
- class Filenames (object ):
99
- @classmethod
100
- def avoid_collisions_with (cls , scie_name ):
101
- # type: (str) -> Filenames
102
- return cls (
103
- pex = Filename ("_pex" if scie_name == "pex" else "pex" ),
104
- configure_binding = Filename (
105
- "_configure-binding.py"
106
- if scie_name == "configure-binding.py"
107
- else "configure-binding.py"
108
- ),
109
- )
110
104
111
- pex = attr .ib () # type: Filename
112
- configure_binding = attr .ib () # type: Filename
105
+ Filenames .seal ()
113
106
114
107
115
108
def create_manifests (
116
109
configuration , # type: ScieConfiguration
117
110
name , # type: str
118
111
pex , # type: PEX
119
- filenames , # type: Filenames
112
+ use_platform_suffix = None , # type: Optional[bool]
120
113
):
121
114
# type: (...) -> Iterator[Manifest]
122
115
@@ -208,15 +201,27 @@ def create_cmd(named_entry_point):
208
201
"args" : ["{scie.bindings.configure:PEX}" ],
209
202
}
210
203
204
+ # Try to give the PEX the extracted filename expected by the user. This should work in almost
205
+ # all cases save for the Pex PEX.
206
+ pex_name = os .path .basename (pex .path ())
207
+ if pex_name not in frozenset (filename .value for filename in Filenames .values ()):
208
+ pex_key = Filenames .PEX .name # type: Optional[str]
209
+ else :
210
+ pex_name = Filenames .PEX .name
211
+ pex_key = None
212
+
211
213
lift = {
212
214
"name" : name ,
213
215
"ptex" : {
214
- "id" : "ptex" ,
216
+ "id" : Filenames . PTEX . name ,
215
217
"version" : PTEX_VERSION ,
216
218
"argv1" : "{scie.env.PEX_BOOTSTRAP_URLS={scie.lift}}" ,
217
219
},
218
220
"scie_jump" : {"version" : SCIE_JUMP_VERSION },
219
- "files" : [{"name" : filenames .configure_binding .name }, {"name" : filenames .pex .name }],
221
+ "files" : [
222
+ {"name" : Filenames .CONFIGURE_BINDING .name },
223
+ dict (name = pex_name , is_executable = True , ** ({"key" : pex_key } if pex_key else {})),
224
+ ],
220
225
} # type: Dict[str, Any]
221
226
222
227
configure_binding = {
@@ -235,7 +240,7 @@ def create_cmd(named_entry_point):
235
240
"exe" : "#{python-distribution:python}" ,
236
241
}
237
242
238
- configure_binding_args = [filenames . pex .placeholder , filenames . configure_binding .placeholder ]
243
+ configure_binding_args = [Filenames . PEX .placeholder , Filenames . CONFIGURE_BINDING .placeholder ]
239
244
for interpreter in configuration .interpreters :
240
245
manifest_path = os .path .join (
241
246
safe_mkdtemp (),
@@ -266,20 +271,24 @@ def create_cmd(named_entry_point):
266
271
else :
267
272
extra_configure_binding_args = ["--installed-pex-dir" ]
268
273
if pex .layout is Layout .LOOSE :
269
- extra_configure_binding_args .append (filenames . pex .placeholder )
274
+ extra_configure_binding_args .append (Filenames . PEX .placeholder )
270
275
else :
271
276
production_assert (pex_info .pex_hash is not None )
272
277
pex_hash = cast (str , pex_info .pex_hash )
273
278
extra_configure_binding_args .append (
274
279
UnzipDir .create (pex_hash , pex_root = pex_root ).path
275
280
)
276
281
282
+ if use_platform_suffix is True or (
283
+ use_platform_suffix is None and interpreter .platform is not SysPlatform .CURRENT
284
+ ):
285
+ lift ["platforms" ] = [interpreter .platform .value ]
286
+
277
287
with safe_open (manifest_path , "wb" ) as fp :
278
288
toml .dump (
279
289
{
280
290
"lift" : dict (
281
291
lift ,
282
- platforms = [interpreter .platform .value ],
283
292
interpreters = [interpreter_config ],
284
293
commands = list (create_commands (interpreter .platform )),
285
294
bindings = [
@@ -453,10 +462,8 @@ def build(
453
462
elif len (configuration .interpreters ) > 1 :
454
463
use_platform_suffix = True
455
464
456
- filenames = Filenames .avoid_collisions_with (name )
457
-
458
465
errors = OrderedDict () # type: OrderedDict[Manifest, str]
459
- for manifest in create_manifests (configuration , name , pex , filenames ):
466
+ for manifest in create_manifests (configuration , name , pex , use_platform_suffix ):
460
467
args = [science , "--cache-dir" , _science_dir (env , "cache" )]
461
468
if env .PEX_VERBOSE :
462
469
args .append ("-{verbosity}" .format (verbosity = "v" * env .PEX_VERBOSE ))
@@ -467,10 +474,10 @@ def build(
467
474
[
468
475
"lift" ,
469
476
"--file" ,
470
- "{name}={pex_file}" .format (name = filenames . pex .name , pex_file = pex_file ),
477
+ "{name}={pex_file}" .format (name = Filenames . PEX .name , pex_file = pex_file ),
471
478
"--file" ,
472
479
"{name}={configure_binding}" .format (
473
- name = filenames . configure_binding .name ,
480
+ name = Filenames . CONFIGURE_BINDING .name ,
474
481
configure_binding = os .path .join (
475
482
os .path .dirname (__file__ ), "configure-binding.py"
476
483
),
0 commit comments