Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Include PYPI_PN opportunities in PythonInlinePyPIURI #569

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
30 changes: 17 additions & 13 deletions src/pkgcheck/checks/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,22 +708,25 @@ def __init__(
replacement: typing.Optional[tuple[str, ...]] = None,
normalize: typing.Optional[bool] = None,
append: typing.Optional[bool] = None,
pypi_pn: typing.Optional[str] = None,
**kwargs,
) -> None:
super().__init__(**kwargs)
self.url = url
self.replacement = tuple(replacement) if replacement is not None else None
self.normalize = normalize
self.append = append
self.pypi_pn = pypi_pn

@property
def desc(self) -> str:
if self.replacement is None:
no_norm = "" if self.normalize else "set PYPI_NO_NORMALIZE=1, "
pypi_pn = "" if self.pypi_pn is None else f"set PYPI_PN={self.pypi_pn}, "
final = "use SRC_URI+= for other URIs" if self.append else "remove SRC_URI"
return (
"inline PyPI URI found matching pypi.eclass default, inherit the eclass, "
f"{no_norm}and {final} instead"
f"{no_norm}{pypi_pn}and {final} instead"
)
else:
return (
Expand Down Expand Up @@ -815,18 +818,19 @@ def check_pypi_mirror(self, pkg, fetchables):
if len(pypi_uris) == 1:
uri, filename = pypi_uris[0]

def matches_fn(expected_fn: str) -> bool:
expected = f"{PYPI_URI_PREFIX}source/{pkg.package[0]}/{pkg.package}/{expected_fn}"
return uri == expected and filename == expected_fn

version = self.translate_version(pkg.version)
append = len(uris) > 1
if matches_fn(f"{self.normalize_distribution_name(pkg.package)}-{version}.tar.gz"):
yield PythonInlinePyPIURI(uri, normalize=True, append=append, pkg=pkg)
return
if matches_fn(f"{pkg.package}-{version}.tar.gz"):
yield PythonInlinePyPIURI(uri, normalize=False, append=append, pkg=pkg)
return
if source_match := PYPI_SDIST_URI_RE.match(uri):
pn, filename_pn, pv, suffix = source_match.groups()
if pv == self.translate_version(pkg.version) and suffix == ".tar.gz":
append = len(uris) > 1
normalize = filename_pn == self.normalize_distribution_name(pn)
if not normalize and filename_pn != pn:
# ignore malformed URLs
return
pn, _ = self.simplify_pn_pv(pn, None, pkg, True)
yield PythonInlinePyPIURI(
uri, normalize=normalize, append=append, pypi_pn=pn, pkg=pkg
)
return

# otherwise, yield result for every URL, with suggested replacement
for uri, dist_filename in pypi_uris:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "0", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/PythonInlinePyPIURL-0.zip", "replacement": ["pypi_sdist_url", "--no-normalize", "\"${PN}\"", "\"${PV}\"", ".zip"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "1_alpha1", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/PythonInlinePyPIURL-1a1.tar.gz", "replacement": null, "normalize": false, "append": false}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "1_alpha1-r1", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/PythonInlinePyPIURL-1a1.tar.gz", "replacement": null, "normalize": false, "append": true}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "2_p4", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/pythoninlinepypiurl-2.post4.tar.gz", "replacement": null, "normalize": true, "append": false}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "2_p4-r1", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/pythoninlinepypiurl-2.post4.tar.gz", "replacement": null, "normalize": true, "append": true}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3", "url": "https://files.pythonhosted.org/packages/py3/p/pypi-url/pypi_url-3-py3-none-any.whl", "replacement": ["pypi_wheel_url", "--unpack", "pypi-url"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3", "url": "https://files.pythonhosted.org/packages/source/p/pypi-url/pypi-url-3.zip", "replacement": ["pypi_sdist_url", "--no-normalize", "pypi-url", "\"${PV}\"", ".zip"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3-r1", "url": "https://files.pythonhosted.org/packages/py3/p/pypi-url/pypi_url-3-py3-none-any.whl", "replacement": ["pypi_wheel_url", "pypi-url"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3-r1", "url": "https://files.pythonhosted.org/packages/source/p/pypi-url/pypi-url-3.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "pypi-url"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "4", "url": "https://files.pythonhosted.org/packages/cp310/P/PythonInlinePyPIURL/pythoninlinepypiurl-4-cp310-cp310-linux_x86_64.whl", "replacement": ["pypi_wheel_url", "\"${PN}\"", "\"${PV}\"", "cp310", "cp310-linux_x86_64"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "4", "url": "https://files.pythonhosted.org/packages/source/p/pypi-url/pypi_url-4.tar.gz", "replacement": ["pypi_sdist_url", "pypi-url"], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "0", "url": "https://files.pythonhosted.org/packages/source/p/python.inline-pypi-url/python.inline-pypi-url-0.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "\"${PN/-/.}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1", "url": "https://files.pythonhosted.org/packages/source/p/python.inline.pypi.url/python.inline.pypi.url-1.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "\"${PN//-/.}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "100", "url": "https://files.pythonhosted.org/packages/source/p/python_inline-pypi-url/python_inline-pypi-url-100.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "\"${PN/-/_}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "200", "url": "https://files.pythonhosted.org/packages/source/P/Python-inline-pypi-url/Python-inline-pypi-url-200.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "\"${PN^}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000", "url": "https://files.pythonhosted.org/packages/source/p/python.inline-pypi-url/python_inline_pypi_url-1000.tar.gz", "replacement": ["pypi_sdist_url", "\"${PN/-/.}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r1", "url": "https://files.pythonhosted.org/packages/source/p/python.inline.pypi.url/python_inline_pypi_url-1000.tar.gz", "replacement": ["pypi_sdist_url", "\"${PN//-/.}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r100", "url": "https://files.pythonhosted.org/packages/source/p/python_inline-pypi-url/python_inline_pypi_url-1000.tar.gz", "replacement": ["pypi_sdist_url", "\"${PN/-/_}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r101", "url": "https://files.pythonhosted.org/packages/source/p/python_inline_pypi_url/python_inline_pypi_url-1000.tar.gz", "replacement": ["pypi_sdist_url", "\"${PN//-/_}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r200", "url": "https://files.pythonhosted.org/packages/source/P/Python-inline-pypi-url/python_inline_pypi_url-1000.tar.gz", "replacement": ["pypi_sdist_url", "\"${PN^}\""], "normalize": null, "append": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "0", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/PythonInlinePyPIURL-0.zip", "replacement": ["pypi_sdist_url", "--no-normalize", "\"${PN}\"", "\"${PV}\"", ".zip"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "1_alpha1", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/PythonInlinePyPIURL-1a1.tar.gz", "replacement": null, "normalize": false, "append": false, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "1_alpha1-r1", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/PythonInlinePyPIURL-1a1.tar.gz", "replacement": null, "normalize": false, "append": true, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "2_p4", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/pythoninlinepypiurl-2.post4.tar.gz", "replacement": null, "normalize": true, "append": false, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "2_p4-r1", "url": "https://files.pythonhosted.org/packages/source/P/PythonInlinePyPIURL/pythoninlinepypiurl-2.post4.tar.gz", "replacement": null, "normalize": true, "append": true, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3", "url": "https://files.pythonhosted.org/packages/py3/p/pypi-url/pypi_url-3-py3-none-any.whl", "replacement": ["pypi_wheel_url", "--unpack", "pypi-url"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3", "url": "https://files.pythonhosted.org/packages/source/p/pypi-url/pypi-url-3.zip", "replacement": ["pypi_sdist_url", "--no-normalize", "pypi-url", "\"${PV}\"", ".zip"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3-r1", "url": "https://files.pythonhosted.org/packages/py3/p/pypi-url/pypi_url-3-py3-none-any.whl", "replacement": ["pypi_wheel_url", "pypi-url"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "3-r1", "url": "https://files.pythonhosted.org/packages/source/p/pypi-url/pypi-url-3.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "pypi-url"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "4", "url": "https://files.pythonhosted.org/packages/cp310/P/PythonInlinePyPIURL/pythoninlinepypiurl-4-cp310-cp310-linux_x86_64.whl", "replacement": ["pypi_wheel_url", "\"${PN}\"", "\"${PV}\"", "cp310", "cp310-linux_x86_64"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "PythonInlinePyPIURL", "version": "4", "url": "https://files.pythonhosted.org/packages/source/p/pypi-url/pypi_url-4.tar.gz", "replacement": ["pypi_sdist_url", "pypi-url"], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "0", "url": "https://files.pythonhosted.org/packages/source/p/python.inline-pypi-url/python.inline-pypi-url-0.tar.gz", "replacement": null, "normalize": false, "append": false, "pypi_pn": "\"${PN/-/.}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1", "url": "https://files.pythonhosted.org/packages/source/p/python.inline.pypi.url/python.inline.pypi.url-1.tar.gz", "replacement": null, "normalize": false, "append": false, "pypi_pn": "\"${PN//-/.}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "100", "url": "https://files.pythonhosted.org/packages/source/p/python_inline-pypi-url/python_inline-pypi-url-100.tar.gz", "replacement": null, "normalize": false, "append": false, "pypi_pn": "\"${PN/-/_}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "200", "url": "https://files.pythonhosted.org/packages/source/P/Python-inline-pypi-url/Python-inline-pypi-url-200.tar.gz", "replacement": null, "normalize": false, "append": false, "pypi_pn": "\"${PN^}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000", "url": "https://files.pythonhosted.org/packages/source/p/python.inline-pypi-url/python_inline_pypi_url-1000.tar.gz", "replacement": null, "normalize": true, "append": false, "pypi_pn": "\"${PN/-/.}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r1", "url": "https://files.pythonhosted.org/packages/source/p/python.inline.pypi.url/python_inline_pypi_url-1000.tar.gz", "replacement": null, "normalize": true, "append": false, "pypi_pn": "\"${PN//-/.}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r100", "url": "https://files.pythonhosted.org/packages/source/p/python_inline-pypi-url/python_inline_pypi_url-1000.tar.gz", "replacement": null, "normalize": true, "append": false, "pypi_pn": "\"${PN/-/_}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r101", "url": "https://files.pythonhosted.org/packages/source/p/python_inline_pypi_url/python_inline_pypi_url-1000.tar.gz", "replacement": null, "normalize": true, "append": false, "pypi_pn": "\"${PN//-/_}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "1000-r200", "url": "https://files.pythonhosted.org/packages/source/P/Python-inline-pypi-url/python_inline_pypi_url-1000.tar.gz", "replacement": null, "normalize": true, "append": false, "pypi_pn": "\"${PN^}\""}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "2000", "url": "https://files.pythonhosted.org/packages/source/p/python.inline-pypi-url/python_inline_pypi_url-2000.tar.gz", "replacement": ["pypi_sdist_url", "\"${PN/-/.}\""], "normalize": null, "append": null, "pypi_pn": null}
{"__class__": "PythonInlinePyPIURI", "category": "PythonFetchableCheck", "package": "python-inline-pypi-url", "version": "2000", "url": "https://files.pythonhosted.org/packages/source/p/python.inline-pypi-url_vectors/python.inline-pypi-url_vectors-151.tar.gz", "replacement": ["pypi_sdist_url", "--no-normalize", "python.inline-pypi-url_vectors", "151"], "normalize": null, "append": null, "pypi_pn": null}
Loading