Show More
@@ -51,18 +51,10 b' class MarkupRenderer(object):' | |||||
51 | RST_PAT = re.compile(r'\.re?st$', re.IGNORECASE) |
|
51 | RST_PAT = re.compile(r'\.re?st$', re.IGNORECASE) | |
52 | PLAIN_PAT = re.compile(r'^readme$', re.IGNORECASE) |
|
52 | PLAIN_PAT = re.compile(r'^readme$', re.IGNORECASE) | |
53 |
|
53 | |||
54 | # list of readme files to search in file tree and display in summary |
|
|||
55 | # attached weights defines the search order lower is first |
|
|||
56 | ALL_READMES = [ |
|
|||
57 | ('readme', 0), ('README', 0), ('Readme', 0), |
|
|||
58 | ('doc/readme', 1), ('doc/README', 1), ('doc/Readme', 1), |
|
|||
59 | ('Docs/readme', 2), ('Docs/README', 2), ('Docs/Readme', 2), |
|
|||
60 | ('DOCS/readme', 2), ('DOCS/README', 2), ('DOCS/Readme', 2), |
|
|||
61 | ('docs/readme', 2), ('docs/README', 2), ('docs/Readme', 2), |
|
|||
62 | ] |
|
|||
63 | # extension together with weights. Lower is first means we control how |
|
54 | # extension together with weights. Lower is first means we control how | |
64 | # extensions are attached to readme names with those. |
|
55 | # extensions are attached to readme names with those. | |
65 | PLAIN_EXTS = [ |
|
56 | PLAIN_EXTS = [ | |
|
57 | # prefer no extension | |||
66 | ('', 0), # special case that renders READMES names without extension |
|
58 | ('', 0), # special case that renders READMES names without extension | |
67 | ('.text', 2), ('.TEXT', 2), |
|
59 | ('.text', 2), ('.TEXT', 2), | |
68 | ('.txt', 3), ('.TXT', 3) |
|
60 | ('.txt', 3), ('.TXT', 3) | |
@@ -80,8 +72,6 b' class MarkupRenderer(object):' | |||||
80 | ('.markdown', 4), ('.MARKDOWN', 4) |
|
72 | ('.markdown', 4), ('.MARKDOWN', 4) | |
81 | ] |
|
73 | ] | |
82 |
|
74 | |||
83 | ALL_EXTS = PLAIN_EXTS + MARKDOWN_EXTS + RST_EXTS |
|
|||
84 |
|
||||
85 | def _detect_renderer(self, source, filename=None): |
|
75 | def _detect_renderer(self, source, filename=None): | |
86 | """ |
|
76 | """ | |
87 | runs detection of what renderer should be used for generating html |
|
77 | runs detection of what renderer should be used for generating html | |
@@ -124,29 +114,6 b' class MarkupRenderer(object):' | |||||
124 |
|
114 | |||
125 | return None |
|
115 | return None | |
126 |
|
116 | |||
127 | @classmethod |
|
|||
128 | def generate_readmes(cls, all_readmes, extensions): |
|
|||
129 | combined = itertools.product(all_readmes, extensions) |
|
|||
130 | # sort by filename weight(y[0][1]) + extensions weight(y[1][1]) |
|
|||
131 | prioritized_readmes = sorted(combined, key=lambda y: y[0][1] + y[1][1]) |
|
|||
132 | # filename, extension |
|
|||
133 | return [''.join([x[0][0], x[1][0]]) for x in prioritized_readmes] |
|
|||
134 |
|
||||
135 | def pick_readme_order(self, default_renderer): |
|
|||
136 |
|
||||
137 | if default_renderer == 'markdown': |
|
|||
138 | markdown = self.generate_readmes(self.ALL_READMES, self.MARKDOWN_EXTS) |
|
|||
139 | readme_order = markdown + self.generate_readmes( |
|
|||
140 | self.ALL_READMES, self.RST_EXTS + self.PLAIN_EXTS) |
|
|||
141 | elif default_renderer == 'rst': |
|
|||
142 | markdown = self.generate_readmes(self.ALL_READMES, self.RST_EXTS) |
|
|||
143 | readme_order = markdown + self.generate_readmes( |
|
|||
144 | self.ALL_READMES, self.MARKDOWN_EXTS + self.PLAIN_EXTS) |
|
|||
145 | else: |
|
|||
146 | readme_order = self.generate_readmes(self.ALL_READMES, self.ALL_EXTS) |
|
|||
147 |
|
||||
148 | return readme_order |
|
|||
149 |
|
||||
150 | def render(self, source, filename=None): |
|
117 | def render(self, source, filename=None): | |
151 | """ |
|
118 | """ | |
152 | Renders a given filename using detected renderer |
|
119 | Renders a given filename using detected renderer |
@@ -1037,23 +1037,6 b' class ReadmeFinder:' | |||||
1037 |
|
1037 | |||
1038 | return sorted(paths, key=priority_and_path) |
|
1038 | return sorted(paths, key=priority_and_path) | |
1039 |
|
1039 | |||
1040 | def search_old(self, commit): |
|
|||
1041 | """ |
|
|||
1042 | Try to find a readme in the given `commit`. |
|
|||
1043 | """ |
|
|||
1044 | renderer = MarkupRenderer() |
|
|||
1045 | for f in renderer.pick_readme_order(self._default_renderer): |
|
|||
1046 | log.debug("Trying README %s", f) |
|
|||
1047 | try: |
|
|||
1048 | node = commit.get_node(f) |
|
|||
1049 | except NodeDoesNotExistError: |
|
|||
1050 | continue |
|
|||
1051 |
|
||||
1052 | if not node.is_file(): |
|
|||
1053 | continue |
|
|||
1054 |
|
||||
1055 | return f |
|
|||
1056 |
|
||||
1057 |
|
1040 | |||
1058 | class ReadmeMatch: |
|
1041 | class ReadmeMatch: | |
1059 |
|
1042 |
@@ -177,37 +177,3 b' Auto status change to |new_status|' | |||||
177 | renderer = RstTemplateRenderer() |
|
177 | renderer = RstTemplateRenderer() | |
178 | rendered = renderer.render('auto_status_change.mako', **params) |
|
178 | rendered = renderer.render('auto_status_change.mako', **params) | |
179 | assert expected == rendered |
|
179 | assert expected == rendered | |
180 |
|
||||
181 |
|
||||
182 | @pytest.mark.parametrize( |
|
|||
183 | "readmes, exts, order", |
|
|||
184 | [ |
|
|||
185 | ([], [], []), |
|
|||
186 |
|
||||
187 | ([('readme1', 0), ('text1', 1)], [('.ext', 0), ('.txt', 1)], |
|
|||
188 | ['readme1.ext', 'readme1.txt', 'text1.ext', 'text1.txt']), |
|
|||
189 |
|
||||
190 | ([('readme2', 0), ('text2', 1)], [('.ext', 2), ('.txt', 1)], |
|
|||
191 | ['readme2.txt', 'readme2.ext', 'text2.txt', 'text2.ext']), |
|
|||
192 |
|
||||
193 | ([('readme3', 0), ('text3', 1)], [('.XXX', 1)], |
|
|||
194 | ['readme3.XXX', 'text3.XXX']), |
|
|||
195 | ]) |
|
|||
196 | def test_generate_readmes(readmes, exts, order): |
|
|||
197 | assert order == MarkupRenderer.generate_readmes(readmes, exts) |
|
|||
198 |
|
||||
199 |
|
||||
200 | @pytest.mark.parametrize( |
|
|||
201 | "renderer, expected_order", |
|
|||
202 | [ |
|
|||
203 | ('plain', ['readme', 'README', 'Readme']), |
|
|||
204 | ('text', ['readme', 'README', 'Readme']), |
|
|||
205 | ('markdown', MarkupRenderer.generate_readmes( |
|
|||
206 | MarkupRenderer.ALL_READMES, MarkupRenderer.MARKDOWN_EXTS)), |
|
|||
207 | ('rst', MarkupRenderer.generate_readmes( |
|
|||
208 | MarkupRenderer.ALL_READMES, MarkupRenderer.RST_EXTS)), |
|
|||
209 | ]) |
|
|||
210 | def test_order_of_readme_generation(renderer, expected_order): |
|
|||
211 | mkd_renderer = MarkupRenderer() |
|
|||
212 | assert expected_order == mkd_renderer.pick_readme_order( |
|
|||
213 | renderer)[:len(expected_order)] |
|
General Comments 0
You need to be logged in to leave comments.
Login now