From a8cddcf4a93a12db066e62ab6604e10fd07f50b7 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Wed, 21 Feb 2024 22:53:22 -0500 Subject: [PATCH] extract method to generate Lockfile using default lockfile resource --- .../python/subsystems/python_tool_base.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/python/pants/backend/python/subsystems/python_tool_base.py b/src/python/pants/backend/python/subsystems/python_tool_base.py index 51877a8efe8..1a54fe87a5e 100644 --- a/src/python/pants/backend/python/subsystems/python_tool_base.py +++ b/src/python/pants/backend/python/subsystems/python_tool_base.py @@ -141,6 +141,19 @@ def default_lockfile_url(cls) -> str: ) ) + @classmethod + def pex_requirements_for_default_lockfile(cls): + """Generate the pex requirements using this subsystem's default lockfile resource.""" + assert cls.default_lockfile_resource is not None + pkg, path = cls.default_lockfile_resource + url = f"resource://{pkg}/{path}" + origin = f"The built-in default lockfile for {cls.options_scope}" + return Lockfile( + url=url, + url_description_of_origin=origin, + resolve_name=cls.options_scope, + ) + def pex_requirements( self, *, @@ -155,17 +168,8 @@ def pex_requirements( from_superset=Resolve(self.install_from_resolve, use_entire_lockfile), description_of_origin=description_of_origin, ) - - assert self.default_lockfile_resource is not None - pkg, path = self.default_lockfile_resource - url = f"resource://{pkg}/{path}" - origin = f"The built-in default lockfile for {self.options_scope}" - lockfile = Lockfile( - url=url, - url_description_of_origin=origin, - resolve_name=self.options_scope, - ) - return EntireLockfile(lockfile) + else: + return EntireLockfile(self.pex_requirements_for_default_lockfile()) @property def interpreter_constraints(self) -> InterpreterConstraints: