Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddUvicornApp doesn't use uvicorn from the virtual environment #545

Open
dluc opened this issue Mar 7, 2025 · 1 comment · May be fixed by #546
Open

AddUvicornApp doesn't use uvicorn from the virtual environment #545

dluc opened this issue Mar 7, 2025 · 1 comment · May be fixed by #546

Comments

@dluc
Copy link

dluc commented Mar 7, 2025

Describe the bug

Trying to launch a python service from Aspire using AddUvicornApp(), the launch fails with:

ModuleNotFoundError: No module named 'redis'

When I launch the python service manually, using poetry run uvicorn app.main:app everything works fine instead.

I found that the different behavior is because AddUvicornApp uses uvicorn (and python) from the host, rather than the one inside .venv:

Manual => poetry run uvicorn app.main:app => Ok
AddUvicornApp => uvicorn app.main:app => Fail

Could you change the implementation to allow using uvicorn from the virtual env (.venv dir)?

Regression

No response

Steps to reproduce

Create app with Poetry, add a dependency missing in the host, integrate the service using `AddUvicornApp`. The app crashes.

Expected behavior

AddUvicornApp should leverage uvicorn from the app .venv folder

Screenshots

No response

IDE and version

Other

IDE version

CLI

Nuget packages

Aspire.Hosting.AppHost 9.1.0
CommunityToolkit.Aspire.Hosting.Python.Extensions 9.2.1

Additional context

No response

Help us help you

No, just wanted to report this

@dluc
Copy link
Author

dluc commented Mar 7, 2025

This change to private ... AddUvicornApp(...) method should be sufficient:

From:

var instrumentationExecutable = virtualEnvironment.GetExecutable("opentelemetry-instrument");
var projectExecutable = instrumentationExecutable ?? "uvicorn";

To:

var instrumentationExecutable = virtualEnvironment.GetExecutable("opentelemetry-instrument");
var uvicornExecutable = virtualEnvironment.GetExecutable("uvicorn") ?? "uvicorn";
var projectExecutable = instrumentationExecutable ?? uvicornExecutable;

dluc added a commit to dluc/AspireCommunityToolkit that referenced this issue Mar 7, 2025
@dluc dluc linked a pull request Mar 7, 2025 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant