Skip to content

Conversation

@alexrudd2
Copy link
Collaborator

@alexrudd2 alexrudd2 commented Aug 8, 2025

uv is to pip and venv what ruff is to pyflakes and black - faster and better in every way.

It greatly speeds up dependency resolution and install, and eliminates the fuss of activating venv on Windows (which I remember was quite fun to setup for @janiversen ... )

The dependency setup with a cache miss is <2s, which is nearly as fast as a cache hit with the existing solution.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

Looks like a nice change, but it seems uv is not ready to meet codespell.

@janiversen
Copy link
Collaborator

Feel free to exclude lock files in pyproject.toml.

doc/build_html Outdated
popd

sphinx-build -M html "." "../build/html"
if command -v uv &> /dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change could be made a lot easier in ci.yml line 74 without any side effects.

Copy link
Collaborator Author

@alexrudd2 alexrudd2 Aug 8, 2025

Choose a reason for hiding this comment

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

(1) No, since the call to sphinx-build is in build_html. It would fail without uv run (or activating the venv)
(2) By doing it this way it can work either with or without uv in either CI or locally.

I'm not ready to propose switching over the entire project yet. (e.g. python -m build -> uv build and some pyproject.toml changes)

Copy link
Collaborator

@janiversen janiversen Aug 8, 2025

Choose a reason for hiding this comment

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

if you put uv in front of build_html it should activate the venv which will then be handed to sphinx.

Switching the whole project to uv, will not happen in a long time, since that would e.g. invalidate the use of work on to easily change environments.

Copy link
Collaborator Author

@alexrudd2 alexrudd2 Aug 8, 2025

Choose a reason for hiding this comment

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

if you put uv in front of build_html it should activate the venv which will then be handed to sphinx.

You know I try things before writing you, right? :)

Switching the whole project to uv, will not happen in a long time, since that would e.g. invalidate the use of work on to easily change environments.

I'm not sure what exactly you mean here, but in my trials with uv it makes switching environments easier. It's not perfect but I added this to ~/.bashrc and it works pretty well:

# https://dev.to/moniquelive/auto-activate-and-deactivate-python-venv-using-zsh>
python_venv() {
  MYVENV=./.venv
  # when you cd into a folder that contains $MYVENV
  [[ -d $MYVENV ]] && source $MYVENV/bin/activate > /dev/null 2>&1 && uv sync ->
  # when you cd into a folder that doesn't
  [[ ! -d $MYVENV ]] && deactivate > /dev/null 2>&1
}

PROMPT_COMMAND="python_venv; $PROMPT_COMMAND"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I expected you to try before writing, however if I run "workon" before calling build_html it uses the environment assigned, so I do not understand what the problem is with running "uv" before the build_html command. venv is normally inherited across shell sessions.

your python_env function have one floor, I have at the moment 8 different venv, and when I login to my vm, I start by "workon ".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting, this is my first hearing of workon.

For the CI, uv sync creates a venv, but does not activate it. So I had to activate it.

I think this is resolved to your satisfaction? build_html is untouched compared to dev.

@alexrudd2 alexrudd2 requested a review from janiversen August 8, 2025 18:58
Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

Thanks a lot, this seems to be a very GOOD solution.

I am sorry, that I had to "correct" you, your PR´s and comments are HIGHLY valued, but I also need to think of the consequences.

I am sure you will find an elegant solution for build_html as well.

@janiversen janiversen merged commit ef9fecc into pymodbus-dev:dev Aug 8, 2025
1 check passed
@alexrudd2 alexrudd2 deleted the uv branch August 8, 2025 22:08
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.

2 participants