Commit df6d48e3 authored by Tomas Krizek's avatar Tomas Krizek
Browse files

Merge branch 'upstream-version' into 'master'

upstream-version: get latest version from PyPI

See merge request !42
parents 0f318d14 6d1c4817
Pipeline #80276 failed with stages
in 2 minutes and 39 seconds
......@@ -6,6 +6,6 @@ make_archive_script = "scripts/make-dev-archive.sh"
[upstream]
# needed for get-archive
archive_url = "https://gitlab.nic.cz/packaging/{{ project.name }}/-/archive/v{{ version }}/{{ project.name }}-v{{ version }}.tar.gz"
archive_url = "https://gitlab.nic.cz/packaging/{{ project.name }}/-/archive/v{{ version }}/{{ project.name }}-{{ version }}.tar.gz"
# script to check latest upstream version
version_script = "scripts/upstream-version.py"
#!/usr/bin/python3
"""
example script to get latest upstream version from HTML file listing
and print it to stdout
get latest upstream version from PyPI
Such custom script can be used by apkg to check for latest upstream version
This script can be used by apkg to check for latest upstream version
using upstream.version_script config option.
"""
from apkg.util import upstreamversion
from packaging.version import Version
import requests
url = 'https://secure.nic.cz/files/knot-resolver/'
v = upstreamversion.version_from_listing(url)
print(v)
def version_from_pypi(name):
url = 'https://pypi.org/pypi/%s/json' % name
r = requests.get(url)
if not r.ok:
return None
data = r.json()
versions = data['releases'].keys()
version = sorted(versions, key=Version)[-1]
return version
# apkg expects last stdout line to contain the upstream version string
print(version_from_pypi('apkg'))
......@@ -41,8 +41,8 @@ def test_apkg_make_archive(tmpdir, capsys):
assert re.match(r"pkg/archives/dev/apkg-.*\.tar\.gz", out)
def test_apkg_get_archive(tmpdir, capsys):
VERSION = '0.0.1'
def test_apkg_get_archive_manual(tmpdir, capsys):
VERSION = '0.0.2'
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
repo_dir = str(repo_path)
assert repo_dir.endswith('apkg')
......@@ -50,7 +50,17 @@ def test_apkg_get_archive(tmpdir, capsys):
assert apkg('get-archive', '--version', VERSION) == 0
out, _ = capsys.readouterr()
# first stdout line should be downloaded archive
assert out.startswith("pkg/archives/upstream/apkg-v%s.tar.gz" % VERSION)
assert out.startswith("pkg/archives/upstream/apkg-%s.tar.gz" % VERSION)
def test_apkg_get_archive_auto(tmpdir, capsys):
# this tests upstream version detection as well
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
with cd(repo_path):
assert apkg('get-archive') == 0
out, _ = capsys.readouterr()
# first stdout line should be downloaded archive
assert out.startswith("pkg/archives/upstream/apkg-")
def test_apkg_srcpkg(tmpdir, capsys):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment