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
« 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.
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"""
22import warnings
24from .__version__ import __version__, __version_info__, PYENV
26from .storylib.story import Step, Slide
28from .env.py.story import Story as PythonStory
30try:
31 from .env.ipy.story import Story as JupyterStory
32 import IPython
34 if not IPython.get_ipython():
35 raise ImportError("JupyterStory")
36except ImportError:
37 JupyterStory = None # type: ignore
39try:
40 from .env.st.story import Story as StreamlitStory
41 import streamlit as st
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
48 if not ctx:
49 raise ImportError("StreamlitStory")
50except ImportError:
51 StreamlitStory = None # type: ignore
54def get_story():
55 """
56 A method for returning the appropriate Story for the environment.
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
63 return JupyterStory or StreamlitStory or PythonStory # type: ignore
66Story = get_story()
67"""
68Available types:
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"""
76__all__ = ["get_story", "Story", "Slide", "Step"]
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 )