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

Use uv/hatch instead of Poetry #3039

Merged
merged 26 commits into from
Feb 17, 2025
Merged

Use uv/hatch instead of Poetry #3039

merged 26 commits into from
Feb 17, 2025

Conversation

mquinnfd
Copy link
Contributor

@mquinnfd mquinnfd commented Jan 29, 2025

Tracking WIP towards replacing poetry with uv/Hatch (and maybe ditching tox at the same time)

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@mquinnfd
Copy link
Contributor Author

Just for visibility, I'm working from this draft PR here https://github.com/locustio/locust/pull/3039/files

  • Poetry etc. switched to hatch/uv
  • Dynamic versioning stuff working OK locally
  • Local build with front end compilation working
  • Started moving tox targets over to hatch envs
  • Running existing tests via pytest (which was already added) plus coverage

Probably going to be next week before I tackle the pipeline, as this takes longer generally, but I'd say it's going well 🥳

@mquinnfd mquinnfd changed the title WIP: Poetry to UV/Hatch Poetry to UV/Hatch Feb 3, 2025
@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 3, 2025

Ok the CI is fully green on this 🚀 💯
This is supposed to be a like-for-like, same logic applies with re-using the same build throughout the CI/CD process

Things done:

  • poetry moved to uv/hatch
  • tox moved to hatch test environments
  • Dynamic versioning with hatch-vcs
  • Existing tests now run with pytest
  • Pre build runs as hatch hook
  • Dockerfiles etc. updated
  • ReadTheDocs config updated and build green

Things not done:

  • Update documentation and Makefile
  • Sand down rough edges on pipeline
  • Add pipeline caching where possible
  • Try and parallelise tests for fun
  • Test release process (none of these steps changed though)
  • Reinstate failing "date" tests

@cyberw
Copy link
Collaborator

cyberw commented Feb 4, 2025

Looks grand! Going through the code now!

cache: 'yarn'
cache-dependency-path: locust/webui/yarn.lock
# cache: 'yarn'
# cache-dependency-path: locust/webui/yarn.lock
Copy link
Collaborator

Choose a reason for hiding this comment

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

