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

DEV-5295 | Replace poetry with uv #1638

Conversation

benjaminEwhite
Copy link
Contributor

@benjaminEwhite benjaminEwhite commented Oct 4, 2024

Please fill out each section even if it's just with "N/A"

Plan? (if this draft/incomplete indicate what you intend to do and how)

What's this PR do?

This PR replaces poetry with uv which is a Python package and project manager written in Rust that is very fast and well documented.

This PR makes the following changes:

  • Updates the pre-commit GH workflow, removing dependencies on Python and a poetry install step that do not appear to be needed.
  • Updates the test-python.yml GH workflow to use uv over poetry.
  • Updates .pre-commit-config.yaml to use a UV pre-commit action.
  • Updates Dockerfile to use uv instead of poetry (taking advantage of a uv docker image). Did a small amount of cleanup on Dockerfile to make more readable (and removed an unneeded step).
  • Updates Makefile to use uv instead of poetry
  • Updates README.md to reflect new package/project manager.

Why are we doing this? How does it help us?

uv is very fast, improves dev experience, and reduces complexity around virtual env management.

Are there detailed, specific, step-by-step testing instructions in the associated ticket?

Yes

Did this PR make changes to the user interface that may require changes to the user-facing docs?

No

Have automated unit tests been added? If not, why?

No. Not appropriate for this kind of change.

How should this change be communicated to end users?

N/A

Are there any smells or added technical debt to note?

No

Has this been documented? If so, where?

I created a confluence page to document the performance improvements vs. poetry

I also have drafted an updated version of our confluence page on updating revengine dependencies

What are the relevant tickets? Add a link to any relevant ones.

DEV-5295

Do any changes need to be made before deployment to production (adding environment variables, for example)? If so, open a ticket and link it to the ticket for this PR and list it here:

No

Are there next steps? If so, what? Have tickets been opened for them? List next-step tickets here:

No

@x110dc x110dc temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 15:59 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 17:40 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 20:51 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 21:12 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 21:44 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 21:50 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 23:27 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 23:38 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 23:44 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 4, 2024 23:55 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 5, 2024 00:02 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 5, 2024 00:05 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 5, 2024 00:51 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 5, 2024 01:02 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 7, 2024 21:14 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 7, 2024 21:29 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 7, 2024 21:32 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 7, 2024 21:34 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 7, 2024 23:42 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 8, 2024 00:39 Inactive
@benjaminEwhite benjaminEwhite changed the title DEV-5295 | First pass at using uv in revengine DEV-5295 | Replace poetry with uv Oct 8, 2024
@benjaminEwhite benjaminEwhite marked this pull request as ready for review October 8, 2024 00:42
.envrc.example Outdated Show resolved Hide resolved
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 8, 2024 00:42 Inactive
…t-for-poetry-pyenv' of github.com:newsrevenuehub/rev-engine into DEV-5295-5-project-proof-of-concept-of-uv-as-replacement-for-poetry-pyenv
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 8, 2024 12:00 Inactive
- name: Run tests
run: |
source .venv/bin/activate
touch .env
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't seem to have been needed.

" \
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This step does not appear to be required for our setup.

@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 8, 2024 13:09 Inactive
@benjaminEwhite benjaminEwhite temporarily deployed to rev-engine-dev-5295-5-p-lwko47 October 8, 2024 17:26 Inactive
@@ -23,3 +23,4 @@ export MAILCHIMP_CLIENT_SECRET=
export REACT_APP_HUB_GOOGLE_MAPS_API_KEY=
export REACT_APP_NRE_MAILCHIMP_CLIENT_ID=$MAILCHIMP_CLIENT_ID
export RP_MAILCHIMP_LIST_CONFIGURATION_COMPLETE_TOPIC=rp-mailchimp-list-configuration-complete
export VIRTUAL_ENV=".venv"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a comment as to what this is used by? [I don't see VIRTUAL_ENV referenced anywhere else]


##### Initial installation

Ensure you have a system version of Python and uv installed.
Copy link
Contributor

Choose a reason for hiding this comment

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

nm, it's clear from general uv link above

Consider adding description or link to how to install uv

@@ -1,4 +1,6 @@

VENV_DIR="./.venv"
Copy link
Contributor

Choose a reason for hiding this comment

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

Prepending superfluous "./" is weird.


setup:
@echo 'Setting up the environment...'
@test -d $(VENV_DIR) || uv venv $(VENV_DIR) && echo "Virtual environment created at $(VENV_DIR)"
source $(VENV_DIR)/bin/activate
Copy link
Contributor

Choose a reason for hiding this comment

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

source is bash built in (for me under ubuntu) and make is using sh. Thus

source "./.venv"/bin/activate
/bin/sh: 1: source: not found

Setting default shell wfm, copied from

https://stackoverflow.com/questions/7507810/how-to-source-a-script-in-a-makefile

Makefile default shell is /bin/sh which does not implement source.
Changing shell to /bin/bash makes it possible:

# Makefile

SHELL := /bin/bash

```

Adding or removing dependencies will automatically update the `pyproject.toml` file and the `poetry.lock` file.
Note that unlike Poetry, uv does not automatically update the `pyproject.toml` file and `uv.lock` files after adding/removing dependencies. You'll want to manually add/remove from `pyproject.toml` and you'll want to run `uv lock` to update the lockfile.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would cut "unlike Poetry, "

Also consider moving this to top of section, under ### How to... [reckon it's harder to miss there].


install_requirements:
@echo 'Installing project requirements...'
poetry install --no-root
uv sync --frozen

setup:
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the method to "start work" is source $(VENV_DIR)/bin/activate. It would be nice to have make entry for this

activate:
source $(VENV_DIR)/bin/activate
python --version

I miss poetry shell (or rather vex) there's workarounds astral-sh/uv#1910


- name: Set up Python and dependencies
run: |
uv venv create --python=python3.10
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have "upgrade python docs"? If so should add mention to look here and in Dockerfile to update python versions.

@@ -48,15 +48,31 @@ repos:
hooks:
- id: ruff
args: [ --fix ]
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.4.18
Copy link
Contributor

Choose a reason for hiding this comment

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

The installer gave me version 0.4.20.

Leo and I have this problem with ruff. They upgrade it so frequently, often occurs between dev and review.

# We need to recreate the /usr/share/man/man{1..8} directories first because
# they were clobbered by a parent image.
# Copy uv tool
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
Copy link
Contributor

Choose a reason for hiding this comment

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

latest is probably easier than updating specific version all the time?

"responses>=0.25.3",
"ruff>=0.6.8",
]

# TODO @njh: reduce complexity to 10 or less
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should go with [tool.ruff.lint.mccabe] section

[tool.uv] was inserted in-between

@benjaminEwhite
Copy link
Contributor Author

Closing this PR because it's served purpose as PoC and we've decided not to move forward with uv in revengine just yet.

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 this pull request may close these issues.

3 participants