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