Hello community,

here is the log from the commit of package python-renderspec for 
openSUSE:Factory checked in at 2017-04-24 09:49:23
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-renderspec (Old)
 and      /work/SRC/openSUSE:Factory/.python-renderspec.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-renderspec"

Mon Apr 24 09:49:23 2017 rev:3 rq:489763 version:1.6.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-renderspec/python-renderspec.changes      
2017-04-20 20:50:14.625956221 +0200
+++ /work/SRC/openSUSE:Factory/.python-renderspec.new/python-renderspec.changes 
2017-04-24 09:49:23.946735555 +0200
@@ -1,0 +2,17 @@
+Fri Apr 21 09:14:13 UTC 2017 - cloud-de...@suse.de
+
+- update to version 1.6.0
+  - Return the full path when searching for archive files
+  - Add 'basename' filter
+
+-------------------------------------------------------------------
+Thu Apr 13 10:14:13 UTC 2017 - cloud-de...@suse.de
+
+- update to version 1.5.0:
+  - Look in 'output_dir' when searching archives
+  - Enable and fix more tests
+  - Updated from global requirements
+  - Make output dir available in the context
+  - Add new function fetch_source() to download files
+
+-------------------------------------------------------------------

Old:
----
  renderspec-1.4.0.tar.gz

New:
----
  renderspec-1.6.0.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-renderspec.spec ++++++
--- /var/tmp/diff_new_pack.F15Xxy/_old  2017-04-24 09:49:24.890602059 +0200
+++ /var/tmp/diff_new_pack.F15Xxy/_new  2017-04-24 09:49:24.894601494 +0200
@@ -18,7 +18,7 @@
 
 %global sname renderspec
 Name:           python-renderspec
-Version:        1.4.0
+Version:        1.6.0
 Release:        0
 Summary:        Generate spec files from Jinja2 templates
 License:        Apache-2.0

++++++ renderspec-1.4.0.tar.gz -> renderspec-1.6.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/ChangeLog 
new/renderspec-1.6.0/ChangeLog
--- old/renderspec-1.4.0/ChangeLog      2017-04-05 16:50:36.000000000 +0200
+++ new/renderspec-1.6.0/ChangeLog      2017-04-21 11:14:16.000000000 +0200
@@ -1,6 +1,21 @@
 CHANGES
 =======
 
+1.6.0
+-----
+
+* Add 'basename' filter
+* Return the full path when searching for archive files
+
+1.5.0
+-----
+
+* Look in 'output_dir' when searching archives
+* Enable and fix more tests
+* Add new function fetch_source() to download files
+* Make output dir available in the context
+* Updated from global requirements
+
 1.4.0
 -----
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/PKG-INFO 
new/renderspec-1.6.0/PKG-INFO
--- old/renderspec-1.4.0/PKG-INFO       2017-04-05 16:50:36.000000000 +0200
+++ new/renderspec-1.6.0/PKG-INFO       2017-04-21 11:14:16.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: renderspec
-Version: 1.4.0
+Version: 1.6.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.4.0/doc/source/usage.rst 
new/renderspec-1.6.0/doc/source/usage.rst
--- old/renderspec-1.4.0/doc/source/usage.rst   2017-04-05 16:48:18.000000000 
+0200
+++ new/renderspec-1.6.0/doc/source/usage.rst   2017-04-21 11:10:44.000000000 
+0200
@@ -131,14 +131,17 @@
 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::
+here is that the version in `upstream_version()` is not explicit given. The 
archive
+can be fetched with the `fetch_source()` function::
 
+  {% set source = 
fetch_source('http://tarballs.openstack.org/oslo.config/oslo.config-master.tar.gz')
 %}
   {% set pypi_name = 'oslo.config' %}
   {% set upstream_version = upstream_version() %}
   {% set rpm_release = '1' %}
 
   Version: {{ py2rpmversion() }}
   Release: {{ py2rpmrelease() }}
+  Source0: {{ source }}
 
 .. _PKG-INFO: https://www.python.org/dev/peps/pep-0314/
 
@@ -259,7 +262,12 @@
   {% set upstream_version = upstream_version() %}
 
 Note that for dynamic version detection, the variable `pypi_name` needs to be 
