File tree Expand file tree Collapse file tree 1 file changed +29
-4
lines changed Expand file tree Collapse file tree 1 file changed +29
-4
lines changed Original file line number Diff line number Diff line change 11from importlib .metadata import PackageNotFoundError , version
22
3- try :
4- __version__ = version ("pdl" )
5- except PackageNotFoundError :
6- pass
3+ from ._version import __version__ as hardcoded_version
4+
5+
6+ def _get_distribution_version (distribution_name : str ) -> str :
7+ """
8+ This function attempts to retrieve the version of PDL package using
9+ importlib.metadata.
10+
11+ When the package is not installed, importlib will raise a PackageNotFoundError.
12+ In this case, we fallback to the hardcoded version.
13+
14+ When the package is installed, but the distribution name does not match,
15+ importlib will return the version of the package that is installed.
16+ """
17+ try :
18+ return version (distribution_name )
19+ except PackageNotFoundError :
20+ # This is a fallback for when the package is not recognized by importlib.metadata.
21+ # This can happen when the package is not installed.
22+ return (
23+ hardcoded_version
24+ if distribution_name == "pdl"
25+ else _get_distribution_version (
26+ "pdl" # This is a fallback to maintain the previous behavior.
27+ )
28+ )
29+
30+
31+ __version__ = _get_distribution_version ("prompt-declaration-language" )
You can’t perform that action at this time.
0 commit comments