posit-dev / positron

Positron, a next-generation data science IDE
Other
2.56k stars 80 forks source link

Fastapi display in viewer does not work on Ubuntu #4949

Open testlabauto opened 1 week ago

testlabauto commented 1 week ago

System details:

Positron and OS details:

Ubuntu 24.04 Positron 2024.11.0 build 16

Interpreter details:

Python 3.10.12

Describe the issue:

The fastapi_example from qa-example-content does not render in the Viewer on Ubuntu.

Steps to reproduce the issue:

  1. Clone qa-example-content
  2. Run fastapi_example
  3. Note that the viewer url shows http://127.0.0.1:8000/docs but nothing is displayed

Expected or desired behavior:

FastAPI example works

Were there any error messages in the UI, Output panel, or Developer Tools console?

Uncaught SyntaxError: Identifier 'hostMessaging' has already been declared

testlabauto commented 1 week ago

FYI @seeM @isabelizimm

jonvanausdeln commented 1 week ago

On my windows box I get

C:\Users\JonVanausdeln\source\qa-example-content [main ≡ +0 ~1 -0 !]> C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\python.exe -m uvicorn --reload workspaces/python_apps/fastapi_example.fastapi_example:app
INFO:     Will watch for changes in these directories: ['C:\\Users\\JonVanausdeln\\source\\qa-example-content']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [5648] using WatchFiles
Process SpawnProcess-1:
Traceback (most recent call last):
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\multiprocessing\process.py", line 314, in _bootstrap
    self.run()
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\_subprocess.py", line 80, in subprocess_started
    target(sockets=sockets)
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\runners.py", line 118, in run    
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\server.py", line 69, in serve
    await self._serve(sockets)
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\server.py", line 76, in _serve
    config.load()
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\config.py", line 434, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\importer.py", line 22, in import_from_string
    raise exc from None
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\site-packages\uvicorn\importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\JonVanausdeln\.pyenv\pyenv-win\versions\3.12.2\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'workspaces/python_apps/fastapi_example'
seeM commented 1 week ago

@jonvanausdeln this looks like a separate Windows-specific issue where our conversion from a file path (workspaces/python_apps/fastapi_example/fastapi_example.py) to a Python module import path (workspaces.python_apps.fastapi_example.fastapi_example) is not working as expected.

I'm not yet sure what's happening in the Ubuntu case.

jonvanausdeln commented 1 week ago

@seeM , should I open a separate issue for windows?

seeM commented 1 week ago

@jonvanausdeln yes I think so