GeezerVison is showing github.com — MAINT: De-dupe regex usage · wangtingpython/zipline@6d83b06
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: setup.py +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -133,12 +133,14 @@ def _with_bounds(req): |
133 | 133 | return ''.join(with_bounds) |
134 | 134 |
|
135 | 135 |
|
| 136 | +REQ_PATTERN = re.compile("([^=<>]+)([<=>]{1,2})(.*)") |
| 137 | + |
| 138 | + |
136 | 139 | def _conda_format(req): |
137 | | - return re.sub( |
138 | | - '([^=<>]+)([=<>]{1,2})', |
139 | | - lambda m: '%s %s' % (m.group(1).lower(), m.group(2)), |
140 | | - req, |
141 | | - 1, |
| 140 | + return REQ_PATTERN.sub( |
| 141 | + lambda m: '%s %s%s' % (m.group(1).lower(), m.group(2), m.group(3)), |
| 142 | + req, |
| 143 | + 1, |
142 | 144 | ) |
143 | 145 |
|
144 | 146 |
|
@@ -184,14 +186,12 @@ def module_requirements(requirements_path, module_names): |
184 | 186 | module_names = set(module_names) |
185 | 187 | found = set() |
186 | 188 | module_lines = [] |
187 | | - parser = re.compile("([^=<>]+)([<=>]{1,2})(.*)") |
188 | 189 | for line in read_requirements(requirements_path, strict_bounds=True): |
189 | | - match = parser.match(line) |
| 190 | + match = REQ_PATTERN.match(line) |
190 | 191 | if match is None: |
191 | 192 | raise AssertionError("Could not parse requirement: '%s'" % line) |
192 | 193 |
|
193 | | - groups = match.groups() |
194 | | - name = groups[0] |
| 194 | + name = match.group(1) |
195 | 195 | if name in module_names: |
196 | 196 | found.add(name) |
197 | 197 | module_lines.append(line) |
|