Browse Source

code review

Falko Schindler 1 year ago
parent
commit
4611c48cdc

+ 1 - 12
nicegui/globals.py

@@ -4,18 +4,7 @@ import logging
 from contextlib import contextmanager
 from enum import Enum
 from pathlib import Path
-from typing import (
-    TYPE_CHECKING,
-    Any,
-    Awaitable,
-    Callable,
-    Dict,
-    Iterator,
-    List,
-    Optional,
-    Set,
-    Union,
-)
+from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Iterator, List, Optional, Set, Union
 
 from socketio import AsyncServer
 from uvicorn import Server

+ 3 - 1
nicegui/run.py

@@ -11,8 +11,9 @@ import uvicorn
 from uvicorn.main import STARTUP_FAILURE
 from uvicorn.supervisors import ChangeReload, Multiprocess
 
-from . import globals, helpers, native_mode
+from . import globals, helpers
 from . import native as native_module
+from . import native_mode
 from .air import Air
 from .language import Language
 
@@ -79,6 +80,7 @@ def run(*,
     :param uvicorn_reload_includes: string with comma-separated list of glob-patterns which trigger reload on modification (default: `'.py'`)
     :param uvicorn_reload_excludes: string with comma-separated list of glob-patterns which should be ignored for reload (default: `'.*, .py[cod], .sw.*, ~*'`)
     :param tailwind: whether to use Tailwind (experimental, default: `True`)
+    :param development: whether to use the development version of Vue and Quasar dependencies (default: `True`)
     :param storage_secret: secret key for browser based storage (default: `None`, a value is required to enable ui.storage.individual and ui.storage.browser)
     :param kwargs: additional keyword arguments are passed to `uvicorn.run`    
     '''

+ 4 - 1
nicegui/run_with.py

@@ -18,6 +18,8 @@ def run_with(
     language: Language = 'en-US',
     binding_refresh_interval: float = 0.1,
     mount_path: str = '/',
+    tailwind: bool = True,
+    development: bool = True,
     storage_secret: Optional[str] = None,
 ) -> None:
     globals.ui_run_has_been_called = True
@@ -27,7 +29,8 @@ def run_with(
     globals.dark = dark
     globals.language = language
     globals.binding_refresh_interval = binding_refresh_interval
-    globals.tailwind = True
+    globals.tailwind = tailwind
+    globals.development = development
 
     set_storage_secret(storage_secret)
     app.on_event('startup')(lambda: handle_startup(with_welcome_message=False))

+ 1 - 1
nicegui/templates/index.html

@@ -15,7 +15,7 @@
     {% if tailwind %}
     <script src="{{ prefix | safe }}/_nicegui/{{version}}/static/tailwindcss.min.js"></script>
     {% endif %}
-
+    <!-- prevent Prettier from removing this line -->
     {% if development %}
     <script src="{{ prefix | safe }}/_nicegui/{{version}}/static/vue.global.js"></script>
     <script src="{{ prefix | safe }}/_nicegui/{{version}}/static/quasar.umd.js"></script>

+ 0 - 21
tests/test_dependency_dev_mode.py

@@ -1,21 +0,0 @@
-from nicegui import __version__
-
-from .screen import Screen
-
-
-def test_dev_mode(screen: Screen) -> None:
-    screen.ui_run_kwargs['development'] = True
-    screen.open('/')
-
-    #! probably doesn't work!
-    screen.should_contain(f'<script src="/_nicegui/{__version__}/static/vue.global.js"></script>')
-    screen.should_contain(f'<script src="/_nicegui/{__version__}/static/quasar.umd.js"></script>')
-
-
-def test_prod_mode(screen: Screen):
-    screen.ui_run_kwargs['development'] = False
-    screen.open('/')
-
-    #! probably doesn't work!
-    screen.should_contain(f'<script src="/_nicegui/{__version__}/static/vue.global.prod.js"></script>')
-    screen.should_contain(f'<script src="/_nicegui/{__version__}/static/quasar.umd.prod.js"></script>')

+ 19 - 0
tests/test_development_mode.py

@@ -0,0 +1,19 @@
+from selenium.webdriver.common.by import By
+
+from nicegui import __version__
+
+from .screen import Screen
+
+
+def test_dev_mode(screen: Screen) -> None:
+    screen.ui_run_kwargs['development'] = True
+    screen.open('/')
+    screen.selenium.find_element(By.XPATH, f'//script[@src="/_nicegui/{__version__}/static/vue.global.js"]')
+    screen.selenium.find_element(By.XPATH, f'//script[@src="/_nicegui/{__version__}/static/quasar.umd.js"]')
+
+
+def test_prod_mode(screen: Screen):
+    screen.ui_run_kwargs['development'] = False
+    screen.open('/')
+    screen.selenium.find_element(By.XPATH, f'//script[@src="/_nicegui/{__version__}/static/vue.global.prod.js"]')
+    screen.selenium.find_element(By.XPATH, f'//script[@src="/_nicegui/{__version__}/static/quasar.umd.prod.js"]')