Skip to content

Update Makefile to easily switch between Python versions#562

Merged
alcarney merged 4 commits into
openlawlibrary:mainfrom
alcarney:python-versions
Jun 29, 2025
Merged

Update Makefile to easily switch between Python versions#562
alcarney merged 4 commits into
openlawlibrary:mainfrom
alcarney:python-versions

Conversation

@alcarney

@alcarney alcarney commented Jun 29, 2025

Copy link
Copy Markdown
Collaborator

Description (e.g. "Related to ...", etc.)

Building on #561, now that we're using uv directly for everything we're not only able to simply the Makefile greatly, but it's now trivial to switch between Python versions.

By default, the Makefile will use 3.13

$ make test
/home/alex/.local/bin/uv run --managed-python --python 3.13 --group test --all-extras poe test
Poe => pytest --cov
=========================================================== test session starts ===========================================================
platform linux -- Python 3.13.5, pytest-8.4.1, pluggy-1.6.0

But by setting the PY variable when running make, you easily test against a different version, say 3.9

$ PY=3.9 make test
/home/alex/.local/bin/uv run --managed-python --python 3.9 --group test --all-extras poe test
Using CPython 3.9.23
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Installed 31 packages in 41ms
Poe => pytest --cov
=========================================================== test session starts ===========================================================
platform linux -- Python 3.9.23, pytest-8.4.1, pluggy-1.6.0

And since uv supports it, it's now trivial to start playing around with running pygls with a free-threaded Python build!

PY=3.13t make test     # <- note the `t` in the Python version!

For the most part, free-threaded Python appears to "just work", however, it's probably not quite ready to add to CI as there is at least one websocket test that hangs the test suite. I'm also not sure if enough of our test suite really exercises threading all that much?...

Thanks to this code snippet I have updated the pytest header to indicate if the test suite is running with or without the GIL.

❯ PY=3.13t make test
/home/alex/.local/bin/uv run --managed-python --python 3.13t --group test --all-extras poe test
Poe => pytest --cov
=========================================================== test session starts ===========================================================
platform linux -- Python 3.13.0, pytest-8.4.1, pluggy-1.6.0
...
GIL: disabled

Finally, I came across this article the other day and thought it was a great idea, so using it as a guide I've tweaked the test suite so that all of our slow (i.e. end-to-end) tests now run last.

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

Automated linters

You can run the lints that are run on CI locally with:

uv run --all-extras poe lint

@alcarney alcarney requested a review from tombh June 29, 2025 12:52
@tombh

tombh commented Jun 29, 2025

Copy link
Copy Markdown
Collaborator

Nice simplification!

And wow, GIL: disabled, it's been a long time coming, that's the first time I've ever seen a Python do that. Good question about how much pygls actually uses threading, but still great to at least have some testing for it.

@alcarney

Copy link
Copy Markdown
Collaborator Author

Thanks!

@alcarney alcarney merged commit ce77e68 into openlawlibrary:main Jun 29, 2025
18 checks passed
@alcarney alcarney deleted the python-versions branch June 29, 2025 15:24
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