Merge lp:~clint-fewbar/charm-tools/flag-readme into lp:~charmers/charm-tools/trunk

Proposed by Clint Byrum
Status: Merged
Approved by: Marco Ceppi
Approved revision: 165
Merged at revision: 165
Proposed branch: lp:~clint-fewbar/charm-tools/flag-readme
Merge into: lp:~charmers/charm-tools/trunk
Diff against target: 102 lines (+34/-0)
6 files modified
scripts/proof (+23/-0)
tests/charms/mod-spdy/README (+3/-0)
tests/proof/expected/broken-maintainer (+2/-0)
tests/proof/expected/missing-maintainer (+2/-0)
tests/proof/expected/test (+2/-0)
tests/proof/expected/unknown-metadata (+2/-0)
To merge this branch: bzr merge lp:~clint-fewbar/charm-tools/flag-readme
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Marco Ceppi (community) Approve
Review via email: mp+129345@code.launchpad.net

Description of the change

Flag instances of the boilerplate lines of the README.ex in a README so that
if somebody just renames the file blindly we get an E:

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM!

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

This will throw an error if the readme contains the line "-----\n" say. Only checking non-trivial lines (20 chars or more for instance).

+ for l in [ x.strip() for x in tr]:
...
+ tr.seek(0)

Rather than iterating over the file multiple times and seeking back to the start, do it once and reuse this list. For instance:

    try:
        bad_lines = []
        with open(TEMPLATE_README) as tr:
            for line in tr:
                if len(line) > 20:
                    bad_lines.append(line.strip())
        for readme in found_readmes:
            ...
    except ...

review: Needs Fixing
166. By Clint Byrum

address case where short lines in the example README are common idioms

167. By Clint Byrum

Adding short lines from README.ex to test short line heuristic

Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Thanks Martin, I think I've addressed it with the last commit. Can you review again?

Revision history for this message
Martin Packman (gz) wrote :

+ tr.seek(0)

This is harmless but now redundant.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/proof'
2--- scripts/proof 2012-09-30 16:13:08 +0000
3+++ scripts/proof 2012-10-28 15:04:18 +0000
4@@ -47,6 +47,9 @@
5 KNOWN_SCOPES = [ 'global',
6 'container' ]
7
8+TEMPLATE_README = os.path.abspath(
9+ os.path.join(__file__, '..', '..', 'templates', 'charm', 'README.ex'))
10+
11 class RelationError(Exception):
12 pass
13
14@@ -212,6 +215,26 @@
15 if len(found_readmes):
16 if 'README.ex' in found_readmes:
17 err("Includes template README.ex file")
18+ try:
19+ with open(TEMPLATE_README) as tr:
20+ bad_lines = []
21+ for line in tr:
22+ if len(line) >= 20:
23+ bad_lines.append(line.strip())
24+ for readme in found_readmes:
25+ readme_path = os.path.join(charm_path, readme)
26+ with open(readme_path) as r:
27+ readme_content = r.read()
28+ lc = 0
29+ for l in bad_lines:
30+ if not len(l):
31+ continue
32+ lc += 1
33+ if l in readme_content:
34+ err("%s Includes boilerplate README.ex line %d" % (readme, lc))
35+ tr.seek(0)
36+ except IOError, e:
37+ err("Error while opening %s (%s)" % (e.filename, e.strerror))
38 else:
39 warn("no README file")
40
41
42=== modified file 'tests/charms/mod-spdy/README'
43--- tests/charms/mod-spdy/README 2012-04-23 20:46:55 +0000
44+++ tests/charms/mod-spdy/README 2012-10-28 15:04:18 +0000
45@@ -1,3 +1,6 @@
46+Configuration
47+-------------
48+
49 This will open port 443 on any machine with apache and enable mod_spdy.
50
51 juju deploy wrdpress
52
53=== modified file 'tests/proof/expected/broken-maintainer'
54--- tests/proof/expected/broken-maintainer 2012-09-30 16:07:25 +0000
55+++ tests/proof/expected/broken-maintainer 2012-10-28 15:04:18 +0000
56@@ -2,6 +2,8 @@
57 W: Maintainer address should contain a real-name and email only. [test@testhost]
58 E: no copyright file
59 E: Includes template README.ex file
60+E: README.ex Includes boilerplate README.ex line 1
61+E: README.ex Includes boilerplate README.ex line 2
62 E: template interface names should be changed: interface-name
63 E: template relations should be renamed to fit charm: relation-name
64 E: template interface names should be changed: interface-name
65
66=== modified file 'tests/proof/expected/missing-maintainer'
67--- tests/proof/expected/missing-maintainer 2012-09-30 16:07:25 +0000
68+++ tests/proof/expected/missing-maintainer 2012-10-28 15:04:18 +0000
69@@ -2,6 +2,8 @@
70 E: Charms need a maintainer (See RFC2822) - Name <email>
71 E: no copyright file
72 E: Includes template README.ex file
73+E: README.ex Includes boilerplate README.ex line 1
74+E: README.ex Includes boilerplate README.ex line 2
75 E: template interface names should be changed: interface-name
76 E: template relations should be renamed to fit charm: relation-name
77 E: template interface names should be changed: interface-name
78
79=== modified file 'tests/proof/expected/test'
80--- tests/proof/expected/test 2012-09-30 16:07:25 +0000
81+++ tests/proof/expected/test 2012-10-28 15:04:18 +0000
82@@ -1,5 +1,7 @@
83 E: no copyright file
84 E: Includes template README.ex file
85+E: README.ex Includes boilerplate README.ex line 1
86+E: README.ex Includes boilerplate README.ex line 2
87 E: template interface names should be changed: interface-name
88 E: template relations should be renamed to fit charm: relation-name
89 E: template interface names should be changed: interface-name
90
91=== modified file 'tests/proof/expected/unknown-metadata'
92--- tests/proof/expected/unknown-metadata 2012-09-30 16:07:25 +0000
93+++ tests/proof/expected/unknown-metadata 2012-10-28 15:04:18 +0000
94@@ -2,6 +2,8 @@
95 W: metadata name (test) must match directory name (unknown-metadata) exactly for local deployment.
96 E: no copyright file
97 E: Includes template README.ex file
98+E: README.ex Includes boilerplate README.ex line 1
99+E: README.ex Includes boilerplate README.ex line 2
100 E: template interface names should be changed: interface-name
101 E: Unknown relation field in relation relation-name - (baz)
102 E: template relations should be renamed to fit charm: relation-name

Subscribers

People subscribed via source and target branches