Read __version__ string for an init file.
(init_file)
| 123 | |
| 124 | |
| 125 | def get_version_string(init_file): |
| 126 | """ |
| 127 | Read __version__ string for an init file. |
| 128 | """ |
| 129 | |
| 130 | with open(init_file, "r") as fp: |
| 131 | content = fp.read() |
| 132 | version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", content, re.M) |
| 133 | if version_match: |
| 134 | return version_match.group(1) |
| 135 | |
| 136 | raise RuntimeError("Unable to find version string in %s." % (init_file)) |
| 137 | |
| 138 | |
| 139 | # alias for get_version_string |