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

Configure ruff and UV #23

Merged
merged 12 commits into from
Nov 7, 2024
Merged

Configure ruff and UV #23

merged 12 commits into from
Nov 7, 2024

Conversation

dfsnow
Copy link
Member

@dfsnow dfsnow commented Nov 7, 2024

This PR swaps our Python packaging toolchain to uv, similar to the switch performed in ccao-data/data-architecture#635. The main benefit here is simpler tooling and much faster builds.

The diff here looks really messy, but most of it is reformatting from ruff. I recommend excluding 2a7f7c1 and only reviewing the tooling changes.

Closes #22.

@dfsnow dfsnow force-pushed the dfsnow/configure-ruff-and-uv branch 2 times, most recently from 6a34bdc to 574b892 Compare November 7, 2024 19:20
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: "pip"
python-version-file: pyproject.toml
Copy link
Member Author

Choose a reason for hiding this comment

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

This just install the min version specified in our pyproject.toml, in this case 3.10.

@@ -18,14 +18,24 @@ jobs:
- name: Checkout
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that usually we want to install Python packages into the system library with uv by setting UV_SYSTEM_PYTHON=1. However, in this case, we want uv to install things into the tox-created virtualenv, so we leave that var unset.

Comment on lines +84 to +85
deps =
setuptools>=61.0
Copy link
Member Author

Choose a reason for hiding this comment

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

This installs dependencies into each tox environment using uv.

Comment on lines +35 to +36
uv tool install tox --with tox-uv
tox --version
Copy link
Member Author

Choose a reason for hiding this comment

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

The tox-uv plugin sets up virtual environments using uv that are compatible with tox.

Comment on lines -76 to -82
[gh]
python =
3.12 = py312
3.11 = py311
3.10 = py310
3.9 = py39
3.8 = py38
Copy link
Member Author

Choose a reason for hiding this comment

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

We no longer need this environment mapping since we just explicitly specify the tox environment via these commands:

env=$(echo ${{ matrix.python-version }} | tr -d '.' | sed 's/^/py/')
tox r -v --notest -e "$env"

@dfsnow dfsnow requested a review from jeancochrane November 7, 2024 19:54
@dfsnow dfsnow marked this pull request as ready for review November 7, 2024 19:54
@dfsnow dfsnow requested a review from wrridgeway as a code owner November 7, 2024 19:54
Copy link

@jeancochrane jeancochrane left a comment

Choose a reason for hiding this comment

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

Nice work here! A couple questions about Python log buffering and appropriate ways of running system-level tools with uv, but nothing serious.

@@ -6,21 +6,30 @@ on:

name: lint

env:
PYTHONUNBUFFERED: "1"

Choose a reason for hiding this comment

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

[Question, non-blocking] Should we be setting this more widely across our workflows? I've never noticed a buffering problem with Python scripts in GitHub workflow logs (except on our network, which blocks websockets and so prevents all real-time logs from displaying) but maybe I just haven't been watching out for the right issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's purely defensive. I've run into a few cases over the past couple months where Python won't output full logs due to its buffered output.


- name: Generate HTML
run: |
sphinx-build -d _build/doctrees docs/source _build/html
uv run sphinx-build -d _build/doctrees docs/source _build/html

Choose a reason for hiding this comment

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

[Question, non-blocking] If we're installing packages into the global environment by setting UV_SYSTEM_PYTHON=1, do we need to prefix the sphinx-build call with uv here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, totally unneeded! I removed it in acafd68.

Comment on lines 42 to 43
uv run pytest --doctest-modules \
--junitxml=junit/test-results-${{ matrix.python-version }}.xml

Choose a reason for hiding this comment

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

[Question, non-blocking] Same question here about using the uv prefix when UV_SYSTEM_PYTHON=1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in acafd68!

@dfsnow dfsnow force-pushed the dfsnow/configure-ruff-and-uv branch from f1569e6 to acafd68 Compare November 7, 2024 20:11
@dfsnow dfsnow merged commit 7dfcba7 into main Nov 7, 2024
12 checks passed
@dfsnow dfsnow deleted the dfsnow/configure-ruff-and-uv branch November 7, 2024 20:20
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.

Configure ruff to sort Python imports
3 participants