Skip to content

Commit

Permalink
extract method to generate Lockfile using default lockfile resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lilatomic committed Mar 11, 2024
1 parent 4d0671f commit a8cddcf
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/python/pants/backend/python/subsystems/python_tool_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
*,
Expand All @@ -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:
Expand Down

0 comments on commit a8cddcf

Please sign in to comment.