Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 16 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,75 +54,49 @@ jobs:
- name: Checkout repo from github
uses: actions/[email protected]

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-[email protected]
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python }}
enable-cache: true

- name: Set venv path (NON Windows)
if: matrix.os != 'windows-latest'
- name: Create virtualenv and sync dependencies
run: |
echo "VIRTUAL_ENV=${{ github.workspace }}/venv" >> $GITHUB_ENV
echo ${{ github.workspace }}/venv/bin >> $GITHUB_PATH

- name: Set venv path (Windows)
if: matrix.os == 'windows-latest'
run: |
echo "VIRTUAL_ENV=${{ github.workspace }}\\venv" >> $Env:GITHUB_ENV
echo "${{ github.workspace }}\\venv\\Scripts" >> $Env:GITHUB_PATH

- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: ${{ env.VIRTUAL_ENV }}
key: >-
${{ runner.os }}-${{ matrix.python }}-venv-${{
hashFiles('pyproject.toml') }}

- name: Create venv (NEW CACHE)
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv ${{ env.VIRTUAL_ENV }}
python -m pip install --upgrade pip
pip install -e ".[all]"
uv sync --all-extras

- name: codespell
if: matrix.run_doc == true
run: |
codespell
uv run codespell --skip "*.lock"

- name: dcoumentation
- name: documentation
if: matrix.run_doc == true
run: |
cd doc; ./build_html
run: cd doc && ./build_html

- name: pylint
if: matrix.run_lint == true
run: |
pylint --recursive=y examples pymodbus test
uv run pylint --recursive=y examples pymodbus test

- name: mypy
if: matrix.run_lint == true
run: |
mypy pymodbus examples
uv run mypy pymodbus examples

- name: ruff
if: matrix.run_lint == true
run: |
ruff check .
uv run ruff check .

- name: pytest
if: ${{ (matrix.os != 'ubuntu-latest') || (matrix.python != '3.13') }}
run: |
env
pytest
if: ${{ (matrix.os != 'ubuntu-latest') || (matrix.python != '3.13.0') }}
run: |
uv run pytest

- name: pytest coverage
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python == '3.13') }}
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python == '3.13.0') }}
run: |
env
pytest --cov
uv run pytest --cov

analyze:
name: Analyze Python
Expand Down
8 changes: 7 additions & 1 deletion doc/build_html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ zip -9 doc/source/_static/examples.zip examples/*
tar -czf doc/source/_static/examples.tgz examples
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.

echo "Using: uv run sphinx-build"
uv run sphinx-build -M html "." "../build/html"
else
echo "Using: sphinx-build"
sphinx-build -M html "." "../build/html"
fi