set
-before calling `upstream_version()`.
+before calling `upstream_version()`. `upstream_version()` tries to find an 
archive
+in:
+
+1. the output directory where the rendered .spec file ends
+2. the directory where the .spec.j2 template comes from
+3. the current working directory
 
 
 context function `py2rpmversion`
@@ -303,6 +311,30 @@
 to be able to use the `py2rpmrelease()` function.
 
 
+context function `fetch_source`
+*******************************
+The function `fetch_source` downloads the given url and puts the file into the
+`output_dir` (that's the directory where the rendered .spec file will be in).
+If `output_dir` is not available (that's the case when `renderspec` writes the
+rendered spec to stdout) the download is skipped. But in any case the function
+returns the same url that it got as parameter::
+
+  {% set source = 
fetch_source('http://tarballs.openstack.org/oslo.log/oslo.log-master.tar.gz') %}
+  Source0: {{ source }}
+
+
+context filter `basename`
+*************************
+This is a filter which just returns ```os.path.basename()```::
+
+  {% set source = 
fetch_source('http://tarballs.openstack.org/oslo.log/oslo.log-master.tar.gz') %}
+  Source0: {{ source|basename }}
+
+which then renders to::
+
+  Source0: oslo.log-master.tar.gz
+
+
 distribution specific blocks & child templates
 **********************************************
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/renderspec/__init__.py 
new/renderspec-1.6.0/renderspec/__init__.py
--- old/renderspec-1.4.0/renderspec/__init__.py 2017-04-05 16:48:18.000000000 
+0200
+++ new/renderspec-1.6.0/renderspec/__init__.py 2017-04-21 11:10:44.000000000 
+0200
@@ -48,6 +48,14 @@
                                    " needed for '%s'" % (var_name, needed_by))
 
 
+def _context_fetch_source(context, url):
+    """fetch the given url into the output_dir and return the url"""
+    if context['output_dir']:
+        filename = os.path.basename(url)
+        utils._download_file(url, context['output_dir'], filename)
+    return url
+
+
 def _context_upstream_version(context, pkg_version=None):
     """return the version which should be set to the 'upstream_version'
     variable in the jinja context"""
@@ -58,10 +66,14 @@
         _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)
