Merge lp:~mvo/click/fix-multiple-framework-validation into lp:click/devel

Proposed by Michael Vogt
Status: Merged
Approved by: Michael Vogt
Approved revision: 548
Merged at revision: 562
Proposed branch: lp:~mvo/click/fix-multiple-framework-validation
Merge into: lp:click/devel
Diff against target: 90 lines (+22/-14)
2 files modified
click/framework.py (+19/-13)
click/tests/test_build.py (+3/-1)
To merge this branch: bzr merge lp:~mvo/click/fix-multiple-framework-validation
Reviewer Review Type Date Requested Status
Barry Warsaw Approve
Review via email: mp+244258@code.launchpad.net

Description of the change

This branch fixes a error when click encounters multiple frameworks
like "ubuntu-core-15.04-dev1, docker-1.3". The current check will
raise a error because it assumes all base-names are equal. This is
no longer the case in snappy and the new code checks base-name properly
now.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

Two minor observations, but otherwise LGTM.

review: Approve
548. By Michael Vogt

address review comments from barry

Revision history for this message
Michael Vogt (mvo) wrote :

Hi Barry,

thanks for your review!

On Tue, Feb 17, 2015 at 04:03:34PM -0000, Barry Warsaw wrote:
[..]
> Would it make sense to wrap this in `try/except ImportError` clauses? I know that gets a bit verbose, but at least you wouldn't have these commented out lines and could automatically use the native libs if available.

Thanks, I was thinking about this a little bit and I think this block
can just be removed. Its a goal of click build to run on pure
python. So we need the function anyway and can as well use them :)

[..]
> > + framework_base_name = click_framework_get_base_name(
> > + framework_name)
> > framework_base_version = click_framework_get_base_version(
> > framework_name)
> > - framework_base_versions.add(framework_base_version)
> > + if (framework_base_name in base_name_versions and
> > + framework_base_version != base_name_versions[framework_base_name]):
>
> What about (w/abbreviations due to wrapping):
>
> prev = base_name_versions.get(framework_base_name, framework_base_version)
> if framework_base_version != prev:
>
> I guess it may not save that much.

I like this idea! Commited.

Feel free to set to "approved" if you feel its ready.

Thanks,
 Michael

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click/framework.py'
--- click/framework.py 2014-06-23 21:14:06 +0000
+++ click/framework.py 2015-02-18 09:17:34 +0000
@@ -31,12 +31,6 @@
31 pass31 pass
3232
3333
34# FIXME: use native lib if available
35#from gi.repository import Click
36#click_framework_get_base_version = Click.framework_get_base_version
37#click_framework_has_framework = Click.has_framework
38
39
40# python version of the vala parse_deb822_file()34# python version of the vala parse_deb822_file()
41def parse_deb822_file(filename):35def parse_deb822_file(filename):
42 data = {}36 data = {}
@@ -76,6 +70,12 @@
76 return deb822.get("base-version", None)70 return deb822.get("base-version", None)
7771
7872
73# python version of the vala click_framework_get_base_version()
74def click_framework_get_base_name(framework_name):
75 deb822 = parse_deb822_file(get_framework_path(framework_name))
76 return deb822.get("base-name", None)
77
78
79# python version of the vala click_framework_has_framework79# python version of the vala click_framework_has_framework
80def click_framework_has_framework(framework_name):80def click_framework_has_framework(framework_name):
81 return os.path.exists(get_framework_path(framework_name))81 return os.path.exists(get_framework_path(framework_name))
@@ -94,7 +94,7 @@
94 raise ClickFrameworkInvalid(94 raise ClickFrameworkInvalid(
95 'Could not parse framework "%s"' % framework_string)95 'Could not parse framework "%s"' % framework_string)
9696
97 framework_base_versions = set()97 base_name_versions = {}
98 missing_frameworks = []98 missing_frameworks = []
99 for or_dep in parsed_framework:99 for or_dep in parsed_framework:
100 if len(or_dep) > 1:100 if len(or_dep) > 1:
@@ -110,9 +110,20 @@
110 if not click_framework_has_framework(framework_name):110 if not click_framework_has_framework(framework_name):
111 missing_frameworks.append(framework_name)111 missing_frameworks.append(framework_name)
112 continue112 continue
113 # ensure we do not use different base versions for the same base-name
114 framework_base_name = click_framework_get_base_name(
115 framework_name)
113 framework_base_version = click_framework_get_base_version(116 framework_base_version = click_framework_get_base_version(
114 framework_name)117 framework_name)
115 framework_base_versions.add(framework_base_version)118 prev = base_name_versions.get(framework_base_name, None)
119 if prev and prev != framework_base_version:
120 raise ClickFrameworkInvalid(
121 'Multiple frameworks with different base versions are not '
122 'allowed. Found: {} ({} != {})'.format(
123 framework_base_name,
124 framework_base_version,
125 base_name_versions[framework_base_name]))
126 base_name_versions[framework_base_name] = framework_base_version
116127
117 if not ignore_missing_frameworks:128 if not ignore_missing_frameworks:
118 if len(missing_frameworks) > 1:129 if len(missing_frameworks) > 1:
@@ -132,8 +143,3 @@
132 elif missing_frameworks:143 elif missing_frameworks:
133 logging.warning('Ignoring missing framework "%s"' % (144 logging.warning('Ignoring missing framework "%s"' % (
134 missing_frameworks[0]))145 missing_frameworks[0]))
135
136 if len(framework_base_versions) > 1:
137 raise ClickFrameworkInvalid(
138 'Multiple frameworks with different base versions are not '
139 'allowed. Found: {0}'.format(framework_base_versions))
140146
=== modified file 'click/tests/test_build.py'
--- click/tests/test_build.py 2015-01-19 10:26:26 +0000
+++ click/tests/test_build.py 2015-02-18 09:17:34 +0000
@@ -289,13 +289,15 @@
289 self.builder = ClickBuilder()289 self.builder = ClickBuilder()
290 for framework_name in ("ubuntu-sdk-13.10",290 for framework_name in ("ubuntu-sdk-13.10",
291 "ubuntu-sdk-14.04-papi",291 "ubuntu-sdk-14.04-papi",
292 "ubuntu-sdk-14.04-html"):292 "ubuntu-sdk-14.04-html",
293 "docker-sdk-1.3"):
293 self._create_mock_framework_file(framework_name)294 self._create_mock_framework_file(framework_name)
294295
295 def test_validate_framework_good(self):296 def test_validate_framework_good(self):
296 valid_framework_values = (297 valid_framework_values = (
297 "ubuntu-sdk-13.10",298 "ubuntu-sdk-13.10",
298 "ubuntu-sdk-14.04-papi, ubuntu-sdk-14.04-html",299 "ubuntu-sdk-14.04-papi, ubuntu-sdk-14.04-html",
300 "ubuntu-sdk-13.10, docker-sdk-1.3",
299 )301 )
300 for framework in valid_framework_values:302 for framework in valid_framework_values:
301 self.builder._validate_framework(framework)303 self.builder._validate_framework(framework)

Subscribers

People subscribed via source and target branches

to all changes: