Parse information from a line in a requirements text file.
(line)
| 38 | require_fpath = fname |
| 39 | |
| 40 | def parse_line(line): |
| 41 | """Parse information from a line in a requirements text file.""" |
| 42 | if line.startswith('-r '): |
| 43 | # Allow specifying requirements in other files |
| 44 | target = line.split(' ')[1] |
| 45 | for info in parse_require_file(target): |
| 46 | yield info |
| 47 | else: |
| 48 | info = {'line': line} |
| 49 | if line.startswith('-e '): |
| 50 | info['package'] = line.split('#egg=')[1] |
| 51 | else: |
| 52 | # Remove versioning from the package |
| 53 | pat = '(' + '|'.join(['>=', '==', '>']) + ')' |
| 54 | parts = re.split(pat, line, maxsplit=1) |
| 55 | parts = [p.strip() for p in parts] |
| 56 | |
| 57 | info['package'] = parts[0] |
| 58 | if len(parts) > 1: |
| 59 | op, rest = parts[1:] |
| 60 | if ';' in rest: |
| 61 | # Handle platform specific dependencies |
| 62 | # http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies |
| 63 | version, platform_deps = map(str.strip, |
| 64 | rest.split(';')) |
| 65 | info['platform_deps'] = platform_deps |
| 66 | else: |
| 67 | version = rest # NOQA |
| 68 | if '--' in version: |
| 69 | # the `extras_require` doesn't accept options. |
| 70 | version = version.split('--')[0].strip() |
| 71 | info['version'] = (op, version) |
| 72 | yield info |
| 73 | |
| 74 | def parse_require_file(fpath): |
| 75 | with open(fpath, 'r') as f: |
no test coverage detected