Просмотр исходного кода

Merge pull request #1143 from zauberzeug/lighter_package

Lighter core package by making pywebview, plotly and matplotlib optional
Falko Schindler 1 год назад
Родитель
Сommit
7695ca6332
8 измененных файлов с 310 добавлено и 540 удалено
  1. 2 2
      .github/workflows/test.yml
  2. 2 2
      development.dockerfile
  3. 1 0
      nicegui/globals.py
  4. 2 1
      nicegui/native_mode.py
  5. 23 5
      nicegui/ui.py
  6. 265 520
      poetry.lock
  7. 9 7
      pyproject.toml
  8. 6 3
      website/documentation.py

+ 2 - 2
.github/workflows/test.yml

@@ -6,7 +6,7 @@ jobs:
   test:
     strategy:
       matrix:
-        python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
+        python: ["3.8", "3.9", "3.10", "3.11"]
       fail-fast: false
     runs-on: ubuntu-latest
     timeout-minutes: 40
@@ -23,7 +23,7 @@ jobs:
       - name: install dependencies
         run: |
           poetry config virtualenvs.create false
-          poetry install
+          poetry install --all-extras
           # install packages to run the examples
           pip install opencv-python opencv-contrib-python-headless httpx replicate langchain openai simpy tortoise-orm
           pip install -r tests/requirements.txt

+ 2 - 2
development.dockerfile

@@ -1,4 +1,4 @@
-FROM python:3.7.16-slim
+FROM python:3.8-slim
 
 RUN apt update && apt install curl -y
 
@@ -11,6 +11,6 @@ RUN curl -sSL https://install.python-poetry.org | python3 - && \
 WORKDIR /app
 
 COPY ./pyproject.toml ./poetry.lock* main.py ./
-RUN poetry install --no-root
+RUN poetry install --no-root --all-extras
 
 CMD python3 -m debugpy --listen 5678 main.py

+ 1 - 0
nicegui/globals.py

@@ -32,6 +32,7 @@ loop: Optional[asyncio.AbstractEventLoop] = None
 log: logging.Logger = logging.getLogger('nicegui')
 state: State = State.STOPPED
 ui_run_has_been_called: bool = False
+optional_features: List[str] = []
 
 reload: bool
 title: str

+ 2 - 1
nicegui/native_mode.py

