Skip to content

Commit 63c5105

Browse files
committed
fix: _metadata import works outside of module
1 parent 1445387 commit 63c5105

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

DateIntervalCycler/DateIntervalCycler.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import Sequence, Union, Optional, Iterator
22
import datetime as dt
33

4+
# %% --------------------------------------------------------------------------
5+
46
try:
57
from ._metadata import (
68
__version__,
@@ -15,16 +17,34 @@
1517
__copyright__,
1618
)
1719
except ImportError:
18-
__version__ = "Failed to load from _metadata.py"
19-
__author__ = __version__
20-
__email__ = __version__
21-
__license__ = __version__
22-
__status__ = __version__
23-
__maintainer__ = __version__
24-
__credits__ = __version__
25-
__url__ = __version__
26-
__description__ = __version__
27-
__copyright__ = __version__
20+
try:
21+
from _metadata import (
22+
__version__,
23+
__author__,
24+
__email__,
25+
__license__,
26+
__status__,
27+
__maintainer__,
28+
__credits__,
29+
__url__,
30+
__description__,
31+
__copyright__,
32+
)
33+
except ImportError:
34+
# _metadata.py failed to load,
35+
# fill in with dummy values (script may be standalone)
36+
__version__ = "Failed to load from _metadata.py"
37+
__author__ = __version__
38+
__email__ = __version__
39+
__license__ = __version__
40+
__status__ = __version__
41+
__maintainer__ = __version__
42+
__credits__ = __version__
43+
__url__ = __version__
44+
__description__ = __version__
45+
__copyright__ = __version__
46+
47+
# %% --------------------------------------------------------------------------
2848

2949
FEB28 = (2, 28)
3050
FEB29 = (2, 29)
@@ -38,6 +58,8 @@
3858
_month_days_29 = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
3959
_month_days_28 = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
4060

61+
# %% --------------------------------------------------------------------------
62+
4163

4264
def _is_leap(year: int) -> bool:
4365
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
@@ -57,6 +79,8 @@ def _intervals_to_array(cycles: Sequence[tuple[int, int]]) -> tuple[tuple[int, i
5779
"""
5880
return tuple(sorted(set([(r[0], r[1]) for r in cycles])))
5981

82+
# %% --------------------------------------------------------------------------
83+
6084

6185
class DateIntervalCycler:
6286
"""
@@ -1658,6 +1682,8 @@ def __next__(self) -> tuple[dt.datetime, dt.datetime]:
16581682
# return rng
16591683
raise StopIteration
16601684

1685+
# %% --------------------------------------------------------------------------
1686+
16611687

16621688
if __name__ == "__main__":
16631689
print(f"Version: {__version__}")

0 commit comments

Comments
 (0)