diff --git a/src/cmsstyle/__init__.py b/src/cmsstyle/__init__.py index 35d79de..8581837 100644 --- a/src/cmsstyle/__init__.py +++ b/src/cmsstyle/__init__.py @@ -1 +1,3 @@ +from ._version import version as __version__ # noqa: F401 + from .cmsstyle import * diff --git a/src/cmsstyle/_utils.py b/src/cmsstyle/_utils.py new file mode 100644 index 0000000..b950e0e --- /dev/null +++ b/src/cmsstyle/_utils.py @@ -0,0 +1,9 @@ +def env_type(): + try: + ipy_str = str(type(get_ipython())) + if 'zmqshell' in ipy_str: + return 'jupyter' + if 'terminal' in ipy_str: + return 'ipython' + except: + return 'terminal' diff --git a/src/cmsstyle/_version.pyi b/src/cmsstyle/_version.pyi new file mode 100644 index 0000000..5bb2b22 --- /dev/null +++ b/src/cmsstyle/_version.pyi @@ -0,0 +1,2 @@ +version: str +version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] diff --git a/src/cmsstyle/cmsstyle.py b/src/cmsstyle/cmsstyle.py index a927923..a0bf7b4 100644 --- a/src/cmsstyle/cmsstyle.py +++ b/src/cmsstyle/cmsstyle.py @@ -20,6 +20,7 @@ from dataclasses import dataclass from typing import Any, Iterable import os +from ._utils import env_type # This global variables for the module should not be accessed directy! Use the utilities below. cms_lumi = "Run 2, 138 fb^{#minus1}" @@ -725,13 +726,13 @@ def setCMSStyle(force=rt.kTRUE): cmsStyle.SetHatchesSpacing(1.3) # Some additional parameters we need to set as "style" - - if ( - float(".".join(re.split("\\.|/", rt.__version__)[0:2])) >= 6.32 - ): # Not available before! - # This change by O. Gonzalez allows to save inside the canvas the - # informnation about the defined colours. - rt.TColor.DefinedColors(1) + if env_type() != "jupyter": # Snippet below crashes in jupyter as late as 6.36. Issue reproted to ROOT + if ( + float(".".join(re.split("\\.|/", rt.__version__)[0:2])) >= 6.32 + ): # Not available before! + # This change by O. Gonzalez allows to save inside the canvas the + # informnation about the defined colours. + rt.TColor.DefinedColors(1) # Using the Style. cmsStyle.cd()