-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separate lib, ipyvizzu, streamlit modules - one package #179
base: main
Are you sure you want to change the base?
Conversation
@nyirog I started another draft for separating lib, python, jupyter, streamlit, etc. modules. In this solution we'll use one package that contains a module (chartlib) which is an abstract chart class, and from that an inherited python, jupyter and streamlit charts. In the other draft I separated the modules into different packages because if we add jupyter, streamlit, etc as a dependency, everyone needs to install all of them. In used to help the import, I add a small script into ipyvizzu/init.py that tries to find the environment where ipyvizzu used. |
It seems good, that only that user have to install
I don't know how data scientists work, but it is a common practice to create new virtualenv for every new project, therefore I would not guess about the existence of setup(
...,
extras_require={
"jupyter": ["IPython"],
"streamlit": ["streamlit"],
}
)
I think it is a good practice to catch the from .python.chart import Chart as PythonChart
try:
from .jupyter.chart import Chart as JupyterChart
except ImportError:
JupyterChart = None
try:
from .streamlit.chart import Chart as StreamlitChart
except ImportError:
StreamlitChart = None
def get_chart():
return JupyterChart or StreamlitChart or PythonChart Ps.: Sorry for the late reply, but I don't have even zero but "minus" free time. |
@@ -1,2 +1 @@ | |||
IPython |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ipython
and streamlit
may could be added to setup
as extras_require
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ps.: Sorry for the late reply, but I don't have even zero but "minus" free time.
@nyirog No problem at all, really appreciate your help.
@nyirog Thank, it's an easier way. from .python.chart import Chart as PythonChart
try:
from .jupyter.chart import Chart as JupyterChart
import IPython # type: ignore
if not IPython.get_ipython(): # pragma: no cover
raise ImportError("JupyterChart")
except ImportError as e: # pragma: no cover
JupyterChart = None # type: ignore
try:
from .streamlit.chart import Chart as StreamlitChart
import streamlit as st
if not st.scriptrunner.script_run_context.get_script_run_ctx(): # pragma: no cover
raise ImportError("StreamlitChart")
except ImportError: # pragma: no cover
StreamlitChart = None # type: ignore
def get_chart():
"""A method for returning the appropriate Chart for the environment."""
return JupyterChart or StreamlitChart or PythonChart
Chart = get_chart() |
Yes, we should hide import error from the user and report error only when the user asked for a specific Chart (StreamlitChart or JupyterChar) but the required packages are not installed. We can raise a runtime error in that case. The runtime error should be risen from a constructor ( p.s.: In the example above the |
todo: