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

Make it work in 2024 #34

Merged
merged 2 commits into from
Jan 6, 2025
Merged
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
19 changes: 13 additions & 6 deletions pypi2pkgbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import shutil
import site
import subprocess
from subprocess import CalledProcessError, PIPE
from subprocess import CalledProcessError, PIPE, DEVNULL
import sys
from tempfile import NamedTemporaryFile, TemporaryDirectory
import textwrap
Expand Down Expand Up @@ -339,6 +339,9 @@ def _run_shell_stdout(args, **kwargs):
def _get_readonly_clean_venv(): # "readonly" is an intent, but not enforced.
venv_dir = TemporaryDirectory()
_run_shell(["python", "-mvenv", venv_dir.name])
_run_shell([ # needed for version parsing
f"{venv_dir.name}/bin/pip", "install", "packaging"],
stdout=DEVNULL)
return venv_dir # Don't let venv_dir get GC'd.


Expand Down Expand Up @@ -667,7 +670,7 @@ def _get_info_pypi():
if not request["releases"]:
raise PackagingError(f"No suitable release found for {name}.")
src = ("from sys import argv; "
"from pkg_resources import parse_version as pv; ")
"from packaging.version import parse as pv; ")
src += (
"print(sorted(argv[1:], key=pv))" if pre else
"print(sorted([v for v in argv[1:] if not pv(v).is_prerelease],"
Expand Down Expand Up @@ -904,7 +907,11 @@ def write(self, options):

def _get_fullpath():
# This may be absolute and not in cwd (if PKGDEST is set).
return Path(_run_shell_stdout("makepkg --packagelist", cwd=cwd))
# --packagelist may output multiple lines when debug option is set.
# only take the first line (the main package).
return Path(_run_shell_stdout(
"makepkg --packagelist",
cwd=cwd).splitlines()[0])

fullpath = _get_fullpath()
# Update PKGBUILD.
Expand Down Expand Up @@ -1176,13 +1183,13 @@ def _find_license(self):
{**TROVE_COMMON_LICENSES,
**TROVE_SPECIAL_LICENSES}[license_class])
except KeyError:
licenses.append(f"custom:{license_class}")
licenses.append(f"LicenseRef-{license_class}")
# pypa/warehouse#3473: "UNKNOWN" -> "", but not for old pkgs.
elif info["license"] not in [None, "", "UNKNOWN"]:
licenses.append("custom:{}".format(info["license"]))
licenses.append("LicenseRef-{}".format(info["license"]))
else:
LOGGER.warning("No license information available.")
licenses.append("custom:unknown")
licenses.append("LicenseRef-unknown")

_license_found = False
if any(license not in TROVE_COMMON_LICENSES for license in licenses):
Expand Down
Loading