diff options
author | Frederik Rietdijk <fridh@fridh.nl> | 2017-05-27 11:21:07 +0200 |
---|---|---|
committer | Frederik Rietdijk <fridh@fridh.nl> | 2017-05-27 11:29:42 +0200 |
commit | dce1c26e5d4bd25d21e1abc3397e02d6def044a8 (patch) | |
tree | 16974639f6d47c249689d8ba399902d4063c8130 /maintainers | |
parent | 66deb1846372690c30ae67bfa49cd88e9e0bc503 (diff) |
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
Diffstat (limited to 'maintainers')
-rwxr-xr-x | maintainers/scripts/update-python-libraries | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/maintainers/scripts/update-python-libraries b/maintainers/scripts/update-python-libraries index bb94b25ee16b..90f6c94233ac 100755 --- a/maintainers/scripts/update-python-libraries +++ b/maintainers/scripts/update-python-libraries @@ -64,7 +64,7 @@ def _fetch_page(url): if r.status_code == requests.codes.ok: return r.json() else: - logging.warning("Request for {} failed".format(url)) + raise ValueError("Request for {} failed".format(url)) def _get_latest_version(package, extension): @@ -72,7 +72,7 @@ def _get_latest_version(package, extension): url = "{}/{}/json".format(INDEX, package) json = _fetch_page(url) - data = extract_relevant_nix_data(json)[1] + data = extract_relevant_nix_data(json, extension)[1] version = data['latest_version'] if version in data['versions']: @@ -83,7 +83,7 @@ def _get_latest_version(package, extension): 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. :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) return releases - # Collect data + # Collect data) name = str(json['info']['name']) latest_version = str(_extract_latest_version(json)) #src = _get_src_and_hash(json, latest_version, EXTENSIONS) - sources = _get_sources(json, EXTENSIONS) + sources = _get_sources(json, [extension]) # Collect meta data license = str(_extract_license(json)) @@ -188,7 +188,7 @@ def _update_package(path): except ValueError as e: # No format mentioned, then we assume we have setuptools # and use a .tar.gz - logging.warning("Path {}: {}".format(path, str(e))) + logging.info("Path {}: {}".format(path, str(e))) extension = ".tar.gz" else: if format == 'wheel': @@ -197,33 +197,38 @@ def _update_package(path): try: url = _get_value('url', text) 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: - logging.warning("Path {}: {}".format(path, str(e))) + logging.info("Path {}: {}".format(path, str(e))) extension = ".tar.gz" - new_version, new_sha256 = _get_latest_version(pname, extension) - if not new_sha256: - logging.warning("Path has no valid file available: {}".format(path)) - return False - - if new_version != version: - - try: - text = _replace_value('version', new_version, text) - except ValueError as e: - logging.warning("Path {}: {}".format(path, str(e))) - try: - text = _replace_value('sha256', new_sha256, text) - except ValueError as e: - logging.warning("Path {}: {}".format(path, str(e))) + try: + 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: + logging.warning("Path has no valid file available: {}".format(path)) + return False + if new_version != version: + try: + text = _replace_value('version', new_version, text) + except ValueError as e: + logging.warning("Path {}: {}".format(path, str(e))) + try: + text = _replace_value('sha256', new_sha256, text) + except ValueError as e: + logging.warning("Path {}: {}".format(path, str(e))) - with open(path, 'w') as f: - f.write(text) + with open(path, 'w') as f: + f.write(text) - logging.info("Updated {} from {} to {}".format(pname, version, new_version)) + logging.info("Updated {} from {} to {}".format(pname, version, new_version)) - else: - logging.info("No update available for {} at {}".format(pname, version)) + else: + logging.info("No update available for {} at {}".format(pname, version)) return True |