Parse information from a line in a requirements text file
(line)
| 105 | require_fpath = fname |
| 106 | |
| 107 | def parse_line(line): |
| 108 | """ |
| 109 | Parse information from a line in a requirements text file |
| 110 | """ |
| 111 | if line.startswith('-r '): |
| 112 | # Allow specifying requirements in other files |
| 113 | target = line.split(' ')[1] |
| 114 | for info in parse_require_file(target): |
| 115 | yield info |
| 116 | else: |
| 117 | info = {'line': line} |
| 118 | if line.startswith('-e '): |
| 119 | info['package'] = line.split('#egg=')[1] |
| 120 | else: |
| 121 | # Remove versioning from the package |
| 122 | pat = '(' + '|'.join(['>=', '==', '>']) + ')' |
| 123 | parts = re.split(pat, line, maxsplit=1) |
| 124 | parts = [p.strip() for p in parts] |
| 125 | |
| 126 | info['package'] = parts[0] |
| 127 | if len(parts) > 1: |
| 128 | op, rest = parts[1:] |
| 129 | if ';' in rest: |
| 130 | # Handle platform specific dependencies |
| 131 | # http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies |
| 132 | version, platform_deps = map(str.strip, |
| 133 | rest.split(';')) |
| 134 | info['platform_deps'] = platform_deps |
| 135 | else: |
| 136 | version = rest # NOQA |
| 137 | info['version'] = (op, version) |
| 138 | yield info |
| 139 | |
| 140 | def parse_require_file(fpath): |
| 141 | with open(fpath, 'r') as f: |
no test coverage detected