76
76
from typing import IO , Dict , Iterable , List , Mapping , Optional , Set , Text , Tuple , Union
77
77
78
78
import attr # vendor:skip
79
+
80
+ from pex .resolve .lockfile .updater import Update
79
81
else :
80
82
from pex .third_party import attr
81
83
@@ -526,6 +528,20 @@ def add_create_lock_options(cls, create_parser):
526
528
)
527
529
),
528
530
)
531
+ create_parser .add_argument (
532
+ "--elide-unused-requires-dist" ,
533
+ "--no-elide-unused-requires-dist" ,
534
+ dest = "elide_unused_requires_dist" ,
535
+ type = bool ,
536
+ default = False ,
537
+ action = HandleBoolAction ,
538
+ help = (
539
+ "When creating the lock, elide dependencies from the 'requires_dists' lists that "
540
+ "can never be active due to markers. This does not change the reachable content of "
541
+ "the lock, but it does cut down on lock file size. This currently only elides "
542
+ "extras deps that are never activated, but may trim more in the future."
543
+ ),
544
+ )
529
545
cls ._add_lock_options (create_parser )
530
546
cls ._add_resolve_options (create_parser )
531
547
cls .add_json_options (create_parser , entity = "lock" , include_switch = False )
@@ -899,6 +915,7 @@ def _create(self):
899
915
for interpreter_constraint in target_configuration .interpreter_constraints
900
916
),
901
917
target_systems = tuple (self .options .target_systems ),
918
+ elide_unused_requires_dist = self .options .elide_unused_requires_dist ,
902
919
)
903
920
elif self .options .target_systems :
904
921
return Error (
@@ -907,7 +924,10 @@ def _create(self):
907
924
)
908
925
)
909
926
else :
910
- lock_configuration = LockConfiguration (style = self .options .style )
927
+ lock_configuration = LockConfiguration (
928
+ style = self .options .style ,
929
+ elide_unused_requires_dist = self .options .elide_unused_requires_dist ,
930
+ )
911
931
912
932
targets = try_ (
913
933
self ._resolve_targets (
@@ -1242,7 +1262,7 @@ def _process_lock_update(
1242
1262
dry_run = self .options .dry_run
1243
1263
path_mappings = self ._get_path_mappings ()
1244
1264
output = sys .stdout if dry_run is DryRunStyle .DISPLAY else sys .stderr
1245
- updates = [] # type: List[Union[DeleteUpdate, VersionUpdate, ArtifactsUpdate] ]
1265
+ updates = [] # type: List[Update ]
1246
1266
warnings = [] # type: List[str]
1247
1267
for resolve_update in lock_update .resolves :
1248
1268
platform = resolve_update .updated_resolve .target_platform
@@ -1317,7 +1337,7 @@ def _process_lock_update(
1317
1337
)
1318
1338
if update_req :
1319
1339
requirements_by_project_name [project_name ] = update_req
1320
- else :
1340
+ elif isinstance ( update , ArtifactsUpdate ) :
1321
1341
message_lines = [
1322
1342
" {lead_in} {project_name} {version} artifacts:" .format (
1323
1343
lead_in = "Would update" if dry_run else "Updated" ,
@@ -1351,8 +1371,25 @@ def _process_lock_update(
1351
1371
)
1352
1372
for artifact in update .removed
1353
1373
)
1354
-
1355
1374
print ("\n " .join (message_lines ), file = output )
1375
+ else :
1376
+ message_lines = [
1377
+ " {lead_in} {project_name} {version} requirements:" .format (
1378
+ lead_in = "Would update" if dry_run else "Updated" ,
1379
+ project_name = project_name ,
1380
+ version = update .version ,
1381
+ )
1382
+ ]
1383
+ if update .added :
1384
+ message_lines .extend (
1385
+ " + {added}" .format (added = req ) for req in update .added
1386
+ )
1387
+ if update .removed :
1388
+ message_lines .extend (
1389
+ " - {removed}" .format (removed = req ) for req in update .removed
1390
+ )
1391
+ print ("\n " .join (message_lines ), file = output )
1392
+
1356
1393
if fingerprint_updates :
1357
1394
warnings .append (
1358
1395
"Detected fingerprint changes in the following locked {projects} for lock "
@@ -1547,6 +1584,7 @@ def _sync(self):
1547
1584
for interpreter_constraint in target_configuration .interpreter_constraints
1548
1585
),
1549
1586
target_systems = tuple (self .options .target_systems ),
1587
+ elide_unused_requires_dist = self .options .elide_unused_requires_dist ,
1550
1588
)
1551
1589
elif self .options .target_systems :
1552
1590
return Error (
@@ -1555,7 +1593,10 @@ def _sync(self):
1555
1593
)
1556
1594
)
1557
1595
else :
1558
- lock_configuration = LockConfiguration (style = self .options .style )
1596
+ lock_configuration = LockConfiguration (
1597
+ style = self .options .style ,
1598
+ elide_unused_requires_dist = self .options .elide_unused_requires_dist ,
1599
+ )
1559
1600
1560
1601
lock_file_path = self .options .lock
1561
1602
if os .path .exists (lock_file_path ):
@@ -1566,6 +1607,7 @@ def _sync(self):
1566
1607
style = lock_configuration .style ,
1567
1608
requires_python = SortedTuple (lock_configuration .requires_python ),
1568
1609
target_systems = SortedTuple (lock_configuration .target_systems ),
1610
+ elide_unused_requires_dist = lock_configuration .elide_unused_requires_dist ,
1569
1611
pip_version = pip_configuration .version ,
1570
1612
resolver_version = pip_configuration .resolver_version ,
1571
1613
allow_prereleases = pip_configuration .allow_prereleases ,
0 commit comments