Skip to content

Add WithPythonUvEnvironment to Python extension builder in Aspire.Hosting.Python #11934

Description

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

The Aspire.Hosting.Python package needs a way of adding a UV-managed virtual environment with dependencies to the PythonAppResource.

This can be done with an extension method to the builder patterns in PythonAppResourceBuilderExtensions called WithPythonUvEnvironment.

Describe the solution you'd like

The method should take any PythonAppResource and attach a child resource which runs the uv sync command in the working directory of the Python app to ensure that the virtual environment exists.

The API for this would be:

        public static IResourceBuilder<T> WithPythonUvEnvironment<T>(this IResourceBuilder<T> builder)
        where T : PythonAppResource

This new resource runs uv sync in the working directory of the Python App Resource for which it was attached. This uv sync command is done via the existing Executable Resource infrastructure.

Behaviours:

  1. The name of this new resource is the python app resource name with -uv-environment suffixed, i.e. $"{builder.Resource.Name}-uv-environment
  2. This new resource is a new standalone resource class, PythonUvEnvironmentResource
  3. This new UV resource adds the Python app resource as a parent and sets a WaitForCompletion relationship to the parent so that the uv sync command must complete successfully before the PythonAppResource can be started. This ensure that the virtual environment exists and the dependencies are installed before the Python app is started.
  4. If the uv sync command fails, it should fail the resource and the parent Python App resource will fail to start.

Additional context

No response

Metadata

Metadata

Assignees

Labels

area-integrationsIssues pertaining to Aspire Integrations packagespython

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions