mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 04:43:09 +03:00
Python: fix update script
- use correct extension - do not update expressions that have an url that does not contain pypi - show warning in case request fails
This commit is contained in:
parent
66deb18463
commit
dce1c26e5d
@ -64,7 +64,7 @@ def _fetch_page(url):
|
|||||||
if r.status_code == requests.codes.ok:
|
if r.status_code == requests.codes.ok:
|
||||||
return r.json()
|
return r.json()
|
||||||
else:
|
else:
|
||||||
logging.warning("Request for {} failed".format(url))
|
raise ValueError("Request for {} failed".format(url))
|
||||||
|
|
||||||
def _get_latest_version(package, extension):
|
def _get_latest_version(package, extension):
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ def _get_latest_version(package, extension):
|
|||||||
url = "{}/{}/json".format(INDEX, package)
|
url = "{}/{}/json".format(INDEX, package)
|
||||||
json = _fetch_page(url)
|
json = _fetch_page(url)
|
||||||
|
|
||||||
data = extract_relevant_nix_data(json)[1]
|
data = extract_relevant_nix_data(json, extension)[1]
|
||||||
|
|
||||||
version = data['latest_version']
|
version = data['latest_version']
|
||||||
if version in data['versions']:
|
if version in data['versions']:
|
||||||
@ -83,7 +83,7 @@ def _get_latest_version(package, extension):
|
|||||||
return version, sha256
|
return version, sha256
|
||||||
|
|
||||||
|
|
||||||
def extract_relevant_nix_data(json):
|
def extract_relevant_nix_data(json, extension):
|
||||||
"""Extract relevant Nix data from the JSON of a package obtained from PyPI.
|
"""Extract relevant Nix data from the JSON of a package obtained from PyPI.
|
||||||
|
|
||||||
:param json: JSON obtained from PyPI
|
:param json: JSON obtained from PyPI
|
||||||
@ -124,11 +124,11 @@ def extract_relevant_nix_data(json):
|
|||||||
releases = toolz.itemfilter(lambda x: x[1] is not None, releases)
|
releases = toolz.itemfilter(lambda x: x[1] is not None, releases)
|
||||||
return releases
|
return releases
|
||||||
|
|
||||||
# Collect data
|
# Collect data)
|
||||||
name = str(json['info']['name'])
|
name = str(json['info']['name'])
|
||||||
latest_version = str(_extract_latest_version(json))
|
latest_version = str(_extract_latest_version(json))
|
||||||
#src = _get_src_and_hash(json, latest_version, EXTENSIONS)
|
#src = _get_src_and_hash(json, latest_version, EXTENSIONS)
|
||||||
sources = _get_sources(json, EXTENSIONS)
|
sources = _get_sources(json, [extension])
|
||||||
|
|
||||||
# Collect meta data
|
# Collect meta data
|
||||||
license = str(_extract_license(json))
|
license = str(_extract_license(json))
|
||||||
@ -188,7 +188,7 @@ def _update_package(path):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
# No format mentioned, then we assume we have setuptools
|
# No format mentioned, then we assume we have setuptools
|
||||||
# and use a .tar.gz
|
# and use a .tar.gz
|
||||||
logging.warning("Path {}: {}".format(path, str(e)))
|
logging.info("Path {}: {}".format(path, str(e)))
|
||||||
extension = ".tar.gz"
|
extension = ".tar.gz"
|
||||||
else:
|
else:
|
||||||
if format == 'wheel':
|
if format == 'wheel':
|
||||||
@ -197,17 +197,22 @@ def _update_package(path):
|
|||||||
try:
|
try:
|
||||||
url = _get_value('url', text)
|
url = _get_value('url', text)
|
||||||
extension = os.path.splitext(url)[1]
|
extension = os.path.splitext(url)[1]
|
||||||
|
if 'pypi' not in url:
|
||||||
|
logging.warning("Path {}: uses non-PyPI url, not updating.".format(path))
|
||||||
|
return False
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logging.warning("Path {}: {}".format(path, str(e)))
|
logging.info("Path {}: {}".format(path, str(e)))
|
||||||
extension = ".tar.gz"
|
extension = ".tar.gz"
|
||||||
|
|
||||||
|
try:
|
||||||
new_version, new_sha256 = _get_latest_version(pname, extension)
|
new_version, new_sha256 = _get_latest_version(pname, extension)
|
||||||
|
except ValueError as e:
|
||||||
|
logging.warning("Path {}: {}".format(path, str(e)))
|
||||||
|
else:
|
||||||
if not new_sha256:
|
if not new_sha256:
|
||||||
logging.warning("Path has no valid file available: {}".format(path))
|
logging.warning("Path has no valid file available: {}".format(path))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if new_version != version:
|
if new_version != version:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
text = _replace_value('version', new_version, text)
|
text = _replace_value('version', new_version, text)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user