Parse information from a line in a requirements text file.
(line)
| 83 | require_fpath = fname |
| 84 | |
| 85 | def parse_line(line): |
| 86 | """Parse information from a line in a requirements text file.""" |
| 87 | if line.startswith('-r '): |
| 88 | # Allow specifying requirements in other files |
| 89 | target = line.split(' ')[1] |
| 90 | for info in parse_require_file(target): |
| 91 | yield info |
| 92 | else: |
| 93 | info = {'line': line} |
| 94 | if line.startswith('-e '): |
| 95 | info['package'] = line.split('#egg=')[1] |
| 96 | else: |
| 97 | # Remove versioning from the package |
| 98 | pat = '(' + '|'.join(['>=', '==', '>']) + ')' |
| 99 | parts = re.split(pat, line, maxsplit=1) |
| 100 | parts = [p.strip() for p in parts] |
| 101 | |
| 102 | info['package'] = parts[0] |
| 103 | if len(parts) > 1: |
| 104 | op, rest = parts[1:] |
| 105 | if ';' in rest: |
| 106 | # Handle platform specific dependencies |
| 107 | # http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies |
| 108 | version, platform_deps = map(str.strip, |
| 109 | rest.split(';')) |
| 110 | info['platform_deps'] = platform_deps |
| 111 | else: |
| 112 | version = rest # NOQA |
| 113 | info['version'] = (op, version) |
| 114 | yield info |
| 115 | |
| 116 | def parse_require_file(fpath): |
| 117 | with open(fpath, 'r') as f: |
no test coverage detected