| Conditions | 2 |
| Total Lines | 16 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import os |
||
| 6 | def get_version(source): |
||
| 7 | """ |
||
| 8 | Retrieve the version of a python distribution. |
||
| 9 | |||
| 10 | version_file default is the <project_root>/_version.py |
||
| 11 | |||
| 12 | :param source: Path to project root |
||
| 13 | :return: Version string |
||
| 14 | """ |
||
| 15 | version_str_lines = open(os.path.join(source, '_version.py'), "rt").read() |
||
| 16 | version_str_regex = r"^__version__ = ['\"]([^'\"]*)['\"]" |
||
| 17 | mo = re.search(version_str_regex, version_str_lines, re.M) |
||
| 18 | if mo: |
||
| 19 | return mo.group(1) |
||
| 20 | else: |
||
| 21 | raise RuntimeError("Unable to find version string in %s." % os.path.join(source, os.path.basename(source))) |
||
| 22 | |||
| 34 |