Coverage for rivapy / tools / holidays_compat.py: 37%
27 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-27 14:36 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-27 14:36 +0000
1# Compatibility wrapper for different versions of the `holidays` package.
2# It exposes a small, stable surface used across the codebase: HolidayBase, ECB
3# (European Central Bank calendar), EuropeanCentralBank (alias), country_holidays
4# and common country classes where available.
6try:
7 # Newer/standard API
8 from holidays import HolidayBase, country_holidays
10 # Many installations provide ECB; some versions provide EuropeanCentralBank
11 try:
12 from holidays import ECB
13 except Exception:
14 ECB = None
15 try:
16 from holidays import EuropeanCentralBank
17 except Exception:
18 # alias ECB if available
19 EuropeanCentralBank = ECB
20 # optional country classes
21 try:
22 from holidays import UnitedStates, Germany
23 except Exception:
24 UnitedStates = None
25 Germany = None
26 # provide short aliases expected by tests
27 DE = Germany
28 US = UnitedStates
29except Exception:
30 # If the holidays package is not available, expose minimal placeholders so
31 # imports do not fail at module import time. Attempting to use these
32 # placeholders will raise informative ImportErrors later.
33 class HolidayBase: # type: ignore
34 """Placeholder base class when `holidays` is not installed."""
36 def country_holidays(country):
37 raise ImportError("`holidays` package not installed or does not provide country_holidays")
39 ECB = None
40 EuropeanCentralBank = None
41 UnitedStates = None
42 Germany = None
43 DE = None
44 US = None