Coverage for src/ipyvizzustory/__init__.py: 100%
12 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-25 13:56 +0100
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-25 13:56 +0100
1"""
2Build, present and share animated data stories in `Jupyter Notebook` and similar environments.
4`ipyvizzu-story` package consists of two main parts:
6* [Storylib][ipyvizzustory.storylib]: environment independent modules
7* [Env][ipyvizzustory.env]: environment dependent modules
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.
12`ipyvizzu-story` package imports the following objects in `__init__.py`:
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"""
23from .storylib.story import Step, Slide
25from .env.py.story import Story as PythonStory
27try:
28 from .env.ipy.story import Story as JupyterStory
29 import IPython # type: ignore
31 if not IPython.get_ipython(): # pragma: no cover
32 raise ImportError("JupyterStory")
33except ImportError as e: # pragma: no cover
34 JupyterStory = None # type: ignore
36try:
37 from .env.st.story import Story as StreamlitStory
38 import streamlit as st
40 if hasattr(st, "runtime"): # pragma: no cover
41 ctx = st.runtime.scriptrunner.get_script_run_ctx() # type: ignore
42 else: # pragma: no cover
43 ctx = st.scriptrunner.script_run_context.get_script_run_ctx() # type: ignore # pylint: disable=no-member
45 if not ctx: # pragma: no cover
46 raise ImportError("StreamlitStory")
47except ImportError: # pragma: no cover
48 StreamlitStory = None # type: ignore
51def get_story():
52 """
53 A method for returning the appropriate Story for the environment.
55 Returns:
56 (Union[ipyvizzustory.env.py.story.Story, ipyvizzustory.env.ipy.story.Story, ipyvizzustory.env.st.story.Story]):
57 The appropriate `Story` for the environment.
58 """ # pylint: disable=line-too-long
60 return JupyterStory or StreamlitStory or PythonStory
63Story = get_story()
64"""
65Available types:
67* [Jupyter/IPython Story][ipyvizzustory.env.ipy.story.Story]
68* [Streamlit Story][ipyvizzustory.env.st.story.Story]
69* [Panel Story][ipyvizzustory.env.pn.story.Story]
70* [Python Story][ipyvizzustory.env.py.story.Story]
71"""