-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a change to create this version dynamically. In addition, for dev setups, this commit adds the ability of showing the version of the without having to be in the popper repo folder.
- Loading branch information
Showing
4 changed files
with
52 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
import importlib | ||
import pathlib | ||
import os | ||
|
||
__version__ = "0.0.0" | ||
|
||
_repo_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..") | ||
_git_dir = os.path.join(_repo_dir, ".git") | ||
_version_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "_version.py") | ||
|
||
# check if dunamai is available | ||
dunamai_spec = importlib.util.find_spec("dunamai") | ||
dunamai_found = dunamai_spec is not None | ||
if dunamai_found: | ||
_dunamai_spec = importlib.util.find_spec("dunamai") | ||
_dunamai_found = _dunamai_spec is not None | ||
|
||
# if codebase is inside a git repo and dunamai available | ||
if os.path.isdir(_git_dir) and _dunamai_found: | ||
|
||
# if dunamai is found, then we use it to display the version | ||
import dunamai | ||
|
||
__version__ = dunamai.Version.from_any_vcs().serialize() | ||
_ver = f'__popper_version__ = "{__version__}"' | ||
# define GIT_DIR so dunamai gets the info for the popper repo instead of wherever | ||
# popper is being invoked from | ||
os.environ["GIT_DIR"] = _git_dir | ||
|
||
try: | ||
__version__ = dunamai.Version.from_git().serialize() | ||
_ver = f"__popper_version__ = '{__version__}'" | ||
except RuntimeError as e: | ||
# only raise if not a dunamai-raised error | ||
if "This does not appear to be a Git project" not in str(e): | ||
raise e | ||
|
||
_init_script_dir = pathlib.Path(__file__).parent.absolute() | ||
_version_path_ = os.path.join(_init_script_dir, "_version.py") | ||
with open(_version_path_, "w") as v: | ||
with open(_version_file, "w") as v: | ||
v.write(_ver + "\n") | ||
else: | ||
from popper._version import __popper_version__ as __version__ | ||
|
||
# unset GIT_DIR | ||
os.environ.pop("GIT_DIR") | ||
|
||
elif os.path.isfile(_version_file): | ||
# codebase not in a popper repo, and version file exists, so let's read from it | ||
from popper._version import __popper_version__ as _ver | ||
|
||
__version__ = _ver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__popper_version__ = "0.0.0" | ||
__popper_version__ = '2.7.0.post2.dev0+bed65005' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
from click.testing import CliRunner | ||
|
||
from popper import __version__ | ||
from popper._version import __popper_version__ | ||
from popper import _version_file | ||
from popper.commands import cmd_version | ||
from .test_common import PopperTest | ||
|
||
|
||
class TestCommandVersion(PopperTest): | ||
def test_version(self): | ||
|
||
self.assertIsNot("0.0.0", __version__) | ||
with self.assertLogs("popper") as test: | ||
runner = CliRunner() | ||
result = runner.invoke(cmd_version.cli) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIsNot(__version__, "0.0.0") | ||
self.assertEqual(__version__, __popper_version__) | ||
self.assertTrue(__version__ in test.output[0]) | ||
result = CliRunner().invoke(cmd_version.cli) | ||
self.assertTrue(__version__ in test.output[0]) | ||
self.assertEqual(0, result.exit_code) | ||
|
||
with open(_version_file) as f: | ||
self.assertEqual(f"__popper_version__ = '{__version__}'\n", f.read()) |