Skip to content

Add support for running python projects#4142

Merged
mitchdenny merged 33 commits intomicrosoft:mainfrom
wmeints:python-hosting-support
Jun 26, 2024
Merged

Add support for running python projects#4142
mitchdenny merged 33 commits intomicrosoft:mainfrom
wmeints:python-hosting-support

Conversation

@wmeints
Copy link
Copy Markdown
Contributor

@wmeints wmeints commented May 10, 2024

This PR introduces support for running Python projects as part of an Aspire solution. I took the NodeJS extension as inspiration but had to add a couple of extra pieces of logic since Python is a lot less standardized when it comes to how projects are structured.

Initially I created this project: https://github.com/wmeints/aspire-python but I feel that this PR is a much more useful way to add support for Python. I think it's a great resolution for #2760.

Assumptions made by the extension

  • Your python project has a virtual environment located under .venv. Although you can change that.
  • You have a Dockerfile for publishing the project to test/acceptance/production environments.

@ghost ghost added the area-integrations Issues pertaining to Aspire Integrations packages label May 10, 2024
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 10, 2024
Comment thread Aspire.sln
Comment thread playground/python/Python.AppHost/Program.cs Outdated
Comment thread src/Aspire.Hosting.Python/FlaskProjectResourceExtensionBuilder.cs Outdated
@mitchdenny
Copy link
Copy Markdown
Member

@davidfowl I've been thinking about things like Node.js (and now Python). I'm wondering if whether to make things easier for people we should create a boilerplate Dockerfile if one doesn't already exist. The idea being that it gives people a starting point.

So if someone does AddPython...) and points at a particular directory we'll drop down a Dockerfile and .dockerignore file if one doesn't already exist. Then the can tweak it from there customizing the base image etc.

@davidfowl
Copy link
Copy Markdown
Contributor

I don't think we should be writing files to disk using these APIs, but I like the idea that they would publish as a docker file by default. The publish operation would throw because it couldn't find one. That would instruct the user to add one for their language.

Comment thread src/Aspire.Hosting.Python/FlaskProjectResourceExtensionBuilder.cs Outdated
Comment thread tests/Aspire.Hosting.Tests/Python/AddPythonProjectTests.cs Outdated
Comment thread src/Aspire.Hosting.Python/PythonProjectResource.cs Outdated
@wmeints
Copy link
Copy Markdown
Contributor Author

wmeints commented May 13, 2024

I can see I broke the build because I forgot to update the playground apphost. I will do that tomorrow morning (GMT+1)

Comment thread tests/Aspire.Hosting.Tests/Python/AddPythonProjectTests.cs Outdated
Comment thread src/Aspire.Hosting.Python/VirtualEnvironment.cs Outdated
Comment thread src/Aspire.Hosting.Python/PythonProjectResource.cs Outdated
@wmeints wmeints force-pushed the python-hosting-support branch from 0f772cc to 30c850f Compare May 30, 2024 04:54
Comment thread src/Aspire.Hosting.Python/PythonProjectResourceBuilderExtensions.cs
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny
Copy link
Copy Markdown
Member

@radical I think we need to kick the tests in Aspire.Hosting.Tests that were recently enabled for CI back to local only until we can fix the issue of the port conflicts.

@mitchdenny
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread tests/Aspire.Hosting.Tests/Python/AddPythonProjectTests.cs Outdated
Comment thread tests/Aspire.Hosting.Tests/Python/AddPythonProjectTests.cs Outdated
Comment thread tests/Aspire.Hosting.Tests/Python/AddPythonProjectTests.cs Outdated
@mitchdenny
Copy link
Copy Markdown
Member

/azp run

1 similar comment
@mitchdenny
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny
Copy link
Copy Markdown
Member

@wmeints thanks so much for your contribution to .NET Aspire. We'll be shipping your work in .NET Aspire 8.1!

@dotnet-bot
Copy link
Copy Markdown
Contributor

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Aspire.StackExchange.Redis Branch 42 41.35 🔻

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=720670&view=codecoverage-tab

@mitchdenny mitchdenny merged commit 1227690 into microsoft:main Jun 26, 2024
@wmeints
Copy link
Copy Markdown
Contributor Author

wmeints commented Jun 26, 2024

Excited to see this appear in 8.1! And thanks again for all the reviews and patience. I learned a lot from this experience. I'm coming back for more 😄

@wmeints wmeints deleted the python-hosting-support branch June 26, 2024 06:34
@mitchdenny
Copy link
Copy Markdown
Member

@wmeints I'm writing up the blog post for .NET Aspire 8.1 are you happy for me to link to your GitHub profile for this contribution?

@wmeints
Copy link
Copy Markdown
Contributor Author

wmeints commented Jul 15, 2024

@mitchdenny Feel free to link my profile in the blogpost :-)

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants