better-van-82973
05/09/2024, 9:31 PMclassmethod / classproperty? I know https://github.com/pantsbuild/pants/issues/19730 is ongoing, but I was trying to invoke an async rule inside a classproperty which doesn’t seem to happen anywhere else in the codebase.better-van-82973
05/09/2024, 10:10 PMhappy-kitchen-89482
05/09/2024, 10:11 PMhappy-kitchen-89482
05/09/2024, 10:12 PMhappy-kitchen-89482
05/09/2024, 10:12 PMhappy-kitchen-89482
05/09/2024, 10:12 PMbetter-van-82973
05/09/2024, 10:14 PMPythonToolRequirementsBase dynamically argument the subsystem’s help text by reading the lockfile.
So what I was planning to do is create a classmethod on `PythonToolRequirementsBase`called help_extended that contains the version read from the lockfile.broad-processor-92400
05/09/2024, 11:37 PMopen and manually parse "just enough" of the PEX json to extract the info required?broad-processor-92400
05/09/2024, 11:48 PMbetter-van-82973
05/09/2024, 11:48 PMbetter-van-82973
05/09/2024, 11:49 PMhappy-kitchen-89482
05/10/2024, 1:24 AMbetter-van-82973
05/10/2024, 1:26 AMparts = urlparse(lockfile.url)
# urlparse retains the leading / in URLs with a netloc.
lockfile_path = parts.path[1:] if parts.path.startswith("/") else parts.path
if parts.scheme in {"", "file"}:
synthetic_lock = False
lockfile_digest = await Get(
Digest,
PathGlobs(
[lockfile_path],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
description_of_origin=lockfile.url_description_of_origin,
),
)
_digest_contents = await Get(DigestContents, Digest, lockfile_digest)
lock_bytes = _digest_contents[0].content
elif parts.scheme == "resource":
synthetic_lock = True
_fc = FileContent(
lockfile_path,
# The "netloc" in our made-up "resource://" scheme is the package.
importlib.resources.read_binary(parts.netloc, lockfile_path),
)
lockfile_path, lock_bytes = (_fc.path, _fc.content)
lockfile_digest = await Get(Digest, CreateDigest([_fc]))
else:
raise ValueError(
f"Unsupported scheme {parts.scheme} for lockfile URL: {lockfile.url} "
f"(origin: {lockfile.url_description_of_origin})"
)
New code:
lockfile = cls.pex_requirements_for_default_lockfile()
parts = urlparse(lockfile.url)
# urlparse retains the leading / in URLs with a netloc.
lockfile_path = parts.path[1:] if parts.path.startswith("/") else parts.path
if parts.scheme in {"", "file"}:
with open(lockfile_path, "rb") as fp:
lock_bytes = fp.read()
elif parts.scheme == "resource":
_fc = FileContent(
lockfile_path,
# The "netloc" in our made-up "resource://" scheme is the package.
importlib.resources.read_binary(parts.netloc, lockfile_path),
)
lockfile_path, lock_bytes = (_fc.path, _fc.content)
else:
raise ValueError(
f"Unsupported scheme {parts.scheme} for lockfile URL: {lockfile.url} "
f"(origin: {lockfile.url_description_of_origin})"
)