@@ -526,6 +526,20 @@ def add_create_lock_options(cls, create_parser):
526526 )
527527 ),
528528 )
529+ create_parser .add_argument (
530+ "--lock-build-systems" ,
531+ "--no-lock-build-systems" ,
532+ dest = "lock_build_systems" ,
533+ default = False ,
534+ action = HandleBoolAction ,
535+ type = bool ,
536+ help = (
537+ "When creating a lock that includes sdists, VCS requirements or local project "
538+ "directories that will later need to be built into wheels when using the lock, "
539+ "also lock the build system for each of these source tree artifacts to ensure "
540+ "consistent build environments at future times."
541+ ),
542+ )
529543 cls ._add_lock_options (create_parser )
530544 cls ._add_resolve_options (create_parser )
531545 cls .add_json_options (create_parser , entity = "lock" , include_switch = False )
@@ -802,6 +816,30 @@ def add_extra_arguments(
802816 ) as sync_parser :
803817 cls ._add_sync_arguments (sync_parser )
804818
819+ def _get_lock_configuration (self , target_configuration ):
820+ # type: (TargetConfiguration) -> Union[LockConfiguration, Error]
821+ if self .options .style is LockStyle .UNIVERSAL :
822+ return LockConfiguration (
823+ style = LockStyle .UNIVERSAL ,
824+ requires_python = tuple (
825+ str (interpreter_constraint .requires_python )
826+ for interpreter_constraint in target_configuration .interpreter_constraints
827+ ),
828+ target_systems = tuple (self .options .target_systems ),
829+ lock_build_systems = self .options .lock_build_systems ,
830+ )
831+
832+ if self .options .target_systems :
833+ return Error (
834+ "The --target-system option only applies to --style {universal} locks." .format (
835+ universal = LockStyle .UNIVERSAL .value
836+ )
837+ )
838+
839+ return LockConfiguration (
840+ style = self .options .style , lock_build_systems = self .options .lock_build_systems
841+ )
842+
805843 def _resolve_targets (
806844 self ,
807845 action , # type: str
@@ -891,24 +929,7 @@ def _create(self):
891929 target_configuration = target_options .configure (
892930 self .options , pip_configuration = pip_configuration
893931 )
894- if self .options .style == LockStyle .UNIVERSAL :
895- lock_configuration = LockConfiguration (
896- style = LockStyle .UNIVERSAL ,
897- requires_python = tuple (
898- str (interpreter_constraint .requires_python )
899- for interpreter_constraint in target_configuration .interpreter_constraints
900- ),
901- target_systems = tuple (self .options .target_systems ),
902- )
903- elif self .options .target_systems :
904- return Error (
905- "The --target-system option only applies to --style {universal} locks." .format (
906- universal = LockStyle .UNIVERSAL .value
907- )
908- )
909- else :
910- lock_configuration = LockConfiguration (style = self .options .style )
911-
932+ lock_configuration = try_ (self ._get_lock_configuration (target_configuration ))
912933 targets = try_ (
913934 self ._resolve_targets (
914935 action = "creating" ,
@@ -1454,8 +1475,8 @@ def process_req_edits(
14541475 lock_file = attr .evolve (
14551476 lock_file ,
14561477 pex_version = __version__ ,
1457- requirements = SortedTuple (requirements_by_project_name .values (), key = str ),
1458- constraints = SortedTuple (constraints_by_project_name .values (), key = str ),
1478+ requirements = SortedTuple (requirements_by_project_name .values ()),
1479+ constraints = SortedTuple (constraints_by_project_name .values ()),
14591480 locked_resolves = SortedTuple (
14601481 resolve_update .updated_resolve for resolve_update in lock_update .resolves
14611482 ),
@@ -1539,24 +1560,7 @@ def _sync(self):
15391560 target_configuration = target_options .configure (
15401561 self .options , pip_configuration = pip_configuration
15411562 )
1542- if self .options .style == LockStyle .UNIVERSAL :
1543- lock_configuration = LockConfiguration (
1544- style = LockStyle .UNIVERSAL ,
1545- requires_python = tuple (
1546- str (interpreter_constraint .requires_python )
1547- for interpreter_constraint in target_configuration .interpreter_constraints
1548- ),
1549- target_systems = tuple (self .options .target_systems ),
1550- )
1551- elif self .options .target_systems :
1552- return Error (
1553- "The --target-system option only applies to --style {universal} locks." .format (
1554- universal = LockStyle .UNIVERSAL .value
1555- )
1556- )
1557- else :
1558- lock_configuration = LockConfiguration (style = self .options .style )
1559-
1563+ lock_configuration = try_ (self ._get_lock_configuration (target_configuration ))
15601564 lock_file_path = self .options .lock
15611565 if os .path .exists (lock_file_path ):
15621566 build_configuration = pip_configuration .build_configuration
0 commit comments