Skip to content

Commit 92d2501

Browse files
fix: better logging and error handling added for when no pure wheel exists for the PURL
1 parent 2407510 commit 92d2501

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/macaron/build_spec_generator/common_spec/pypi_spec.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,32 @@ def resolve_fields(self, purl: PackageURL) -> None:
6464
if pypi_package_json.package_json or pypi_package_json.download(dest=""):
6565
requires_array: list[str] = []
6666
build_backends: dict[str, str] = {}
67-
with pypi_package_json.wheel():
68-
logger.debug("Wheel at %s", pypi_package_json.wheel_path)
69-
# Should only have .dist-info directory
70-
logger.debug("It has directories %s", ",".join(os.listdir(pypi_package_json.wheel_path)))
71-
# Make build-req array
72-
wheel_contents, metadata_contents = self.read_directory(pypi_package_json.wheel_path, purl)
73-
generator, version = self.read_generator_line(wheel_contents)
74-
if generator != "":
75-
build_backends[generator] = "==" + version
76-
if generator != "setuptools":
77-
# Apply METADATA heuristics to determine setuptools version
78-
if "License-File" in metadata_contents:
79-
build_backends["setuptools"] = "==" + defaults.get(
80-
"heuristic.pypi", "setuptools_version_emitting_license"
81-
)
82-
elif "Platform: UNKNOWN" in metadata_contents:
83-
build_backends["setuptools"] = "==" + defaults.get(
84-
"heuristic.pypi", "setuptools_version_emitting_platform_unknown"
85-
)
86-
else:
87-
build_backends["setuptools"] = "==" + defaults.get("heuristic.pypi", "default_setuptools")
67+
try:
68+
with pypi_package_json.wheel():
69+
logger.debug("Wheel at %s", pypi_package_json.wheel_path)
70+
# Should only have .dist-info directory
71+
logger.debug("It has directories %s", ",".join(os.listdir(pypi_package_json.wheel_path)))
72+
# Make build-req array
73+
wheel_contents, metadata_contents = self.read_directory(pypi_package_json.wheel_path, purl)
74+
generator, version = self.read_generator_line(wheel_contents)
75+
if generator != "":
76+
build_backends[generator] = "==" + version
77+
if generator != "setuptools":
78+
# Apply METADATA heuristics to determine setuptools version
79+
if "License-File" in metadata_contents:
80+
build_backends["setuptools"] = "==" + defaults.get(
81+
"heuristic.pypi", "setuptools_version_emitting_license"
82+
)
83+
elif "Platform: UNKNOWN" in metadata_contents:
84+
build_backends["setuptools"] = "==" + defaults.get(
85+
"heuristic.pypi", "setuptools_version_emitting_platform_unknown"
86+
)
87+
else:
88+
build_backends["setuptools"] = "==" + defaults.get(
89+
"heuristic.pypi", "default_setuptools"
90+
)
91+
except SourceCodeError:
92+
logger.debug("Could not find pure wheel matching this PURL")
8893

8994
logger.debug("From .dist_info:")
9095
logger.debug(build_backends)
@@ -99,9 +104,9 @@ def resolve_fields(self, purl: PackageURL) -> None:
99104
logger.debug("From pyproject.toml:")
100105
logger.debug(requires_array)
101106
except SourceCodeError:
102-
logger.debug("No pyproject.toml")
107+
logger.debug("No pyproject.toml found")
103108
except SourceCodeError:
104-
logger.debug("No pyproject.toml")
109+
logger.debug("No source distribution found")
105110

106111
# Merge in pyproject.toml information only when the wheel dist_info does not contain the same
107112
# Hatch is an interesting example of this merge being required.

0 commit comments

Comments
 (0)