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
1=== modified file 'click/framework.py'
2--- click/framework.py 2014-06-23 21:14:06 +0000
3+++ click/framework.py 2015-02-18 09:17:34 +0000
4@@ -31,12 +31,6 @@
5 pass
6
7
8-# FIXME: use native lib if available
9-#from gi.repository import Click
10-#click_framework_get_base_version = Click.framework_get_base_version
11-#click_framework_has_framework = Click.has_framework
12-
13-
14 # python version of the vala parse_deb822_file()
15 def parse_deb822_file(filename):
16 data = {}
17@@ -76,6 +70,12 @@
18 return deb822.get("base-version", None)
19
20
21+# python version of the vala click_framework_get_base_version()
22+def click_framework_get_base_name(framework_name):
23+ deb822 = parse_deb822_file(get_framework_path(framework_name))
24+ return deb822.get("base-name", None)
25+
26+
27 # python version of the vala click_framework_has_framework
28 def click_framework_has_framework(framework_name):
29 return os.path.exists(get_framework_path(framework_name))
30@@ -94,7 +94,7 @@
31 raise ClickFrameworkInvalid(
32 'Could not parse framework "%s"' % framework_string)
33
34- framework_base_versions = set()
35+ base_name_versions = {}
36 missing_frameworks = []
37 for or_dep in parsed_framework:
38 if len(or_dep) > 1:
39@@ -110,9 +110,20 @@
40 if not click_framework_has_framework(framework_name):
41 missing_frameworks.append(framework_name)
42 continue
43+ # ensure we do not use different base versions for the same base-name
44+ framework_base_name = click_framework_get_base_name(
45+ framework_name)
46 framework_base_version = click_framework_get_base_version(
47 framework_name)
48- framework_base_versions.add(framework_base_version)
49+ prev = base_name_versions.get(framework_base_name, None)
50+ if prev and prev != framework_base_version:
51+ raise ClickFrameworkInvalid(
52+ 'Multiple frameworks with different base versions are not '
53+ 'allowed. Found: {} ({} != {})'.format(
54+ framework_base_name,
55+ framework_base_version,
56+ base_name_versions[framework_base_name]))
57+ base_name_versions[framework_base_name] = framework_base_version
58
59 if not ignore_missing_frameworks:
60 if len(missing_frameworks) > 1:
61@@ -132,8 +143,3 @@
62 elif missing_frameworks:
63 logging.warning('Ignoring missing framework "%s"' % (
64 missing_frameworks[0]))
65-
66- if len(framework_base_versions) > 1:
67- raise ClickFrameworkInvalid(
68- 'Multiple frameworks with different base versions are not '
69- 'allowed. Found: {0}'.format(framework_base_versions))
70
71=== modified file 'click/tests/test_build.py'
72--- click/tests/test_build.py 2015-01-19 10:26:26 +0000
73+++ click/tests/test_build.py 2015-02-18 09:17:34 +0000
74@@ -289,13 +289,15 @@
75 self.builder = ClickBuilder()
76 for framework_name in ("ubuntu-sdk-13.10",
77 "ubuntu-sdk-14.04-papi",
78- "ubuntu-sdk-14.04-html"):
79+ "ubuntu-sdk-14.04-html",
80+ "docker-sdk-1.3"):
81 self._create_mock_framework_file(framework_name)
82
83 def test_validate_framework_good(self):
84 valid_framework_values = (
85 "ubuntu-sdk-13.10",
86 "ubuntu-sdk-14.04-papi, ubuntu-sdk-14.04-html",
87+ "ubuntu-sdk-13.10, docker-sdk-1.3",
88 )
89 for framework in valid_framework_values:
90 self.builder._validate_framework(framework)

Subscribers

People subscribed via source and target branches

to all changes: