Skip to content

PythonPackageNameCheck: fix TypeError on empty PyPi remote#776

Open
falbrechtskirchinger wants to merge 1 commit intopkgcore:masterfrom
falbrechtskirchinger:fix-typeerror
Open

PythonPackageNameCheck: fix TypeError on empty PyPi remote#776
falbrechtskirchinger wants to merge 1 commit intopkgcore:masterfrom
falbrechtskirchinger:fix-typeerror

Conversation

@falbrechtskirchinger
Copy link
Copy Markdown

@falbrechtskirchinger falbrechtskirchinger commented Mar 28, 2026

Skip check when the PyPI remote-id in metadata.xml is empty and add a test package.

Addresses the following crash observed with a template metadata.xml (<remote-id type="pypi"></remote-id>):

$ pkgcheck scan .
pkgcheck scan: error: Traceback (most recent call last):
  File "/usr/lib/python3.14/site-packages/pkgcheck/pipeline.py", line 191, in _run_checks
    if results := sorted(
                  ~~~~~~^
        chain.from_iterable(pipes[i][-1][scope][j].run(restrict) for j in runners)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/usr/lib/python3.14/site-packages/pkgcheck/runners.py", line 71, in run
    yield from check.feed(item)
  File "/usr/lib/python3.14/site-packages/pkgcheck/checks/python.py", line 1114, in feed
    if pkg.package != normalize(pypi_name):
                      ~~~~~~~~~^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/pkgcheck/checks/python.py", line 1111, in normalize
    return PROJECT_SYMBOL_NORMALIZE_RE.sub("-", project).lower()
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

Expected result:

PkgMetadataXmlEmptyElement: metadata.xml: empty element 'remote-id' on line 9

The test is primarily a regression test, for which I could find no precedent. python/dev-python/PythonMismatchedPackageName4 seems a bit out of place. Should I drop it, put it elsewhere, ...?

Skip check when the PyPI remote-id in metadata.xml is empty and add a
test package.

Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
@@ -1102,6 +1102,12 @@ def feed(self, pkgs):
if len(pypi_remotes) != 1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated- this should be a warning IMO so we can isolate how to handle this better. That situation shouldn't exist- if it does, it points at a bad metadata.xml definition, or something (again) we should address.

@ferringb
Copy link
Copy Markdown
Contributor

I think you're doing the inverse of what is needed- isn't this a malformed metadata.xml per glep68? the 'value'- name- is required. If they've specified a remote-id but left that out, it's malformed.

@falbrechtskirchinger
Copy link
Copy Markdown
Author

I think you're doing the inverse of what is needed- isn't this a malformed metadata.xml per glep68? the 'value'- name- is required. If they've specified a remote-id but left that out, it's malformed.

While I see your point regarding GLEP 68, my goal with this PR is just to stop pkgcheck from crashing outright.

The crash prevents PackageMetadataXmlCheck from catching the empty element. While PkgMetadataXmlEmptyElement may not fail CI, that is a separate problem that another PR can address.

@falbrechtskirchinger
Copy link
Copy Markdown
Author

Also:

def _check_remote_id(self, pkg, loc, doc):
for u in pkg.upstreams:
# empty values are already reported as PkgMetadataXmlEmptyElement
if not u.name:
continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants