posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.82k stars 91 forks source link

Python fastapi app is not working on windows #5312

Open jonvanausdeln opened 1 week ago

jonvanausdeln commented 1 week ago

System details:

Positron and OS details:

Positron 2024.11.0-140 Windows 11

Interpreter details:

Python 3.10.10, but also shows in other versions

Describe the issue:

Fastapi apps are not working on windows.

Steps to reproduce the issue:

  1. Open a simple fastapi app, such as this one
  2. Use the RunApp button in positron
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'

Expected or desired behavior:

App to startup as it does on other platforms.

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

!! QA NOTES !!

Once fixed turn back on fastapi test for windows.

sharon-wang commented 1 week ago

From https://github.com/posit-dev/positron/issues/4949#issuecomment-2402325643:

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.

sharon-wang commented 1 week ago

This test is failing in the prerelease/2024.11 branch -- we may want to backport the Windows test skip to the branch, but probably not critical since I don't think we have automated tests for the patch branch?

jonvanausdeln commented 1 week ago

This test is failing in the prerelease/2024.11 branch -- we may want to backport the Windows test skip to the branch, but probably not critical since I don't think we have automated tests for the patch branch?

Yeah, we have to manually kick off runs on the release branch (for now). But a good idea to backport the skip. I'll do that later today.