Commit 6d1c4817 authored by Jakub Ružička's avatar Jakub Ružička
Browse files

upstream-version: get latest version from PyPI

Replace dummy scripts/upstream-version.py with actual code to get
latest apkg version from PyPI.

This enables upstream version detection and use of

    apkg get-archive

without `--version` parameter.

This also concludes integration of apkg with itself and after next PyPI release

    apkg build --upstream

should start working allowing fully upstream builds from archive only.
parent 0f318d14
Pipeline #80181 passed with stage
in 1 minute and 56 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