Coverage for src/ipyvizzustory/__init__.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-25 14:04 +0100

1"""Python integration of Vizzu-Story.""" 

2 

3 

4from .storylib.story import Step, Slide 

5 

6 

7class Environment: 

8 """A class for selecting the runtime environment.""" 

9 

10 # pylint: disable=import-outside-toplevel 

11 # pylint: disable=unused-import 

12 

13 @staticmethod 

14 def get_story(): 

15 """A static method for importing the appropriate chart for the environment.""" 

16 

17 if Environment.is_ipython(): # pragma: no cover 

18 from .ipy_env.story import Story as JupyterStory 

19 

20 return JupyterStory 

21 

22 if Environment.is_streamlit(): # pragma: no cover 

23 from .st_env.story import Story as StreamlitStory 

24 

25 return StreamlitStory 

26 

27 from .py_env.story import Story as PythonStory 

28 

29 return PythonStory 

30 

31 @staticmethod 

32 def is_ipython(): 

33 """A static method for detecting Jupyter environment.""" 

34 try: 

35 from IPython import get_ipython # type: ignore 

36 

37 return get_ipython() 

38 except ImportError: # pragma: no cover 

39 return None 

40 

41 @staticmethod 

42 def is_streamlit(): 

43 """A static method for detecting Streamlit environment.""" 

44 try: 

45 from streamlit.scriptrunner.script_run_context import get_script_run_ctx 

46 

47 return get_script_run_ctx() 

48 except ImportError: # pragma: no cover 

49 return None 

50 

51 

52Story = Environment.get_story()