mirror of
https://github.com/danieldemus/pyp2spec.git
synced 2026-07-27 21:00:37 +02:00
Exit script correctly on a non-existing package (fixes #30)
This commit is contained in:
committed by
Karolina Surma
parent
dce4344006
commit
238faa40d6
@@ -7,6 +7,9 @@
|
||||
to determine whether the license is allowed in Fedora. Data is provided by the [Fedora Legal team](https://gitlab.com/fedora/legal/fedora-license-data/)
|
||||
- tomllib library is used to read toml files from Python 3.11 on
|
||||
|
||||
### Fixed
|
||||
- pyp2spec quits when a package is not found on PyPI
|
||||
|
||||
|
||||
# [0.6.1] - 2022-08-01
|
||||
### Fixed
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from datetime import date
|
||||
from functools import wraps
|
||||
from subprocess import check_output
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -45,13 +44,12 @@ class PypiPackage:
|
||||
def get_package_metadata(self, *,session=None):
|
||||
pkg_index = f"https://pypi.org/pypi/{self.package_name}/json"
|
||||
s = session or requests.Session()
|
||||
try:
|
||||
response = s.get(pkg_index).json()
|
||||
except json.decoder.JSONDecodeError:
|
||||
response = s.get(pkg_index)
|
||||
if not response.ok:
|
||||
click.secho(f"'{self.package_name}' was not found on PyPI, did you spell it correctly?", fg="red")
|
||||
sys.exit(1)
|
||||
else:
|
||||
return response
|
||||
return response.json()
|
||||
|
||||
def python_name(self):
|
||||
if self.pypi_name.startswith("python"):
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"http_interactions": [{"request": {"body": {"encoding": "utf-8", "string": ""}, "headers": {"User-Agent": ["python-requests/2.28.1"], "Accept-Encoding": ["gzip, deflate"], "Accept": ["*/*"], "Connection": ["keep-alive"]}, "method": "GET", "uri": "https://pypi.org/pypi/definitely-nonexisting-package-name/json"}, "response": {"body": {"encoding": "utf-8", "string": "{\"message\": \"Not Found\"}"}, "headers": {"Connection": ["keep-alive"], "Content-Length": ["24"], "Content-Security-Policy": ["base-uri 'self'; block-all-mixed-content; connect-src 'self' https://api.github.com/repos/ https://api.github.com/search/issues https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com fastly-insights.com *.fastly-insights.com *.ethicalads.io https://api.pwnedpasswords.com https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/sre/mathmaps/ https://2p66nmmycsj3.statuspage.io; default-src 'none'; font-src 'self' fonts.gstatic.com; form-action 'self' https://checkout.stripe.com; frame-ancestors 'none'; frame-src https://www.youtube-nocookie.com; img-src 'self' https://warehouse-camo.ingress.cmh1.psfhosted.org/ https://*.google-analytics.com https://*.googletagmanager.com *.fastly-insights.com *.ethicalads.io; script-src 'self' https://*.googletagmanager.com https://www.google-analytics.com https://ssl.google-analytics.com *.fastly-insights.com *.ethicalads.io 'sha256-U3hKDidudIaxBDEzwGJApJgPEf2mWk6cfMWghrAa6i0=' https://cdn.jsdelivr.net/npm/mathjax@3.2.2/ 'sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII=' 'sha256-0POaN8stWYQxhzjKS+/eOfbbJ/u4YHO5ZagJvLpMypo=' https://www.youtube.com https://s.ytimg.com; style-src 'self' fonts.googleapis.com *.ethicalads.io 'sha256-2YHqZokjiizkHi1Zt+6ar0XJ0OeEy/egBnlm+MDMtrM=' 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' 'sha256-JLEjeN9e5dGsz5475WyRaoA4eQOdNPxDIeUhclnJDCE=' 'sha256-mQyxHEuwZJqpxCw3SLmc4YOySNKXunyu2Oiz1r3/wAE=' 'sha256-OCf+kv5Asiwp++8PIevKBYSgnNLNUZvxAp4a7wMLuKA=' 'sha256-h5LOiLhk6wiJrGsG5ItM0KimwzWQH/yAcmoJDJL//bY='; worker-src *.fastly-insights.com"], "Content-Type": ["application/json"], "Referrer-Policy": ["origin-when-cross-origin"], "Server": ["nginx/1.13.9"], "Accept-Ranges": ["bytes"], "Date": ["Mon, 06 Mar 2023 16:44:57 GMT"], "X-Served-By": ["cache-iad-kiad7000140-IAD, cache-vie6331-VIE"], "X-Cache": ["MISS, MISS"], "X-Cache-Hits": ["0, 0"], "X-Timer": ["S1678121098.760327,VS0,VE166"], "Vary": ["Accept-Encoding"], "Strict-Transport-Security": ["max-age=31536000; includeSubDomains; preload"], "X-Frame-Options": ["deny"], "X-XSS-Protection": ["1; mode=block"], "X-Content-Type-Options": ["nosniff"], "X-Permitted-Cross-Domain-Policies": ["none"]}, "status": {"code": 404, "message": "Not Found"}, "url": "https://pypi.org/pypi/definitely-nonexisting-package-name/json"}, "recorded_at": "2023-03-06T16:44:58"}], "recorded_with": "betamax/0.8.1"}
|
||||
@@ -18,6 +18,11 @@ def changelog():
|
||||
return ("Wed Nov 03 2021", "Packager", "packager@maint.com")
|
||||
|
||||
|
||||
def test_non_existent_package(betamax_session):
|
||||
with pytest.raises(SystemExit):
|
||||
PypiPackage("definitely-nonexisting-package-name", session=betamax_session)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("package, version",
|
||||
[
|
||||
("aionotion", "2.0.3"),
|
||||
|
||||
Reference in New Issue
Block a user