Skip to content

Commit

Permalink
Fix version checking code
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritiusdadd committed Mar 19, 2024
1 parent eb03b3f commit d406df2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/redmost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

GITHUB_REPO_URL = "https://github.com/mauritiusdadd/redmost"
ONLINE_DOC_URL = "https://redmost.readthedocs.io/en/latest"
PYPI_REPO_PAGE = "https://pypi.org/project/redmost"
PYPI_REPO_API_URL = f"{PYPI_REPO_PAGE}/json"
PYPI_REPO_PAGE = "https://pypi.org/project/redmost/"
PYPI_REPO_API_URL = f"https://pypi.python.org/pypi/redmost/json"

LICENSE = """
BSD 3-Clause License
Expand Down
24 changes: 15 additions & 9 deletions src/redmost/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import os
from typing import Optional, Tuple, Union
import requests
from urllib import request
import json

import numpy as np
Expand All @@ -25,15 +25,21 @@

def check_updates() -> Tuple[bool, str]:
"""Check for new a version on pypi.python.org."""
req = requests.get(redmost.PYPI_REPO_API_URL)

req = request.Request(redmost.PYPI_REPO_API_URL, method='GET')
try:
with request.urlopen(req) as response:
response_data = response.read()
except Exception as exc:
return False, str(exc)

pypi_version = version.parse('0')
if req.status_code == requests.codes.ok:
j = json.loads(req.text.encode(req.encoding))
releases = j.get('releases', [])
for release in releases:
ver = version.parse(release)
if not ver.is_prerelease:
pypi_version = max(pypi_version, ver)
j = json.loads(response_data)
releases = j.get('releases', [])
for release in releases:
ver = version.parse(release)
if not ver.is_prerelease:
pypi_version = max(pypi_version, ver)

cur_ver_str = '.'.join([str(x) for x in redmost.version_tuple[:3]])
current_version = version.parse(cur_ver_str)
Expand Down

0 comments on commit d406df2

Please sign in to comment.