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

28 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-10 10:22 +0000

1""" 

2Build, present and share animated data stories in `Jupyter Notebook` and similar environments. 

3 

4`ipyvizzu-story` package consists of two main parts: 

5 

6* [Storylib][ipyvizzustory.storylib]: environment independent modules 

7* [Env][ipyvizzustory.env]: environment dependent modules 

8 

9`ipyvizzu-story` package tries to figure out the environment and import the correct type of `Story`, 

10however `Story` could be imported with full path. 

11 

12`ipyvizzu-story` package imports the following objects in `__init__.py`: 

13 

14 

15* `Story` from [Env.py.story][ipyvizzustory.env.py.story] or 

16 [Env.ipy.story][ipyvizzustory.env.ipy.story] or 

17 [Env.st.story][ipyvizzustory.env.st.story] 

18* [Step][ipyvizzustory.storylib.story.Step] 

19* [Slide][ipyvizzustory.storylib.story.Slide] 

20""" 

21 

22import warnings 

23 

24from .__version__ import __version__, __version_info__, PYENV 

25 

26from .storylib.story import Step, Slide 

27 

28from .env.py.story import Story as PythonStory 

29 

30try: 

31 from .env.ipy.story import Story as JupyterStory 

32 import IPython 

33 

34 if not IPython.get_ipython(): 

35 raise ImportError("JupyterStory") 

36except ImportError: 

37 JupyterStory = None # type: ignore 

38 

39try: 

40 from .env.st.story import Story as StreamlitStory 

41 import streamlit as st 

42 

43 if hasattr(st, "runtime"): 

44 ctx = st.runtime.scriptrunner.get_script_run_ctx() 

45 else: 

46 ctx = st.scriptrunner.script_run_context.get_script_run_ctx() # type: ignore # pylint: disable=no-member 

47 

48 if not ctx: 

49 raise ImportError("StreamlitStory") 

50except ImportError: 

51 StreamlitStory = None # type: ignore 

52 

53 

54def get_story(): 

55 """ 

56 A method for returning the appropriate Story for the environment. 

57 

58 Returns: 

59 (Union[ipyvizzustory.env.py.story.Story, ipyvizzustory.env.ipy.story.Story, ipyvizzustory.env.st.story.Story]): 

60 The appropriate `Story` for the environment. 

61 """ # pylint: disable=line-too-long 

62 

63 return JupyterStory or StreamlitStory or PythonStory # type: ignore 

64 

65 

66Story = get_story() 

67""" 

68Available types: 

69 

70* [Jupyter/IPython Story][ipyvizzustory.env.ipy.story.Story] 

71* [Streamlit Story][ipyvizzustory.env.st.story.Story] 

72* [Panel Story][ipyvizzustory.env.pn.story.Story] 

73* [Python Story][ipyvizzustory.env.py.story.Story] 

74""" 

75 

76__all__ = ["get_story", "Story", "Slide", "Step"] 

77 

78# TODO: remove once support for Python 3.6 is dropped 

79if PYENV < (3, 7): 

80 warnings.warn( 

81 "Python 3.6 support will be dropped in future versions.", 

82 FutureWarning, 

83 stacklevel=2, 

84 )