Fix update check

It should return assets for all platforms, since the repo tarball is
unsuitable for setuptools_scm. Preferred asset is the universal wheel.
This commit is contained in:
Tobias Gruetzmacher 2020-01-26 17:42:35 +01:00
parent 6e14e8709b
commit 66b89f4fed
3 changed files with 37 additions and 14 deletions

View file

@ -6,6 +6,9 @@ The format is based on
## [Unreleased]
### Fixed
- Update check now always shows assets instead of the repo tarball.
## [2.16] - 2020-01-12

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
# Copyright (C) 2012-2014 Bastian Kleineidam
# Copyright (C) 2015-2019 Tobias Gruetzmacher
# Copyright (C) 2015-2020 Tobias Gruetzmacher
from __future__ import absolute_import, division, print_function
@ -10,11 +10,15 @@ import os
from distutils.version import LooseVersion
import dosagelib
from dosagelib import configuration
from . import http
UPDATE_URL = "https://api.github.com/repos/webcomics/dosage/releases/latest"
UPDATE_URL = 'https://api.github.com/repos/webcomics/dosage/releases/latest'
EXTPRIO = {
'.exe': 1 if os.name == 'nt' else 9,
'.whl': 2,
'.gz': 3,
}
def check_update():
@ -38,20 +42,22 @@ def check_update():
return True, (version, None)
def asset_key(asset):
return EXTPRIO.get(os.path.splitext(asset['browser_download_url'])[1], 99)
def get_online_version():
"""Download update info and parse it."""
page = http.default_session.get(UPDATE_URL).json()
version = page.get('tag_name', None)
if os.name == 'nt':
try:
url = next((x['browser_download_url'] for x in page['assets'] if
x['content_type'] == 'application/x-msdos-program'),
configuration.Url)
except KeyError:
url = None
else:
url = page.get('tarball_url', None)
url = None
try:
assets = sorted(page['assets'], key=asset_key)
if len(assets) > 0:
url = assets[0]['browser_download_url']
except KeyError:
pass
return version, url

View file

@ -6,6 +6,7 @@
from __future__ import absolute_import, division, print_function
import json
import os
import re
import pytest
@ -46,19 +47,32 @@ class TestDosage(object):
@responses.activate
def test_update_available(self, capsys):
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),
json={'tag_name': '9999.0', 'tarball_url': 'NOWHERE'})
json={'tag_name': '9999.0', 'assets': [
{'browser_download_url': 'TEST.whl'},
{'browser_download_url': 'TEST.exe'},
]})
cmd_ok('--version', '-v')
captured = capsys.readouterr()
best = 'TEST.exe' if os.name == 'nt' else 'TEST.whl'
assert best in captured.out
assert 'A new version' in captured.out
@responses.activate
def test_no_update_available(self, capsys):
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),
json={'tag_name': '1.0', 'tarball_url': 'NOWHERE'})
json={'tag_name': '1.0'})
cmd_ok('--version', '-v')
captured = capsys.readouterr()
assert 'Detected local or development' in captured.out
@responses.activate
def test_current(self, capsys):
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),
json={'tag_name': dosagelib.__version__})
cmd_ok('--version', '-v')
captured = capsys.readouterr()
assert captured.out.endswith('issues\n')
@responses.activate
def test_update_broken(self, capsys):
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),