Merge lp:~jcsackett/convoy/handle-commments into lp:convoy

Proposed by j.c.sackett
Status: Merged
Approved by: Fabrice Matrat
Approved revision: 34
Merged at revision: 33
Proposed branch: lp:~jcsackett/convoy/handle-commments
Merge into: lp:convoy
Diff against target: 53 lines (+23/-0)
2 files modified
convoy/meta.py (+4/-0)
convoy/tests/test_meta.py (+19/-0)
To merge this branch: bzr merge lp:~jcsackett/convoy/handle-commments
Reviewer Review Type Date Requested Status
Adam Collard (community) Needs Fixing
Francesco Banconi Approve
Fabrice Matrat (community) Approve
Review via email: mp+260469@code.launchpad.net

Commit message

Strip comments as part of extracting the metadata.

Description of the change

convoy's ability to extract modules as part of the metadata of a js file dies when the requires block has comments, b/c it doesn't end up with an object that can be converted to JSON.

With this branch, comments are removed from the string before attempting to load it.

To post a comment you must log in.
Revision history for this message
Fabrice Matrat (fabricematrat) wrote :

LGTM.

review: Approve
Revision history for this message
Francesco Banconi (frankban) wrote :

This branch looks good, thank you!

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'convoy/meta.py'
2--- convoy/meta.py 2012-01-27 03:37:59 +0000
3+++ convoy/meta.py 2015-05-28 11:59:22 +0000
4@@ -35,6 +35,7 @@
5
6 LITERAL_RE = re.compile("([\[ ]+)\"([\w\.\+-]+)\"([^:])")
7 NAME_RE = re.compile("[\.\+-]")
8+COMMENT_RE = re.compile("\/\/.*")
9
10
11 def extract_metadata(src):
12@@ -42,8 +43,11 @@
13 metadata = []
14 for entry in DETAILS_RE.finditer(src):
15 name, details, ignore = entry.groups()
16+ details = details.split('\n')
17+ details = '\n'.join([d for d in details if not d.startswith('//')])
18 details = details.replace('\'', '"')
19 details = DETAILS_FIND.sub(DETAILS_REPLACE, details)
20+ details = COMMENT_RE.sub('', details)
21 details = json.loads(details)
22 details["name"] = name
23 metadata.append(details)
24
25=== modified file 'convoy/tests/test_meta.py'
26--- convoy/tests/test_meta.py 2012-01-27 03:37:59 +0000
27+++ convoy/tests/test_meta.py 2015-05-28 11:59:22 +0000
28@@ -32,6 +32,25 @@
29
30 class ExtractMetadataTest(TestCase):
31
32+ def test_extract_with_comments(self):
33+ """
34+ Extracting the metadata of a file containing a single module
35+ should successfully extract it's requirements.
36+ """
37+ metadata = extract_metadata("""\
38+ YUI.add('lazr.base', function(Y){
39+ Y.log('Hello World');
40+ }, '0.1', {
41+ "requires": [
42+ // this is a comment
43+ "node", "base"
44+ ]
45+ });
46+ """)
47+ self.assertEquals(len(metadata), 1)
48+ self.assertEquals(metadata[0]["name"], "lazr.base")
49+ self.assertEquals(metadata[0]["requires"], ["node", "base"])
50+
51 def test_extract_single_module(self):
52 """
53 Extracting the metadata of a file containing a single module

Subscribers

People subscribed via source and target branches

to all changes: