From e5c63a388c16895f460521b759351cef6a0dd73b Mon Sep 17 00:00:00 2001 From: Daniel Demus Date: Tue, 15 Apr 2025 00:14:54 +0200 Subject: [PATCH] Ensure project_urls is not None when it's "project_urls": null in the json --- .gitignore | 3 ++- CHANGELOG.md | 4 ++++ pyp2spec/pyp2conf.py | 2 +- pyproject.toml | 2 +- tests/test_pyp2conf.py | 18 ++++++++++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1ac15be..2b5f5ab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ .pytest_cache/ *.spec *.conf -.tox/ \ No newline at end of file +.tox/ +pyp2spec.egg-info/ diff --git a/CHANGELOG.md b/CHANGELOG.md index b91a46e..f479539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# [0.12.2] - 2025-04-15 +### Fixed +- Also avoid crashing when you get a specifically None `project_urls` from the json + # [0.12.1] - 2025-04-07 ### Fixed - If no `project_urls` are present in the package data, try `project_url` and diff --git a/pyp2spec/pyp2conf.py b/pyp2spec/pyp2conf.py index cdb02af..c746753 100644 --- a/pyp2spec/pyp2conf.py +++ b/pyp2spec/pyp2conf.py @@ -45,7 +45,7 @@ def is_package_name(package: str) -> bool: def prepare_package_info(data: RawMetadata | dict) -> PackageInfo: - if not (project_urls := data.get("project_urls", {})): + if not (project_urls := data.get("project_urls") or {}): if (homepage := data.get("home_page", "")): project_urls["home_page"] = homepage if (not homepage and (homepage := data.get("project_url", ""))): diff --git a/pyproject.toml b/pyproject.toml index 42ee90a..5f6f73e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pyp2spec" -version = "0.12.1" +version = "0.12.2" description = "Generate a valid Fedora specfile from Python package from PyPI" readme = { file = "README.md", content-type = "text/markdown" } authors = [ diff --git a/tests/test_pyp2conf.py b/tests/test_pyp2conf.py index e00c175..a199430 100644 --- a/tests/test_pyp2conf.py +++ b/tests/test_pyp2conf.py @@ -357,6 +357,24 @@ def test_prepare_package_info_project_url_precedance(): assert result.url == "https://example1.com" +def test_prepare_package_info_project_url_precedance_with_nulls(): + data = { + "name": "foo", + "project_urls": None, + "project_url": None, + "home_page": None, + "package_url": "https://example1.com", + } + result = prepare_package_info(data) + assert result.pypi_name == "foo" + assert result.summary == "..." + assert result.license_files_present is False + assert result.license is None + assert result.extras == [] + assert result.pypi_version == "" + assert result.url == "https://example1.com" + + def test_gather_package_info_pypi_source(): pypi = {"info": { "name": "example",