Skip to content

Commit 7d30b46

Browse files
authored
Merge pull request #71 from cms-cat/fixtest
fix: temp style workaround for jupyter
2 parents 57920a8 + 7aa3327 commit 7d30b46

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/cmsstyle/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from ._version import version as __version__ # noqa: F401
2+
13
from .cmsstyle import *

src/cmsstyle/_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def env_type():
2+
try:
3+
ipy_str = str(type(get_ipython()))
4+
if 'zmqshell' in ipy_str:
5+
return 'jupyter'
6+
if 'terminal' in ipy_str:
7+
return 'ipython'
8+
except:
9+
return 'terminal'

src/cmsstyle/_version.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version: str
2+
version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str]

src/cmsstyle/cmsstyle.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from dataclasses import dataclass
2121
from typing import Any, Iterable
2222
import os
23+
from ._utils import env_type
2324

2425
# This global variables for the module should not be accessed directy! Use the utilities below.
2526
cms_lumi = "Run 2, 138 fb^{#minus1}"
@@ -725,13 +726,13 @@ def setCMSStyle(force=rt.kTRUE):
725726
cmsStyle.SetHatchesSpacing(1.3)
726727

727728
# Some additional parameters we need to set as "style"
728-
729-
if (
730-
float(".".join(re.split("\\.|/", rt.__version__)[0:2])) >= 6.32
731-
): # Not available before!
732-
# This change by O. Gonzalez allows to save inside the canvas the
733-
# informnation about the defined colours.
734-
rt.TColor.DefinedColors(1)
729+
if env_type() != "jupyter": # Snippet below crashes in jupyter as late as 6.36. Issue reproted to ROOT
730+
if (
731+
float(".".join(re.split("\\.|/", rt.__version__)[0:2])) >= 6.32
732+
): # Not available before!
733+
# This change by O. Gonzalez allows to save inside the canvas the
734+
# informnation about the defined colours.
735+
rt.TColor.DefinedColors(1)
735736

736737
# Using the Style.
737738
cmsStyle.cd()

0 commit comments

Comments
 (0)