Parse information from a line in a requirements text file
(line)
| 23 | require_fpath = fname |
| 24 | |
| 25 | def parse_line(line): |
| 26 | """ |
| 27 | Parse information from a line in a requirements text file |
| 28 | """ |
| 29 | if line.startswith('-r '): |
| 30 | # Allow specifying requirements in other files |
| 31 | target = line.split(' ')[1] |
| 32 | for info in parse_require_file(target): |
| 33 | yield info |
| 34 | else: |
| 35 | info = {'line': line} |
| 36 | if line.startswith('-e '): |
| 37 | info['package'] = line.split('#egg=')[1] |
| 38 | else: |
| 39 | # Remove versioning from the package |
| 40 | pat = '(' + '|'.join(['>=', '==', '>']) + ')' |
| 41 | parts = re.split(pat, line, maxsplit=1) |
| 42 | parts = [p.strip() for p in parts] |
| 43 | |
| 44 | info['package'] = parts[0] |
| 45 | if len(parts) > 1: |
| 46 | op, rest = parts[1:] |
| 47 | if ';' in rest: |
| 48 | # Handle platform specific dependencies |
| 49 | # http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies |
| 50 | version, platform_deps = map(str.strip, |
| 51 | rest.split(';')) |
| 52 | info['platform_deps'] = platform_deps |
| 53 | else: |
| 54 | version = rest # NOQA |
| 55 | info['version'] = (op, version) |
| 56 | yield info |
| 57 | |
| 58 | def parse_require_file(fpath): |
| 59 | with open(fpath, 'r') as f: |
no test coverage detected