Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ def __init__(self) -> None:
super().__init__(
name="similar_project_analyzer",
heuristic=Heuristics.SIMILAR_PROJECTS,
depends_on=None,
depends_on=[
(Heuristics.EMPTY_PROJECT_LINK, HeuristicResult.FAIL),
(Heuristics.ONE_RELEASE, HeuristicResult.FAIL),
(Heuristics.HIGH_RELEASE_FREQUENCY, HeuristicResult.FAIL),
(Heuristics.UNCHANGED_RELEASE, HeuristicResult.FAIL),
(Heuristics.CLOSER_RELEASE_JOIN_DATE, HeuristicResult.FAIL),
(Heuristics.SUSPICIOUS_SETUP, HeuristicResult.FAIL),
(Heuristics.WHEEL_ABSENCE, HeuristicResult.FAIL),
(Heuristics.ANOMALOUS_VERSION, HeuristicResult.FAIL),
(Heuristics.TYPOSQUATTING_PRESENCE, HeuristicResult.FAIL),
(Heuristics.FAKE_EMAIL, HeuristicResult.FAIL),
],
)

def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicResult, dict[str, JsonType]]:
Expand Down Expand Up @@ -106,6 +117,9 @@ def get_structure(self, package_name: str) -> list[str]:
list[str]:
The list of files in the package's sdist.
"""
# TODO: We should not download the source distributions for every package.
# This is very inefficient. We should find a different way to extract the package
# structure, e.g., the inspector service?
sdist_url = self.get_url(package_name)
if not sdist_url:
logger.debug("Package %s does not have a sdist.", package_name)
Expand All @@ -117,10 +131,16 @@ def get_structure(self, package_name: str) -> list[str]:
return []

buffer = io.BytesIO(response.content)
with tarfile.open(fileobj=buffer, mode="r:gz") as tf:
members = [
member.name for member in tf.getmembers() if member.name and not member.name.startswith("PAXHeaders/")
]
try:
with tarfile.open(fileobj=buffer, mode="r:gz") as tf:
members = [
member.name
for member in tf.getmembers()
if member.name and not member.name.startswith("PAXHeaders/")
]
except (tarfile.TarError, OSError) as error:
logger.debug("Error reading source code tar file: %s", error)
return []

return members

Expand Down
Loading