Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Oct 21, 2023
1 parent 2a15ba8 commit 082b57b
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions mknodes/info/packageinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ def license_name(self) -> str | None:
"""Get name of the license."""
if license_name := self.metadata.get("License-Expression", "").strip():
return license_name
return next(
(
value.rsplit("::", 1)[1].strip()
for header, value in self.metadata.items()
if header == "Classifier" and value.startswith("License ::")
),
None,
)
if license_names := self.classifier_map.get("License"):
return license_names[0].split(" :: ")[-1]
return None

@functools.cached_property
def repository_url(self) -> str | None:
Expand All @@ -93,23 +88,20 @@ def keywords(self) -> list[str]:
return self.metadata.get("Keywords", "").split(",")

@functools.cached_property
def classifier_map(self) -> dict[str, list[str]]:
def classifier_map(self) -> collections.defaultdict[str, list[str]]:
"""Return a dict containing the classifier categories and values from metadata.
{category_1: [classifier_1, ...],
category_2, [classifier_x, ...],
...
}
"""
classifiers: dict[str, list[str]] = {}
classies: collections.defaultdict[str, list[str]] = collections.defaultdict(list)
for k, v in self.metadata.items():
if k == "Classifier":
category, value = v.split(" :: ", 1)
if category in classifiers:
classifiers[category].append(value)
else:
classifiers[category] = [value]
return classifiers
classies[category].append(value.strip())
return classies

@functools.cached_property
def required_package_names(self) -> list[str]:
Expand Down Expand Up @@ -146,9 +138,9 @@ def authors(self) -> dict[str, str]:
return authors

@functools.cached_property
def extras(self) -> dict[str, list[str]]:
def extras(self) -> collections.defaultdict[str, list[str]]:
"""Return a dict containing extras and the packages {extra: [package_1, ...]}."""
extras: collections.defaultdict = collections.defaultdict(list)
extras: collections.defaultdict[str, list[str]] = collections.defaultdict(list)
for dep in self._required_deps:
for extra in dep.extras:
extras[extra].append(dep.name)
Expand Down Expand Up @@ -211,4 +203,4 @@ def entry_points(self) -> dict[str, list[packagehelpers.EntryPoint]]:

if __name__ == "__main__":
info = PackageInfo("mknodes")
print(info.cli)
print(info.license_name)

0 comments on commit 082b57b

Please sign in to comment.