Skip to content

Commit 2f16de1

Browse files
committed
Fall-back to avoid hard dependency on setuptools_scm
1 parent 1db58c0 commit 2f16de1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

boututils/__init__.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@
4545
except ModuleNotFoundError:
4646
from importlib_metadata import version, PackageNotFoundError
4747
try:
48+
# This gives the version if the boututils package was installed
4849
__version__ = version(__name__)
4950
except PackageNotFoundError:
51+
# This branch handles the case when boututils is used from the git repo
5052
try:
5153
from setuptools_scm import get_version
52-
except ModuleNotFoundError as e:
53-
error_info = (
54-
"'setuptools_scm' is required to get the version number when running "
55-
"boututils from the git repo. Please install 'setuptools_scm'."
56-
)
57-
print(error_info)
58-
raise ModuleNotFoundError(str(e) + ". " + error_info)
59-
else:
6054
from pathlib import Path
6155
path = Path(__file__).resolve()
6256
__version__ = get_version(root="..", relative_to=path)
57+
except (ModuleNotFoundError, LookupError) as e:
58+
# ModuleNotFoundError if setuptools_scm is not installed.
59+
# LookupError if git is not installed, or the code is not in a git repo even
60+
# though it has not been installed.
61+
from warnings import warn
62+
warn(
63+
"'setuptools_scm' and git are required to get the version number when "
64+
"running boututils from the git repo. Please install 'setuptools_scm' and "
65+
"check 'git rev-parse HEAD' works. Setting __version__='dev' as a "
66+
"workaround."
67+
)
68+
__version__ = "dev"

0 commit comments

Comments
 (0)