+
+        # look for archives in:
+        # 1) the output_dir
+        # 2) the dir where the input template (.spec.j2) comes from
+        # 3) the current working dir
+        archives = utils._find_archives([context['output_dir'],
+                                         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)
@@ -205,6 +217,11 @@
     return _context_epoch(context, value)
 
 
+@contextfilter
+def _filter_basename(context, value):
+    return os.path.basename(value)
+
+
 ################
 # jinja2 globals
 ################
@@ -214,6 +231,11 @@
 
 
 @contextfunction
+def _globals_fetch_source(context, url):
+    return _context_fetch_source(context, url)
+
+
+@contextfunction
 def _globals_upstream_version(context, pkg_version=None):
     return _context_upstream_version(context, pkg_version)
 
@@ -246,6 +268,7 @@
 def _env_register_filters_and_globals(env):
     """register all the jinja2 filters we want in the environment"""
     env.filters['epoch'] = _filter_epoch
+    env.filters['basename'] = _filter_basename
     env.globals['py2rpmversion'] = _globals_py2rpmversion
     env.globals['py2rpmrelease'] = _globals_py2rpmrelease
     env.globals['py2pkg'] = _globals_py2pkg
@@ -253,9 +276,11 @@
     env.globals['epoch'] = _globals_epoch
     env.globals['license'] = _globals_license_spdx
     env.globals['upstream_version'] = _globals_upstream_version
+    env.globals['fetch_source'] = _globals_fetch_source
 
 
-def generate_spec(spec_style, epochs, requirements, input_template_path):
+def generate_spec(spec_style, epochs, requirements, input_template_path,
+                  output_path):
     """generate a spec file with the given style and the given template"""
 
     env = Environment(loader=RenderspecLoader(
@@ -269,9 +294,15 @@
         template_name = spec_style
     template = env.get_template(template_name)
     input_template_dir = os.path.dirname(os.path.abspath(input_template_path))
+    if output_path:
+        output_dir = os.path.dirname(
+            os.path.abspath(output_path))
+    else:
+        output_dir = None
     return template.render(spec_style=spec_style, epochs=epochs,
                            requirements=requirements,
-                           input_template_dir=input_template_dir)
+                           input_template_dir=input_template_dir,
+                           output_dir=output_dir)
 
 
 def _is_fedora(distname):
@@ -372,11 +403,17 @@
     except IOError as e:
         print(e)
         return 3
-    spec = generate_spec(args['spec_style'], epochs, requirements,
-                         input_template)
+
     if output_fn and output_fn != '-':
-        print("Rendering: %s -> %s" % (input_template, output_fn))
-        with open(output_fn, "w") as o:
+        output_path = os.path.abspath(output_fn)
+    else:
+        output_path = None
+
+    spec = generate_spec(args['spec_style'], epochs, requirements,
+                         input_template, output_path)
+    if output_path:
+        print("Rendering: %s -> %s" % (input_template, output_path))
+        with open(output_path, "w") as o:
             o.write(spec)
     else:
         print(spec)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/renderspec/utils.py 
new/renderspec-1.6.0/renderspec/utils.py
--- old/renderspec-1.4.0/renderspec/utils.py    2017-04-05 16:48:18.000000000 
+0200
+++ new/renderspec-1.6.0/renderspec/utils.py    2017-04-21 11:10:44.000000000 
+0200
@@ -16,6 +16,7 @@
 
 from __future__ import print_function
 
+from contextlib import closing
 from contextlib import contextmanager
 from email.parser import HeaderParser
 import os
@@ -25,6 +26,20 @@
 import zipfile
 
 import six
+from six.moves.urllib.request import urlopen
+
+
+def _download_file(url, dest_dir, dest_filename):
+    """download a given url to a given destination directory and
+    destination filenamee"""
+    filename = os.path.join(dest_dir, dest_filename)
+    with closing(urlopen(url)) as response:  # nosec
+        with open(filename, 'wb') as f:
+            while True:
+                buf = response.read(8192)
+                if not buf:
+                    break
+                f.write(buf)
 
 
 @contextmanager
@@ -56,7 +71,7 @@
     if isinstance(directories, six.string_types):
         directories = [directories]
 
-    return [f for d in directories for f in os.listdir(d)
+    return [os.path.join(d, f) for d in directories if d for f in os.listdir(d)
             if f.startswith(basename) and
             f.endswith(('tar.gz', 'zip', 'tar.bz2', 'xz'))]
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/renderspec.egg-info/PKG-INFO 
new/renderspec-1.6.0/renderspec.egg-info/PKG-INFO
--- old/renderspec-1.4.0/renderspec.egg-info/PKG-INFO   2017-04-05 
16:50:36.000000000 +0200
+++ new/renderspec-1.6.0/renderspec.egg-info/PKG-INFO   2017-04-21 
11:14:16.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: renderspec
-Version: 1.4.0
+Version: 1.6.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.4.0/renderspec.egg-info/pbr.json 
new/renderspec-1.6.0/renderspec.egg-info/pbr.json
--- old/renderspec-1.4.0/renderspec.egg-info/pbr.json   2017-04-05 
16:50:36.000000000 +0200
+++ new/renderspec-1.6.0/renderspec.egg-info/pbr.json   2017-04-21 
11:14:16.000000000 +0200
@@ -1 +1 @@
-{"git_version": "ac48e74", "is_release": true}
\ No newline at end of file
+{"git_version": "b0512f1", "is_release": true}
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/requirements.txt 
new/renderspec-1.6.0/requirements.txt
--- old/renderspec-1.4.0/requirements.txt       2017-04-05 16:48:18.000000000 
+0200
+++ new/renderspec-1.6.0/requirements.txt       2017-04-21 11:10:42.000000000 
+0200
@@ -5,4 +5,4 @@
 pymod2pkg>=0.7.0 # Apache-2.0
 PyYAML>=3.10.0 # MIT
 packaging>=16.5 # Apache-2.0
-six>=1.9.0  # MIT
+six>=1.9.0 # MIT
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/renderspec-1.4.0/tests.py 
new/renderspec-1.6.0/tests.py
--- old/renderspec-1.4.0/tests.py       2017-04-05 16:48:18.000000000 +0200
+++ new/renderspec-1.6.0/tests.py       2017-04-21 11:10:44.000000000 +0200
@@ -110,6 +110,23 @@
         self.assertEqual(renderspec._context_upstream_version(
                 context, '1.2.0'), '1.2.0')
 
+    @data(
+        # no output_dir -> download_files should not be called
+        (None, 0),
+        # output_dir defined -> download_files should be called once
+        ('.', 1)
+    )
+    @unpack
+    def test_context_fetch_source_no_output_dir(self, output_dir,
+                                                expected_calls):
+        context = {'spec_style': 'suse', 'epochs': {},
+                   'requirements': {}, 'output_dir': output_dir}
+        url = 'http://foo/bar'
+        with patch('renderspec.utils._download_file') as m:
+            self.assertEqual(renderspec._context_fetch_source(
+                context, url), url)
+            self.assertEqual(m.call_count, expected_calls)
+
 
 @ddt
 class RenderspecTemplateFunctionTests(unittest.TestCase):
@@ -118,6 +135,16 @@
         self.env = Environment()
         renderspec._env_register_filters_and_globals(self.env)
 
+    @data(
+        ("{{ 'http://foo/bar'|basename }}", "bar")
+    )
+    @unpack
+    def test_render_func_basename(self, input, expected):
+        template = self.env.from_string(input)
+        self.assertEqual(
+            template.render(spec_style='suse', epochs={}, requirements={}),
+            expected)
+
     def test_render_func_license_spdx(self):
         template = self.env.from_string(
             "{{ license('Apache-2.0') }}")
@@ -338,11 +365,11 @@
                            expected_result):
         tmpdir = tempfile.mkdtemp(prefix='renderspec-test_')
         try:
-            f1 = os.path.join(tmpdir, 'test.spec')
+            f1 = os.path.join(tmpdir, 'test.spec.j2')
             with open(f1, 'w+') as f:
                 f.write(template)
             rendered = renderspec.generate_spec(
-                style, epochs, requirements, f1)
+                style, epochs, requirements, f1, None)
             self.assertEqual(rendered, expected_result)
         finally:
             shutil.rmtree(tmpdir)
@@ -405,7 +432,8 @@
             # mock this to use testing dist-tempaltes folder
             mock_dt_path.return_value = dt_dir
 
-            out = renderspec.generate_spec('loldistro', {}, {}, base_path)
+            out = renderspec.generate_spec('loldistro', {}, {}, base_path,
+                                           None)
             self.assertEqual(out, expected_out)
         finally:
             shutil.rmtree(tmpdir)
@@ -448,12 +476,12 @@
         finally:
             shutil.rmtree(tmpdir)
 
-    def _test__version_from_pkg_info(self):
+    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),
+            pkg_info_file = renderspec.utils._find_pkg_info(tmpdir)
             self.assertEqual(
                 renderspec.utils._get_version_from_pkg_info(pkg_info_file),
                 version
@@ -467,8 +495,9 @@
         (['foo-1.2.3.tar.gz'], 'bar', []),
     )
     @unpack
-    def _test__find_archives(self, archives, pypi_name, expected):
+    def test__find_archives(self, archives, pypi_name, expected):
         tmpdir = tempfile.mkdtemp(prefix='renderspec-test_')
+        expected = [os.path.join(tmpdir, e) for e in expected]
         try:
             for a in archives:
                 open(os.path.join(tmpdir, a), 'w').close()
@@ -479,19 +508,23 @@
         finally:
             shutil.rmtree(tmpdir)
 
-    def _test__find_archives_multiple_dirs(self):
+    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']
+                renderspec.utils._find_archives([None, tmpdir1, tmpdir2],
+                                                'foo'),
+                [os.path.join(tmpdir2, 'foo-1.2.3.tar.xz')]
             )
         finally:
             shutil.rmtree(tmpdir1)
             shutil.rmtree(tmpdir2)
 
+    def test__find_archives_only_no_dir(self):
+        self.assertEqual(renderspec.utils._find_archives([None], 'foo'), [])
+
 
 if __name__ == '__main__':
     unittest.main()


Reply via email to