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

Add uv as package manger for the generated project #5434

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

foarsitter
Copy link
Collaborator

@foarsitter foarsitter commented Oct 6, 2024

The project itself now uses uv and this is an attempt to bring uv to the generated project too.

  • Python commands are executed through uv run for local development. In Docker the .venv python interpreter is added to the $PATH so packages can be used system wide.
  • The uv.lock file is empty on start because is is updated when uv sync is executed.
  • For Heroku I added a pre-commit that compiles a requirements.txt
  • Added a trap to test_docker.sh to cleanup after testing so the next time will no fail due to an existing postgres volume.
  • In test_docker.sh I added a step to test building the docker production image

Before we can merge this we need one last round to update all the versions to the latest ones in the requirement.txt files.

@foarsitter foarsitter changed the title Uv generated project Add uv as package manger for the generated project Oct 7, 2024
@foarsitter
Copy link
Collaborator Author

Related to #3083 #1988

@foarsitter foarsitter force-pushed the uv-generated-project branch 2 times, most recently from bd785eb to 6bae8e7 Compare October 26, 2024 09:48
@foarsitter foarsitter marked this pull request as ready for review October 26, 2024 15:08
@foarsitter
Copy link
Collaborator Author

foarsitter commented Oct 26, 2024

Ready for testing 🎉

cookiecutter https://github.com/foarsitter/cookiecutter-django --checkout uv-generated-project

@foarsitter foarsitter force-pushed the uv-generated-project branch from 8f3ca43 to d12c2e7 Compare October 27, 2024 08:17
Copy link
Member

@browniebroke browniebroke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a first pass and noted a few things. Haven't reviewed the Dockerfiles yet

{{cookiecutter.project_slug}}/pyproject.toml Outdated Show resolved Hide resolved
{{cookiecutter.project_slug}}/pyproject.toml Outdated Show resolved Hide resolved
{{cookiecutter.project_slug}}/.pre-commit-config.yaml Outdated Show resolved Hide resolved
@steveputman
Copy link
Contributor

Hi, there. I played around with using your fork to update some existing projects and eventually got them working but ended up reverting them to their production (pip) versions so that I could revisit when I had more time.

When working on an adapting an existing project, I got an error during the build, which was reproduced when I built a project from scratch using cookiecutter https://github.com/foarsitter/cookiecutter-django --checkout uv-generated-project:

[django python-build-stage 4/6] RUN --mount=type=cache,target=/root/.cache/uv --mount=type=bind,source=uv.lock,target=uv.lock --mount=type=bind,source=pyproject.toml,target=pyproject.toml uv sync --frozen --no-install-project --no-dev:
0.112 Using CPython 3.12.7 interpreter at: /usr/local/bin/python
0.112 Creating virtual environment at: .venv
0.113 error: Could not find root package my-awesome-project
'

I believe that it's caused by having the blank uv.lock. I thought since the local project had the host file rw that it would generate a usable uv.lock during the local build. Is there a way to get a usable version of uv.lock on the host filesystem without running uv sync on the host filesystem? Thanks for this--very cool!

@foarsitter
Copy link
Collaborator Author

@steveputman thanks looking into this!

During a build you cannot write to the host system.

Your interpreter is inside the container together with uv so you can run uv:

docker compose -f docker-compose.local.yml run django uv lock

Struggled a lot with this and it is not ideal. So hopefully someone has a better solution.

@steveputman
Copy link
Contributor

@foarsitter
The Docker documentation was sort of vague on that, but now I know.

Your solution is better than mine (I had uv installed on my host system so just ran uv lock in the project directory.

Thanks for the help! Will let you know if anything else comes up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants