mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
Fix reload mode (#2992)
* Fix reload mode * Add unit test * Add to changelog
This commit is contained in:
parent
8176d9496b
commit
5c32ba31ba
@ -4,7 +4,7 @@
|
||||
No changes to highlight.
|
||||
|
||||
## Bug Fixes:
|
||||
No changes to highlight.
|
||||
* Fix relative import bug in reload mode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2992](https://github.com/gradio-app/gradio/pull/2992)
|
||||
|
||||
## Documentation Changes:
|
||||
No changes to highlight.
|
||||
|
@ -24,11 +24,11 @@ def run_in_reload_mode():
|
||||
demo_name = args[1]
|
||||
|
||||
original_path = args[0]
|
||||
abs_original_path = Path(original_path).name
|
||||
path = str(Path(original_path).resolve())
|
||||
abs_original_path = Path(original_path).resolve()
|
||||
path = os.path.normpath(original_path)
|
||||
path = path.replace("/", ".")
|
||||
path = path.replace("\\", ".")
|
||||
filename = Path(path).stem
|
||||
filename = os.path.splitext(path)[0]
|
||||
|
||||
gradio_folder = Path(inspect.getfile(gradio)).parent
|
||||
|
||||
@ -48,7 +48,7 @@ def run_in_reload_mode():
|
||||
message += f" '{gradio_folder}'"
|
||||
message_change_count += 1
|
||||
|
||||
abs_parent = Path(abs_original_path).parent
|
||||
abs_parent = abs_original_path.parent
|
||||
if str(abs_parent).strip():
|
||||
command += f'--reload-dir "{abs_parent}"'
|
||||
if message_change_count == 1:
|
||||
|
20
test/test_reload.py
Normal file
20
test/test_reload.py
Normal file
@ -0,0 +1,20 @@
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import gradio
|
||||
from gradio.reload import run_in_reload_mode
|
||||
|
||||
|
||||
@patch("gradio.reload.os.system")
|
||||
@patch("gradio.reload.sys")
|
||||
def test_run_in_reload_mode(mock_sys, mock_system_call):
|
||||
|
||||
mock_sys.argv = ["gradio", "demo/calculator/run.py"]
|
||||
run_in_reload_mode()
|
||||
reload_command = mock_system_call.call_args[0][0]
|
||||
gradio_dir = Path(gradio.__file__).parent
|
||||
demo_dir = Path("demo/calculator/run.py").resolve().parent
|
||||
|
||||
assert "uvicorn demo.calculator.run:demo.app" in reload_command
|
||||
assert f'--reload-dir "{gradio_dir}"' in reload_command
|
||||
assert f'--reload-dir "{demo_dir}"' in reload_command
|
Loading…
Reference in New Issue
Block a user