fix(ayanamsa): keep a caller-selected mode across import and transit paths (BUG-1269, upstream 23be1807)

This commit is contained in:
jesse-ux
2026-10-07 17:05:18 +08:00
parent 4b9c019814
commit 4e134b9b9f
6 changed files with 183 additions and 24 deletions
+11 -1
View File
@@ -45,6 +45,10 @@ AYANAMSA_DISPLAY_NAMES = {
DEFAULT_AYANAMSA_NAME = 'raman'
ACTIVE_AYANAMSA_NAME = DEFAULT_AYANAMSA_NAME
# Flipped the first time any caller applies a mode. Import bootstraps read this
# so they do not replace a mode that was already selected. This module is
# imported once; jyotish_engine can be loaded a second time as its own module.
AYANAMSA_APPLIED_IN_PROCESS = False
class UnsupportedAyanamsaError(ValueError):
@@ -92,7 +96,7 @@ def current_ayanamsa_name(args: Any = None) -> str:
def apply_ayanamsa(name: Any = None, swe_module: Any = None) -> bool:
"""Set Swiss Ephemeris sidereal mode explicitly."""
global ACTIVE_AYANAMSA_NAME
global ACTIVE_AYANAMSA_NAME, AYANAMSA_APPLIED_IN_PROCESS
module = swe_module or swe
if module is None:
return False
@@ -102,9 +106,15 @@ def apply_ayanamsa(name: Any = None, swe_module: Any = None) -> bool:
except Exception:
return False
ACTIVE_AYANAMSA_NAME = key
AYANAMSA_APPLIED_IN_PROCESS = True
return True
def ayanamsa_already_applied() -> bool:
"""True once any caller has applied an ayanamsa in this process."""
return AYANAMSA_APPLIED_IN_PROCESS
@contextmanager
def temporary_ayanamsa(name: Any = None, swe_module: Any = None) -> Iterator[str]:
"""Apply a sidereal mode and restore the previous process-wide mode."""