What was the reason to change this? (this is probably mostly @andrewbaldwin44 's area :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm gonna reinstate this --- it was originally breaking something but it's on my TODO listed here: #3039 (comment)


- run: uv venv --python 3.11
Copy link
Collaborator

Choose a reason for hiding this comment

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

setting version here is probably redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I believe this was maybe because the original CI is running under 3.11 at a basic level, if we don't specify, I think it will default to 3.12 ---

Whatever you wanna pick I'd just like to make sure that's the same everywhere that doesn't have a specific version required

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it default to the version installed by actions/setup-python (specified on line 38)?

If it does default to that then I prefer not specifying it again, as someone is bound to forget to update both places :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good shout, I'll start taking a note of these on the TODO

@cyberw
Copy link
Collaborator

cyberw commented Feb 4, 2025

Hmm... I just did uv sync and uv run locust locally but got this. Does it work for you?

❯ uv run locust
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.11`.
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/lars/git/locust/locust/__main__.py", line 1, in <module>
    from .main import main
ImportError: attempted relative import with no known parent package

Activating the venv and running locust directly works fine.

❯ . .venv/bin/activate
❯ locust
Could not find 'locustfile.py'. Ensure your locustfile ends with '.py' or is a directory with locustfiles. See --help for available options.

@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 4, 2025

@cyberw yes - running locust as it is installed into the venv works fine

The reason uv run <stuff> doesn't is down to the relative paths used in the project, you'd need to run it from the locust directory to run it with uv run

For example, this works: uv --directory locust run locust

@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 4, 2025

I guess I still have @andrewbaldwin44 's comments about poetry run bouncing around my head - less of this stuff the better right (?)

@cyberw
Copy link
Collaborator

cyberw commented Feb 4, 2025

@cyberw yes - running locust as it is installed into the venv works fine

The reason uv run <stuff> doesn't is down to the relative paths used in the project, you'd need to run it from the locust directory to run it with uv run

For example, this works: uv --directory locust run locust

How come it worked for poetry? Can we fix how we use relative paths?

We've gotten some other semi-related complaints too: https://github.com/orgs/locustio/discussions/3040

@cyberw
Copy link
Collaborator

cyberw commented Feb 4, 2025

If I fix the issues with html.py (by temporarily modifying sys.path to not include locust), I can change the import in __main__.py to from locust.main import main. Maybe that is the appropriate solution? (and then later rename the html.py module)

@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 5, 2025

This is similar to what I do in my projects ---
Everything is imported from that root, in this case, the locust module. You might need to add the locust folder to the extra analysis paths in VS Code etc.
Imports are locust.blah.blah in all cases, no relative imports.

As you said, doing that just requires the package base (locust) to be on the Python path --- we can change this if you're up for it, was just going for like-for-like currently.

@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 5, 2025

Up to you, I could do this on a branch-of-this-branch and take a look at how it feels I guess, it's obviously a bigger, potentially breaking change

I'm not sure if poetry does some sneaky stuff with the path in it's "run this script" command, it's entirely possible 🤔

I was hoping the uv run command would have some sort of config-level override for directory, rather than a flag, but I can't really see it in the docs 🤔

@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 5, 2025

@cyberw yes - running locust as it is installed into the venv works fine
The reason uv run <stuff> doesn't is down to the relative paths used in the project, you'd need to run it from the locust directory to run it with uv run
For example, this works: uv --directory locust run locust

How come it worked for poetry? Can we fix how we use relative paths?

We've gotten some other semi-related complaints too: https://github.com/orgs/locustio/discussions/3040

This makes sense, maybe it would avoid this type of issue also, using absolute paths

@cyberw
Copy link
Collaborator

cyberw commented Feb 5, 2025

If I fix the issues with html.py (by temporarily modifying sys.path to not include locust), I can change the import in main.py to from locust.main import main. Maybe that is the appropriate solution? (and then later rename the html.py module)

I will fix that, once this PR has been merged (if this is enough, I prefer not making a bigger change)

@mquinnfd mquinnfd marked this pull request as ready for review February 8, 2025 21:57
@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 8, 2025

Hey @cyberw this should be good for a review.
I reintroduced caching, updated the docs to remove poetry and tox steps, cleaned up the Makefile etc. as well.

Couple things

  • Docs steps could be subjective? If they're unclear happy to change
  • I left this in currently from your original helpful paste, I'm not sure if we need it 🤔 and I'm not sure what scenario to use to test this
  • I don't think this should affect the publishing step at all

It's shaving 2-3 mins off the e2e CI runs as well which is nice 🥳 new vs old


.. code-block:: console
$ tox
$ hatch run +py=3.10 test:all
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess there's no direct equivalent, that runs all versions in one invocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically we should be able to wrap it up in hatch test re: this

Originally this seemed to just break when collecting tests with pytest - hatch test just appears to be a way of calling pytest specifically

I'll mess around with it and see if I can get it to work


.. code-block:: console
$ pytest -vv locust/test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it really make sense to add -vv everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary 👍 it's just a tad easier to see what specific tests are breaking during execution, can just omit this by default

@cyberw
Copy link
Collaborator

cyberw commented Feb 9, 2025

Awesome! Apart from those two nit-picks, I think we're good to go!

Docs steps could be subjective? If they're unclear happy to change

Sorry, I dont quite follow? Anyway, I didn't see anything that looked terrible :) And docs are easy to fix "later"...

@mquinnfd
Copy link
Contributor Author

mquinnfd commented Feb 9, 2025

Awesome! Apart from those two nit-picks, I think we're good to go!

Docs steps could be subjective? If they're unclear happy to change

Sorry, I dont quite follow? Anyway, I didn't see anything that looked terrible :) And docs are easy to fix "later"...

Nothing in particular 🥳
Documentation anxiety 😆

@mquinnfd
Copy link
Contributor Author

Updated this again, I've layered some of the hatch environments a bit to leverage the default "hatch test" environment

The result is that:

  • contributors can just call hatch test locally (and make use of the CLI options this wraps)
  • the CI targets will still run hatch run test:all because this allows us to keep the matrix option there rather than mixing multiple CLI calls

@cyberw
Copy link
Collaborator

cyberw commented Feb 14, 2025

Looking real good! In your perspective, is it good enough to merge?

Let me know a time that works for you (I know the builds are working on your branch, but only merging to master will tell us for sure that the pypi/docker upload still works and gets the right versions :)

@mquinnfd
Copy link
Contributor Author

Looking real good! In your perspective, is it good enough to merge?

Let me know a time that works for you (I know the builds are working on your branch, but only merging to master will tell us for sure that the pypi/docker upload still works and gets the right versions :)

I'm with you, this is everything obvious I can think of, it just needs ironed out in prerelease now

I'll be around here and there at the weekend, but I can set aside time on Monday to play whack-a-mole if that works?

@cyberw
Copy link
Collaborator

cyberw commented Feb 14, 2025

I'll be around here and there at the weekend, but I can set aside time on Monday to play whack-a-mole if that works?

Monday sounds great!

@cyberw
Copy link
Collaborator

cyberw commented Feb 15, 2025

I keep getting this warning:

warning: No `requires-python` value found in the workspace. Defaulting to `>=3.13`.

Probably we just need to add requires-python = ">=3.9" to [project]

@mquinnfd
Copy link
Contributor Author

I keep getting this warning:

warning: No `requires-python` value found in the workspace. Defaulting to `>=3.13`.

Probably we just need to add requires-python = ">=3.9" to [project]

Yeah I think that's it, I'll stick that in the config.
I'm around whenever today btw 👋

@cyberw
Copy link
Collaborator

cyberw commented Feb 17, 2025

Cool! I’ll hit merge in about 5 minutes :)

@cyberw cyberw merged commit 496fc3d into locustio:master Feb 17, 2025
17 checks passed
@cyberw cyberw changed the title Poetry to UV/Hatch Use uv/hatch instead of Poetry Feb 17, 2025
@cyberw cyberw mentioned this pull request Feb 17, 2025
2 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 this pull request may close these issues.

None yet

2 participants