Skip to content

Commit 48aa5ab

Browse files
authored
Fix pre-prompt ccds version error (#426)
* fix pre-prompt ccds version error by moving versioning into __init__ and removing any module-level imports from pre-prompt * wrap pre_prompt import of ccds version in try/except * use more specific try/except for import error handling to yield the desired behavior
1 parent fb791fa commit 48aa5ab

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

ccds/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from ccds.version import __version__
1+
from importlib.metadata import version
22

3-
__version__
3+
__version__ = version("cookiecutter-data-science")

ccds/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from cookiecutter import cli
2424
from cookiecutter import main as api_main # noqa: F401 referenced by tests
2525

26-
from ccds.version import __version__
26+
from ccds import __version__
2727

2828

2929
def default_ccds_main(f):

ccds/version.py

-9
This file was deleted.

hooks/pre_prompt.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import warnings
2+
3+
try:
4+
from ccds import __version__
5+
except ModuleNotFoundError:
6+
__version__ = None # ccds is not installed
7+
except ImportError:
8+
__version__ = "2.0.0" # ccds is installed but version is 2.0.0
9+
10+
if __name__ == "__main__":
11+
if __version__ is not None and __version__ < "2.0.1":
12+
warnings.warn(
13+
"You're currently using a CCDS version that always applies the "
14+
"newest template. For more stable behavior, upgrade to "
15+
"CCDS version 2.0.1 or later with your package manager. "
16+
"For example, with pip, run: pip install -U cookiecutter-data-science.",
17+
DeprecationWarning,
18+
)

0 commit comments

Comments
 (0)