|
27 | 27 | methods for details. |
28 | 28 | """ |
29 | 29 |
|
30 | | -# same format as sys.version_info: "A tuple containing the five components of |
31 | | -# the version number: major, minor, micro, releaselevel, and serial. All |
32 | | -# values except releaselevel are integers; the release level is 'alpha', |
33 | | -# 'beta', 'candidate', or 'final'. The version_info value corresponding to the |
34 | | -# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a |
35 | | -# releaselevel of 'dev' for unreleased under-development code. |
36 | | -# |
37 | | -# If the releaselevel is 'alpha' then the major/minor/micro components are not |
38 | | -# established at this point, and setup.py will use a version of next-$(revno). |
39 | | -# If the releaselevel is 'final', then the tarball will be major.minor.micro. |
40 | | -# Otherwise it is major.minor.micro~$(revno). |
41 | | -from pbr.version import VersionInfo |
42 | | - |
43 | | -_version = VersionInfo("testscenarios") |
44 | | -__version__ = _version.semantic_version().version_tuple() |
45 | | -version = _version.release_string() |
46 | | - |
47 | 30 | __all__ = [ |
48 | 31 | 'TestWithScenarios', |
49 | 32 | 'WithScenarios', |
@@ -77,3 +60,53 @@ def test_suite(): |
77 | 60 | def load_tests(standard_tests, module, loader): |
78 | 61 | standard_tests.addTests(loader.loadTestsFromNames(["testscenarios.tests"])) |
79 | 62 | return standard_tests |
| 63 | + |
| 64 | + |
| 65 | +def __get_git_version(): |
| 66 | + import os |
| 67 | + import subprocess |
| 68 | + |
| 69 | + cwd = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir) |
| 70 | + |
| 71 | + try: |
| 72 | + out = subprocess.check_output( |
| 73 | + ["git", "describe"], stderr=subprocess.STDOUT, cwd=cwd |
| 74 | + ) |
| 75 | + except (OSError, subprocess.CalledProcessError): |
| 76 | + return None |
| 77 | + |
| 78 | + try: |
| 79 | + version = out.strip().decode("utf-8") |
| 80 | + except UnicodeDecodeError: |
| 81 | + return None |
| 82 | + |
| 83 | + if "-" in version: # after tag |
| 84 | + # convert version-N-githash to version.postN+githash |
| 85 | + return version.replace("-", ".post", 1).replace("-g", "+git", 1) |
| 86 | + else: |
| 87 | + return version |
| 88 | + |
| 89 | + |
| 90 | +# same format as sys.version_info: "A tuple containing the five components of |
| 91 | +# the version number: major, minor, micro, releaselevel, and serial. All |
| 92 | +# values except releaselevel are integers; the release level is 'alpha', |
| 93 | +# 'beta', 'candidate', or 'final'. The version_info value corresponding to the |
| 94 | +# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a |
| 95 | +# releaselevel of 'dev' for unreleased under-development code. |
| 96 | +# |
| 97 | +# If the releaselevel is 'alpha' then the major/minor/micro components are not |
| 98 | +# established at this point, and setup.py will use a version of next-$(revno). |
| 99 | +# If the releaselevel is 'final', then the tarball will be major.minor.micro. |
| 100 | +# Otherwise it is major.minor.micro~$(revno). |
| 101 | + |
| 102 | +try: |
| 103 | + from ._version import __version__, version |
| 104 | +except ModuleNotFoundError: |
| 105 | + # package is not installed |
| 106 | + if version := __get_git_version(): |
| 107 | + # we're in a git repo |
| 108 | + __version__ = tuple([int(v) if v.isdigit() else v for v in version.split(".")]) |
| 109 | + else: |
| 110 | + # we're working with a tarball or similar |
| 111 | + version = "0.0.0" |
| 112 | + __version__ = (0, 0, 0) |
0 commit comments