From 7f6f92a2256fa3f606034af25aa4a1eabf1b1cb7 Mon Sep 17 00:00:00 2001 From: Wim Glenn Date: Thu, 26 Jan 2023 16:27:16 -0600 Subject: [PATCH] parse homepage from new project_urls metadata field --- johnnydep/__init__.py | 2 +- johnnydep/lib.py | 4 ++++ tests/test_lib.py | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/johnnydep/__init__.py b/johnnydep/__init__.py index b041af1..e3224c4 100644 --- a/johnnydep/__init__.py +++ b/johnnydep/__init__.py @@ -1,5 +1,5 @@ """Display dependency tree of Python distribution""" -__version__ = "1.17.4" +__version__ = "1.17.5" from johnnydep.lib import * diff --git a/johnnydep/lib.py b/johnnydep/lib.py index 08367b4..9470829 100644 --- a/johnnydep/lib.py +++ b/johnnydep/lib.py @@ -151,6 +151,10 @@ def children(self): @property def homepage(self): + for project_url in self.metadata.get("project_urls", []): + if project_url.lower().startswith("homepage, "): + _, url = project_url.split(", ", 1) + return url try: return self.metadata["home_page"] except KeyError: diff --git a/tests/test_lib.py b/tests/test_lib.py index 263b6c8..4c102eb 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -125,6 +125,12 @@ def test_homepage(make_dist): assert jdist.homepage == "https://www.example.org/default" +def test_homepage_from_project_urls(make_dist): + make_dist(project_url=["url1, https://blah", "homepage, https://www.example.org/proj_url"]) + jdist = JohnnyDist("jdtest") + assert jdist.homepage == "https://www.example.org/proj_url" + + def test_no_homepage(make_dist): make_dist(url=None) jdist = JohnnyDist("jdtest")