diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2019-09-30 15:40:09 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2019-10-02 11:14:27 +0200 |
commit | 7b7a7293ecca6a81822a85119b19d3c47e6da0bc (patch) | |
tree | 02e125a18d93a738ab0d87ddac69d724044f5d92 | |
parent | 58b7e48c18e319209a08ad7452ec9f23bd9d5ff6 (diff) | |
download | dlp_check_version_PyPI-7b7a7293ecca6a81822a85119b19d3c47e6da0bc.tar.gz |
Make mypy happy
Fixes #7
-rwxr-xr-x | dlpcvp.py | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -13,7 +13,6 @@ from typing import Iterable, List, Optional, Tuple, Union from urllib.error import HTTPError from urllib.request import Request, urlopen - # PyPI API documentation https://warehouse.readthedocs.io/api-reference/ PyPI_base = "https://pypi.org/pypi/{}/json" # https://github.com/openSUSE/open-build-service/blob/master/docs/api/api/api.txt @@ -76,6 +75,10 @@ def suse_packages(proj: str) -> Iterable[str]: root = raw_xml_data.getroot() for elem in root.iter('entry'): pkg_name = elem.get('name') + # Invalid packages are skipped + if pkg_name is None: + log.warning(f"Package {elem} doesn’t have a name!") + continue # We don't want -doc subpackages if pkg_name.endswith('-doc'): continue @@ -167,6 +170,10 @@ def get_spec_name(req: Request, proj: str, pkg: str, etag: OStr = None) -> OStr: root = raw_xml_data.getroot() for elem in root.iter('entry'): name = elem.get('name') + # Invalid package + if name is None: + log.warning(f"Package {elem} doesn’t have a name!") + return None if name.endswith('.spec'): spec_files.append(name) if name == '_aggregate': @@ -194,10 +201,10 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> Optional[LooseVe For the given name of module return the latest version available on PyPI. """ # pkg, suse_name_etag, suse_spec_etag, pypi_etag - if con: - _, _, _, etag = get_etags(con, name) - else: + if con is None: etag = None + else: + _, _, _, etag = get_etags(con, name) req = Request(url=PyPI_base.format(name)) if etag is not None: @@ -208,7 +215,7 @@ def get_version_from_pypi(name: str, con: DBConnType = None) -> Optional[LooseVe data = json.load(resp) info_dict = data['info'] curr_etag = str(resp.info()['ETag']) - if curr_etag: + if (con is not None) and curr_etag: update_etags(con, name, None, None, curr_etag) # Cleanup version @@ -255,7 +262,7 @@ def package_version(proj: str, pkgn: str, etag_spcf = None if not etag_spcf else etag_spcf spec_file_str = resp.read().decode() - if etag_spcf or etag_fn: + if (con is not None) and (etag_spcf or etag_fn): update_etags(con, pkgn, etag_fn, etag_spcf, None) return parse_spec(spec_file_str) except HTTPError as ex: |