Hello community, here is the log from the commit of package python-renderspec for openSUSE:Factory checked in at 2017-04-20 20:50:10 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-renderspec (Old) and /work/SRC/openSUSE:Factory/.python-renderspec.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-renderspec" Thu Apr 20 20:50:10 2017 rev:2 rq:485853 version:1.4.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-renderspec/python-renderspec.changes 2017-02-21 13:39:11.378750575 +0100 +++ /work/SRC/openSUSE:Factory/.python-renderspec.new/python-renderspec.changes 2017-04-20 20:50:14.625956221 +0200 @@ -1,0 +2,9 @@ +Wed Apr 5 14:52:52 UTC 2017 - [email protected] + +- update to version 1.4.0: + - Fix docs for child templates + - Introduce context variable 'pypi_name' + - Updated from global requirements + - Add dynamic version detection from archive files + +------------------------------------------------------------------- Old: ---- renderspec-1.3.0.tar.gz New: ---- renderspec-1.4.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-renderspec.spec ++++++ --- /var/tmp/diff_new_pack.ezYDqH/_old 2017-04-20 20:50:15.469836897 +0200 +++ /var/tmp/diff_new_pack.ezYDqH/_new 2017-04-20 20:50:15.469836897 +0200 @@ -18,12 +18,12 @@ %global sname renderspec Name: python-renderspec -Version: 1.3.0 +Version: 1.4.0 Release: 0 -Url: http://launchpad.net/%{sname} Summary: Generate spec files from Jinja2 templates License: Apache-2.0 Group: Development/Languages/Python +Url: http://launchpad.net/%{sname} Source0: https://pypi.io/packages/source/r/%{sname}/%{sname}-%{version}.tar.gz BuildRequires: openstack-macros BuildRequires: python-devel @@ -32,6 +32,7 @@ Requires: python-PyYAML >= 3.10.0 Requires: python-packaging >= 16.5 Requires: python-pymod2pkg >= 0.7.0 +Requires: python-six >= 1.9.0 BuildArch: noarch %description ++++++ renderspec-1.3.0.tar.gz -> renderspec-1.4.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/ChangeLog new/renderspec-1.4.0/ChangeLog --- old/renderspec-1.3.0/ChangeLog 2016-12-23 13:22:32.000000000 +0100 +++ new/renderspec-1.4.0/ChangeLog 2017-04-05 16:50:36.000000000 +0200 @@ -1,6 +1,16 @@ CHANGES ======= +1.4.0 +----- + +* Add dynamic version detection from archive files +* Fix docs for child templates +* Introduce context variable 'pypi_name' +* Updated from global requirements +* Updated from global requirements +* Updated from global requirements + 1.3.0 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/PKG-INFO new/renderspec-1.4.0/PKG-INFO --- old/renderspec-1.3.0/PKG-INFO 2016-12-23 13:22:33.000000000 +0100 +++ new/renderspec-1.4.0/PKG-INFO 2017-04-05 16:50:36.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: renderspec -Version: 1.3.0 +Version: 1.4.0 Summary: Jinja2 template renderer for generating .spec files Home-page: http://docs.openstack.org/developer/renderspec/ Author: OpenStack diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/doc/source/usage.rst new/renderspec-1.4.0/doc/source/usage.rst --- old/renderspec-1.3.0/doc/source/usage.rst 2016-12-23 13:20:41.000000000 +0100 +++ new/renderspec-1.4.0/doc/source/usage.rst 2017-04-05 16:48:18.000000000 +0200 @@ -85,7 +85,7 @@ To support both styles with renderspec, the upstream version and a release must be available in the context:: - {% set upstream_version = '1.2.3.0rc1' %} + {% set upstream_version = upstream_version('1.2.3.0rc1') %} {% set rpm_release = '1' %} This should be done on the first lines in the spec.j2 template. The `rpm_release` is @@ -108,7 +108,7 @@ Note that in case of pre-releases you may need to adjust the version that is used in the `Source` tag and the `%prep` sections `%setup`. So use e.g. :: - {% set upstream_version = '1.2.3.0rc1' %} + {% set upstream_version = upstream_version('1.2.3.0rc1') %} {% set rpm_release = '1' %} %name oslo.config Version: {{ py2rpmversion() }} @@ -126,6 +126,21 @@ %prep %setup -q -n %{sname}-1.2.3.0rc1 +The `upstream_version` can also be automatically detected from archive files +(like sdist archives available from pypi) which contain a valid `PKG-INFO`_ file. +For automatic version detection, the context need to know the `pypi_name` and a +archive file must be available and the context variable `upstream_version` needs to +be set to the value of the context function `upstream_version()`. The difference +here is that the version in `upstream_version()` is not explicit given:: + + {% set pypi_name = 'oslo.config' %} + {% set upstream_version = upstream_version() %} + {% set rpm_release = '1' %} + + Version: {{ py2rpmversion() }} + Release: {{ py2rpmrelease() }} + +.. _PKG-INFO: https://www.python.org/dev/peps/pep-0314/ Template features ================= @@ -135,21 +150,32 @@ some extra features renderspec adds to the template context. context function `py2name` -*********************** +************************** `py2name` is used to translate a given pypi name to a package name following the different distribution specific guidelines. .. note:: For translating pypi names (the name a python package has on `pypi.python.org`_ to distro specific names, internally a module called `pymod2pkg`_ is used. -For example, to define a package name and use the `py2name` context function, do:: +The prefered way to use `py2name` is to set the context variable `pypi_name` and +then call `py2name()` without any parameters. In that case, the context variable +is used:: - Name: {{ py2name('oslo.config') }} + {% set pypi_name = 'oslo.config' %} + Name: {{ py2name() }} Rendering this template :program:`renderspec` with the `suse` style would result in:: Name: python-oslo.config +It is also possible to pass the pypi name directly to the `py2name` context function:: + + Name: {{ py2name('oslo.config') }} + +That would create the same rendering result. +If the context env var `pypi_name` is set **and** `py2name` is called with a parameter, +the parameter is used instead of the context var. + context function `py2pkg` ************************* @@ -215,6 +241,27 @@ License: Apache-2.0 +context function `upstream_version` +*********************************** +This function can be used to assign a static version to the variable `upstream_version` +or to dynamically detect the version from a archive (eg. an sdist tarball). +Static assignment looks like:: + + {% set upstream_version = upstream_version('1.1.0a3') %} + +which is basically the same as:: + + {% set upstream_version = '1.1.0a3' %} + +So static assignment is not that useful. Dynamic assignment looks like:: + + {% set pypi_name = 'oslo.config' %} + {% set upstream_version = upstream_version() %} + +Note that for dynamic version detection, the variable `pypi_name` needs to be set +before calling `upstream_version()`. + + context function `py2rpmversion` ******************************** Python has a semantic version schema (see `PEP0440`_) and converting Python versions @@ -264,18 +311,18 @@ automatically used with corresponding `--spec-style`. These allow different output for each spec style (distro) using jinja `{% block %}` syntax. -For example consider simple `renderspec/dist-templates/fedora.spec.j2`: +For example consider simple `renderspec/dist-templates/fedora.spec.j2`:: {% extends ".spec" %} {% block build_requires %} BuildRequires: {{ py2pkg('setuptools') }} {% endblock %} -allows following in a spec template: +allows following in a spec template:: {% block build_requires %}{% endblock %} -to render into +to render into:: BuildRequires: python-setuptools @@ -285,6 +332,40 @@ For more information, see current `renderspec/dist-templates` and usage in `openstack/rpm-packaging`_ project. +Available context variables +=========================== + +There are some variables that need to be set in the spec.j2 template. Preferable +at the beginning before any context function is used. + +pypi_name +********* + +This variable defines the name that is used on pypi. Set with:: + + {% set pypi_name = 'oslo.messaging' %} + +where 'oslo.messaging' is the name that is set. The variable can later be used:: + + Source: {{ pypi_name }}.tar.gz + +upstream_version +**************** + +The variable defines the upstream version that is used:: + + {% set upstream_version = '1.2.3.0rc1' %} + + +rpm_release +*********** +The variable defines the rpm release. It is used together with 'upstream_version' +and only needed with the fedora spec style:: + + {% set rpm_release = '1' %} + + + .. _Jinja2: http://jinja.pocoo.org/docs/dev/ .. _openstack/rpm-packaging: https://git.openstack.org/cgit/openstack/rpm-packaging/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/renderspec/__init__.py new/renderspec-1.4.0/renderspec/__init__.py --- old/renderspec-1.3.0/renderspec/__init__.py 2016-12-23 13:20:41.000000000 +0100 +++ new/renderspec-1.4.0/renderspec/__init__.py 2017-04-05 16:48:18.000000000 +0200 @@ -31,10 +31,12 @@ import yaml from renderspec.distloader import RenderspecLoader +from renderspec import utils from renderspec import versions # a variable that needs to be set for some functions in the context +CONTEXT_VAR_PYPI_NAME = "pypi_name" CONTEXT_VAR_UPSTREAM_VERSION = "upstream_version" CONTEXT_VAR_RPM_RELEASE = "rpm_release" @@ -46,6 +48,31 @@ " needed for '%s'" % (var_name, needed_by)) +def _context_upstream_version(context, pkg_version=None): + """return the version which should be set to the 'upstream_version' + variable in the jinja context""" + if pkg_version: + return pkg_version + else: + # try to auto-detect the version - for that we need the pypi name + _context_check_variable(context, CONTEXT_VAR_PYPI_NAME, + 'upstream_version') + pypi_name = context.vars[CONTEXT_VAR_PYPI_NAME] + # look for archives in the dir where the input template (.spec.j2) + # comes from. As fallback, also look in the current working dir + archives = utils._find_archives([context['input_template_dir'], '.'], + pypi_name) + for archive in archives: + with utils._extract_archive_to_tempdir(archive) as tmpdir: + pkg_info_file = utils._find_pkg_info(tmpdir) + if pkg_info_file: + return utils._get_version_from_pkg_info(pkg_info_file) + # unable to autodetect the version + raise TemplateRuntimeError("Can not autodetect 'upstream_version' from" + " the following archives: '%s'" % ( + ', '.join(archives))) + + def _context_py2rpmversion(context): """get a python PEP0440 compatible version and translate it to an RPM version""" @@ -102,7 +129,12 @@ return context['epochs'].get(pkg_name, 0) -def _context_py2name(context, pkg_name): +def _context_py2name(context, pkg_name=None): + if not pkg_name: + # if the name is not given, try to get the name from the context + _context_check_variable(context, CONTEXT_VAR_PYPI_NAME, + 'py2name') + pkg_name = context.vars[CONTEXT_VAR_PYPI_NAME] return pymod2pkg.module2package(pkg_name, context['spec_style']) @@ -182,6 +214,11 @@ @contextfunction +def _globals_upstream_version(context, pkg_version=None): + return _context_upstream_version(context, pkg_version) + + +@contextfunction def _globals_py2rpmversion(context): return _context_py2rpmversion(context) @@ -202,7 +239,7 @@ @contextfunction -def _globals_py2name(context, value): +def _globals_py2name(context, value=None): return _context_py2name(context, value) @@ -215,6 +252,7 @@ env.globals['py2name'] = _globals_py2name env.globals['epoch'] = _globals_epoch env.globals['license'] = _globals_license_spdx + env.globals['upstream_version'] = _globals_upstream_version def generate_spec(spec_style, epochs, requirements, input_template_path): @@ -230,8 +268,10 @@ if spec_style in env.loader.list_templates(): template_name = spec_style template = env.get_template(template_name) + input_template_dir = os.path.dirname(os.path.abspath(input_template_path)) return template.render(spec_style=spec_style, epochs=epochs, - requirements=requirements) + requirements=requirements, + input_template_dir=input_template_dir) def _is_fedora(distname): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/renderspec/utils.py new/renderspec-1.4.0/renderspec/utils.py --- old/renderspec-1.3.0/renderspec/utils.py 1970-01-01 01:00:00.000000000 +0100 +++ new/renderspec-1.4.0/renderspec/utils.py 2017-04-05 16:48:18.000000000 +0200 @@ -0,0 +1,79 @@ +#!/usr/bin/python +# Copyright (c) 2017 SUSE Linux GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +from contextlib import contextmanager +from email.parser import HeaderParser +import os +import shutil +import tarfile +import tempfile +import zipfile + +import six + + +@contextmanager +def _extract_archive_to_tempdir(archive_filename): + """extract the given tarball or zipfile to a tempdir. + Delete the tempdir at the end""" + if not os.path.exists(archive_filename): + raise Exception("Archive '%s' does not exist" % (archive_filename)) + + tempdir = tempfile.mkdtemp(prefix="renderspec_") + try: + if tarfile.is_tarfile(archive_filename): + with tarfile.open(archive_filename) as f: + f.extractall(tempdir) + elif zipfile.is_zipfile(archive_filename): + with zipfile.ZipFile(archive_filename) as f: + f.extractall(tempdir) + else: + raise Exception("Can not extract '%s'. " + "Not a tar or zip file" % archive_filename) + yield tempdir + finally: + shutil.rmtree(tempdir) + + +def _find_archives(directories, basename): + """return a list of archives in the given directories + or an empty list if no archive(s) can be found""" + if isinstance(directories, six.string_types): + directories = [directories] + + return [f for d in directories for f in os.listdir(d) + if f.startswith(basename) and + f.endswith(('tar.gz', 'zip', 'tar.bz2', 'xz'))] + + +def _find_pkg_info(directory): + """find and return the full path to a PKG-INFO file or None if not found""" + for root, dirs, files in os.walk(directory): + for filename in files: + if filename == 'PKG-INFO': + return os.path.join(root, filename) + # no PKG-INFO file found + return None + + +def _get_version_from_pkg_info(pkg_info_filename): + """get the version from a PKG-INFO (see pep-0314) file""" + with open(pkg_info_filename, 'r') as f: + parser = HeaderParser() + headers = parser.parse(f) + return headers.get('version') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/renderspec.egg-info/PKG-INFO new/renderspec-1.4.0/renderspec.egg-info/PKG-INFO --- old/renderspec-1.3.0/renderspec.egg-info/PKG-INFO 2016-12-23 13:22:32.000000000 +0100 +++ new/renderspec-1.4.0/renderspec.egg-info/PKG-INFO 2017-04-05 16:50:36.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: renderspec -Version: 1.3.0 +Version: 1.4.0 Summary: Jinja2 template renderer for generating .spec files Home-page: http://docs.openstack.org/developer/renderspec/ Author: OpenStack diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/renderspec.egg-info/SOURCES.txt new/renderspec-1.4.0/renderspec.egg-info/SOURCES.txt --- old/renderspec-1.3.0/renderspec.egg-info/SOURCES.txt 2016-12-23 13:22:33.000000000 +0100 +++ new/renderspec-1.4.0/renderspec.egg-info/SOURCES.txt 2017-04-05 16:50:36.000000000 +0200 @@ -15,6 +15,7 @@ doc/source/usage.rst renderspec/__init__.py renderspec/distloader.py +renderspec/utils.py renderspec/versions.py renderspec.egg-info/PKG-INFO renderspec.egg-info/SOURCES.txt diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/renderspec.egg-info/pbr.json new/renderspec-1.4.0/renderspec.egg-info/pbr.json --- old/renderspec-1.3.0/renderspec.egg-info/pbr.json 2016-12-23 13:22:32.000000000 +0100 +++ new/renderspec-1.4.0/renderspec.egg-info/pbr.json 2017-04-05 16:50:36.000000000 +0200 @@ -1 +1 @@ -{"is_release": true, "git_version": "32ebb11"} \ No newline at end of file +{"git_version": "ac48e74", "is_release": true} \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/renderspec.egg-info/requires.txt new/renderspec-1.4.0/renderspec.egg-info/requires.txt --- old/renderspec-1.3.0/renderspec.egg-info/requires.txt 2016-12-23 13:22:32.000000000 +0100 +++ new/renderspec-1.4.0/renderspec.egg-info/requires.txt 2017-04-05 16:50:36.000000000 +0200 @@ -1,7 +1,8 @@ -Jinja2>=2.8 +Jinja2!=2.9.0,!=2.9.1,!=2.9.2,!=2.9.3,!=2.9.4,>=2.8 pymod2pkg>=0.7.0 PyYAML>=3.10.0 packaging>=16.5 +six>=1.9.0 [bandit] bandit>=1.1.0 # Apache-2.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/requirements.txt new/renderspec-1.4.0/requirements.txt --- old/renderspec-1.3.0/requirements.txt 2016-12-23 13:20:41.000000000 +0100 +++ new/renderspec-1.4.0/requirements.txt 2017-04-05 16:48:18.000000000 +0200 @@ -1,7 +1,8 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -Jinja2>=2.8 # BSD License (3 clause) +Jinja2!=2.9.0,!=2.9.1,!=2.9.2,!=2.9.3,!=2.9.4,>=2.8 # BSD License (3 clause) pymod2pkg>=0.7.0 # Apache-2.0 PyYAML>=3.10.0 # MIT packaging>=16.5 # Apache-2.0 +six>=1.9.0 # MIT diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/setup.cfg new/renderspec-1.4.0/setup.cfg --- old/renderspec-1.3.0/setup.cfg 2016-12-23 13:22:33.000000000 +0100 +++ new/renderspec-1.4.0/setup.cfg 2017-04-05 16:50:36.000000000 +0200 @@ -50,5 +50,4 @@ [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/setup.py new/renderspec-1.4.0/setup.py --- old/renderspec-1.3.0/setup.py 2016-12-23 13:20:41.000000000 +0100 +++ new/renderspec-1.4.0/setup.py 2017-04-05 16:48:18.000000000 +0200 @@ -25,5 +25,5 @@ pass setuptools.setup( - setup_requires=['pbr>=1.8'], + setup_requires=['pbr>=2.0.0'], pbr=True) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/test-requirements.txt new/renderspec-1.4.0/test-requirements.txt --- old/renderspec-1.3.0/test-requirements.txt 2016-12-23 13:20:41.000000000 +0100 +++ new/renderspec-1.4.0/test-requirements.txt 2017-04-05 16:48:18.000000000 +0200 @@ -8,5 +8,5 @@ ddt>=1.0.1 # MIT mock>=2.0 # BSD -sphinx!=1.3b1,<1.4,>=1.2.1 # BSD +sphinx>=1.5.1 # BSD oslosphinx>=4.7.0 # Apache-2.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/renderspec-1.3.0/tests.py new/renderspec-1.4.0/tests.py --- old/renderspec-1.3.0/tests.py 2016-12-23 13:20:41.000000000 +0100 +++ new/renderspec-1.4.0/tests.py 2017-04-05 16:48:18.000000000 +0200 @@ -23,10 +23,12 @@ from ddt import data, ddt, unpack from jinja2 import Environment +from jinja2.exceptions import TemplateRuntimeError from mock import Mock, patch import os import renderspec +import renderspec.utils import renderspec.versions import shutil import tempfile @@ -102,6 +104,12 @@ {'spec_style': 'suse', 'epochs': {'oslo.config': 4}, 'requirements': {}}, 'oslo.config'), 4) + def test_context_upstream_version(self): + context = {'spec_style': 'suse', 'epochs': {}, + 'requirements': {}} + self.assertEqual(renderspec._context_upstream_version( + context, '1.2.0'), '1.2.0') + @ddt class RenderspecTemplateFunctionTests(unittest.TestCase): @@ -176,6 +184,14 @@ 'requirements': {'requests': '1.4.0'}}, "{{ py2name('requests') }}", "python-requests"), + # with pypi_name context var + ({'spec_style': 'suse', 'epochs': {}, 'requirements': {}}, + "{% set pypi_name = 'oslo.messaging' %}{{ py2name() }}", + "python-oslo.messaging"), + # with pypi_name context var and explicit parameter + ({'spec_style': 'suse', 'epochs': {}, 'requirements': {}}, + "{% set pypi_name = 'oslo.messaging' %}{{ py2name('requests') }}", + "python-requests"), ) @unpack def test_render_func_py2name(self, context, string, expected_result): @@ -185,6 +201,16 @@ template.render(**context), expected_result) + def test_render_func_py2name_raise(self): + """py2name() called without parameter but no pypi_name context + variable set""" + template = self.env.from_string( + "{{ py2name() }}") + with self.assertRaises(TemplateRuntimeError): + template.render( + **{'spec_style': 'suse', 'epochs': {}, 'requirements': {}} + ) + @data( ('suse', '1.1.0', '1.1.0'), ('suse', '1.1.0.post2', '1.1.0.post2'), @@ -385,5 +411,87 @@ shutil.rmtree(tmpdir) +@ddt +class RenderspecUtilsTests(unittest.TestCase): + def _write_pkg_info(self, destdir, version='5.10.0'): + """write a PKG-INFO file into destdir""" + f1 = os.path.join(destdir, 'PKG-INFO') + with open(f1, 'w+') as f: + f.write('Metadata-Version: 1.1\n' + 'Name: oslo.messaging\n' + 'Version: %s' % (version)) + + def test__extract_archive_to_tempdir_no_file(self): + with self.assertRaises(Exception) as e_info: + with renderspec.utils._extract_archive_to_tempdir("foobar"): + self.assertIn("foobar", str(e_info)) + + def test__find_pkg_info(self): + tmpdir = tempfile.mkdtemp(prefix='renderspec-test_') + try: + self._write_pkg_info(tmpdir) + # we expect _find_pkg_info() to find the file in the tmpdir + self.assertEqual( + renderspec.utils._find_pkg_info(tmpdir), + os.path.join(tmpdir, 'PKG-INFO') + ) + finally: + shutil.rmtree(tmpdir) + + def test__find_pkg_info_not_found(self): + tmpdir = tempfile.mkdtemp(prefix='renderspec-test_') + try: + self.assertEqual( + renderspec.utils._find_pkg_info(tmpdir), + None + ) + finally: + shutil.rmtree(tmpdir) + + def _test__version_from_pkg_info(self): + tmpdir = tempfile.mkdtemp(prefix='renderspec-test_') + version = '5.10.0' + try: + self._write_pkg_info(tmpdir, version) + pkg_info_file = renderspec.utils._find_pkg_info(tmpdir), + self.assertEqual( + renderspec.utils._get_version_from_pkg_info(pkg_info_file), + version + ) + finally: + shutil.rmtree(tmpdir) + + @data( + (['foo-1.2.3.tar.gz'], 'foo', ['foo-1.2.3.tar.gz']), + (['foo-1.2.3.tar.gz', 'bar-1.2.3.xz'], 'foo', ['foo-1.2.3.tar.gz']), + (['foo-1.2.3.tar.gz'], 'bar', []), + ) + @unpack + def _test__find_archives(self, archives, pypi_name, expected): + tmpdir = tempfile.mkdtemp(prefix='renderspec-test_') + try: + for a in archives: + open(os.path.join(tmpdir, a), 'w').close() + self.assertEqual( + renderspec.utils._find_archives(tmpdir, pypi_name), + expected + ) + finally: + shutil.rmtree(tmpdir) + + def _test__find_archives_multiple_dirs(self): + tmpdir1 = tempfile.mkdtemp(prefix='renderspec-test_') + tmpdir2 = tempfile.mkdtemp(prefix='renderspec-test_') + try: + open(os.path.join(tmpdir2, 'foo-1.2.3.tar.xz'), 'w').close() + self.assertEqual( + renderspec.utils._find_archives([tmpdir1, tmpdir2], 'foo'), + ['foo-1.2.3.tar.xz'] + ) + finally: + shutil.rmtree(tmpdir1) + shutil.rmtree(tmpdir2) + + if __name__ == '__main__': unittest.main()