@@ -41,7 +41,8 @@ def open_window(
         start_window_method_executor(window, method_queue, response_queue, closing)
         webview.start(storage_path=tempfile.mkdtemp(), **globals.app.native.start_args)
     except NameError:
-        logging.error('Native mode is not supported in this configuration. Please install pywebview to use it.')
+        logging.error('''Native mode is not supported in this configuration.
+Please run "pip install pywebview" to use it.''')
         sys.exit(1)
 
 

+ 23 - 5
nicegui/ui.py

@@ -40,7 +40,6 @@ __all__ = [
     'menu_item',
     'mermaid',
     'number',
-    'plotly',
     'circular_progress',
     'linear_progress',
     'query',
@@ -127,7 +126,6 @@ from .elements.menu import Menu as menu
 from .elements.menu import MenuItem as menu_item
 from .elements.mermaid import Mermaid as mermaid
 from .elements.number import Number as number
-from .elements.plotly import Plotly as plotly
 from .elements.progress import CircularProgress as circular_progress
 from .elements.progress import LinearProgress as linear_progress
 from .elements.query import query
@@ -173,8 +171,28 @@ from .page_layout import RightDrawer as right_drawer
 from .run import run
 from .run_with import run_with
 
+from .globals import optional_features
+try:
+    from .elements.plotly import Plotly as plotly
+    optional_features.append('plotly')
+except ImportError:
+    def plotly(*args, **kwargs):
+        raise ImportError('Plotly is not installed. Please run "pip install plotly".')
+__all__.append('plotly')
+
 if os.environ.get('MATPLOTLIB', 'true').lower() == 'true':
-    from .elements.line_plot import LinePlot as line_plot
-    from .elements.pyplot import Pyplot as pyplot
-    plot = deprecated(pyplot, 'ui.plot', 'ui.pyplot', 317)
+    try:
+        from .elements.line_plot import LinePlot as line_plot
+        from .elements.pyplot import Pyplot as pyplot
+        plot = deprecated(pyplot, 'ui.plot', 'ui.pyplot', 317)
+        optional_features.append('matplotlib')
+    except ImportError:
+        def line_plot(*args, **kwargs):
+            raise ImportError('Matplotlib is not installed. Please run "pip install matplotlib".')
+
+        def pyplot(*args, **kwargs):
+            raise ImportError('Matplotlib is not installed. Please run "pip install matplotlib".')
+
+        def plot(*args, **kwargs):
+            raise ImportError('Matplotlib is not installed. Please run "pip install matplotlib".')
     __all__.extend(['line_plot', 'pyplot', 'plot'])

Разница между файлами не показана из-за своего большого размера
+ 265 - 520
poetry.lock


+ 9 - 7
pyproject.toml

@@ -9,27 +9,29 @@ repository = "https://github.com/zauberzeug/nicegui"
 keywords = ["gui", "ui", "web", "interface", "live"]
 
 [tool.poetry.dependencies]
-python = "^3.7"
+python = "^3.8"
 typing-extensions = ">=3.10.0"
 markdown2 = "^2.4.7"
 Pygments = ">=2.9.0,<3.0.0"
 uvicorn = {extras = ["standard"], version = "^0.22.0"}
-matplotlib = [
-    { version = "^3.5.0", markers = "python_version ~= '3.7'"},
-    { version = ">=3.6.0,<4.0.0", markers = "python_version ~= '3.11.0'"},
-]
 fastapi = ">=0.92,<1.0.0"
 fastapi-socketio = "^0.0.10"
 vbuild = "^0.8.1"
 watchfiles = ">=0.18.1,<1.0.0"
 jinja2 = "^3.1.2"
 python-multipart = "^0.0.6"
-plotly = "^5.13.0"
 orjson = {version = "^3.8.6", markers = "platform_machine != 'i386' and platform_machine != 'i686'"} # orjson does not support 32bit
-pywebview = "^4.0.2"
 importlib_metadata = { version = "^6.0.0", markers = "python_version ~= '3.7'" } # Python 3.7 has no importlib.metadata
 itsdangerous = "^2.1.2"
 aiofiles = "^23.1.0"
+pywebview = { version = "^4.0.2", optional = true }
+plotly = { version = "^5.13.0", optional = true }
+matplotlib = { version = "^3.5.0", optional = true }
+
+[tool.poetry.extras]
+native = ["pywebview"]
+plotly = ["plotly"]
+matplotlib = ["matplotlib"]
 
 [tool.poetry.group.dev.dependencies]
 icecream = "^2.1.0"

+ 6 - 3
website/documentation.py

@@ -1,6 +1,7 @@
 import uuid
 
 from nicegui import app, events, ui
+from nicegui.globals import optional_features
 
 from . import demo
 from .documentation_tools import element_demo, heading, intro_demo, load_demo, subheading, text_demo
@@ -130,9 +131,11 @@ def create_full() -> None:
     load_demo(ui.table)
     load_demo(ui.aggrid)
     load_demo(ui.chart)
-    load_demo(ui.pyplot)
-    load_demo(ui.line_plot)
-    load_demo(ui.plotly)
+    if 'matplotlib' in optional_features:
+        load_demo(ui.pyplot)
+        load_demo(ui.line_plot)
+    if 'plotly' in optional_features:
+        load_demo(ui.plotly)
     load_demo(ui.linear_progress)
     load_demo(ui.circular_progress)
     load_demo(ui.spinner)

Некоторые файлы не были показаны из-за большого количества измененных файлов