AVRO-4232: [Python] Modernize the Python tooling - #3658
Conversation
Use `uv` for management and `ruff` for linting and formatting
027ddcf to
6ec71fe
Compare
|
|
||
| def main(): | ||
| mail_server = http_server.HTTPServer(SERVER_ADDRESS, MailHandler) | ||
| mail_server = http.server.HTTPServer(SERVER_ADDRESS, MailHandler) |
There was a problem hiding this comment.
I have no idea how this worked before
There was a problem hiding this comment.
Probably didn't. Is there evidence it was ever covered?
|
|
||
|
|
||
| def looney_records(): | ||
| return ({"first": f, "last": l, "type": t} for f, l, t in LOONIES) |
There was a problem hiding this comment.
Here for some reason there was a problem with l, so I renamed it to last
| @@ -1,84 +0,0 @@ | |||
| ## | |||
There was a problem hiding this comment.
I am not sure whether this file should be removed.
But before removing it uv sync would fail with error like There is no "get" in NoneType or something like that.
There was a problem hiding this comment.
It should be fine to remove this as long as the PEP 621 requirements are met. I haven't used uv that much (currently working in a php ecosystem), but I believe uv is fully compliant with that PEP.
There was a problem hiding this comment.
It seems I have "translated" correctly most of the setuptools data (setup.cfg) to pyproject.toml (PEP 621).
My only uncertainty is package-data.
|
@kojiromike I have some concerns about the removal of setup.cfg. I am not a Python dev and I am not fully confident in what I am doing here :-) |
|
My main reason to introduce uv here is because the Python build started failing again without any changes in lang/py/. I guess some dependency has released a new version and to due not using a .lock file the build became unstable. https://github.com/apache/avro/actions/runs/22087958485/job/63826627519 |
Policy by Infra: https://infra.apache.org/github-actions-policy.html > External actions Last allowed version: 7.1.6 (https://github.com/apache/infrastructure-actions/blob/2943971f47fadefa6d86af85c2c24c2cee262ee1/actions.yml#L25-L26) Co-authored-by: Ryan Skraba <ryan@skraba.com>
| writers_schema = local_message.errors | ||
| self.write_error(writers_schema, error, buffer_encoder) | ||
| except schema.AvroException as e: | ||
| except avro.errors.AvroException as e: |
There was a problem hiding this comment.
Hi.
This MR not only modernize the python tooling. But also fix that bug. Do you plane to update the library in pypi too?
Thanks a lot.
There was a problem hiding this comment.
Right!
uv reported this problem and we fixed it!
It will be part of the 1.13.0 release but I cannot say when it will be made.
* AVRO-4232: [Python] Modernize the Python tooling Use `uv` for management and `ruff` for linting and formatting * Ignore uv.lock for ASFv2 licence check * Add librt as a dev dependency * Drop librt as dev-dep. It fails at CI with another error * Do not test Python 3.9 since it is not supported Test 3.14 instead * Try with mypy<1.19 python/mypy#20454 * Use uv for the Java interop tests too * Remove the flake8 settings. Now we use ruff * Update uv.lock * Set cwd to lang/py for `uv sync`. Do not use uv for C# scripts * Update the usage. Wrap variables in quotes * Move more entries from setup.cfg to pyproject.toml * Remove typechecks dependency. It seems to be tox specific * Do not shadow Python built-in `type` * Use `--frozen` for `uv sync` in CI * Update setup-uv Github action to v7 * Fix the package name for AvroException * First declare the local variable and then assign it a value * Use Python 3.10 for mypy * Move "scripts" from setup.cfg to pyproject.toml * Re-add the optional dependencies from setup.cfg to pyproject.toml * Re-add the package-data from setup.cfg to pyproject.toml * Use SHA for the external actions Policy by Infra: https://infra.apache.org/github-actions-policy.html > External actions Last allowed version: 7.1.6 (https://github.com/apache/infrastructure-actions/blob/2943971f47fadefa6d86af85c2c24c2cee262ee1/actions.yml#L25-L26) Co-authored-by: Ryan Skraba <ryan@skraba.com> * No need to call `build.sh` thru `uv run` --------- Co-authored-by: Ryan Skraba <ryan@skraba.com>
* AVRO-4232: [Python] Modernize the Python tooling Use `uv` for management and `ruff` for linting and formatting * Ignore uv.lock for ASFv2 licence check * Add librt as a dev dependency * Drop librt as dev-dep. It fails at CI with another error * Do not test Python 3.9 since it is not supported Test 3.14 instead * Try with mypy<1.19 python/mypy#20454 * Use uv for the Java interop tests too * Remove the flake8 settings. Now we use ruff * Update uv.lock * Set cwd to lang/py for `uv sync`. Do not use uv for C# scripts * Update the usage. Wrap variables in quotes * Move more entries from setup.cfg to pyproject.toml * Remove typechecks dependency. It seems to be tox specific * Do not shadow Python built-in `type` * Use `--frozen` for `uv sync` in CI * Update setup-uv Github action to v7 * Fix the package name for AvroException * First declare the local variable and then assign it a value * Use Python 3.10 for mypy * Move "scripts" from setup.cfg to pyproject.toml * Re-add the optional dependencies from setup.cfg to pyproject.toml * Re-add the package-data from setup.cfg to pyproject.toml * Use SHA for the external actions Policy by Infra: https://infra.apache.org/github-actions-policy.html > External actions Last allowed version: 7.1.6 (https://github.com/apache/infrastructure-actions/blob/2943971f47fadefa6d86af85c2c24c2cee262ee1/actions.yml#L25-L26) Co-authored-by: Ryan Skraba <ryan@skraba.com> * No need to call `build.sh` thru `uv run` --------- Co-authored-by: Ryan Skraba <ryan@skraba.com>
* AVRO-4232: [Python] Backport uv/ruff tooling to branch-1.12 Backports the Python tooling modernization (AVRO-4232, #3658) so that the Java interop workflow's 'uv sync --frozen' step works on branch-1.12. The workflow change was previously backported without the accompanying lang/py migration, leaving no uv.lock or [project] table, which caused 'uv sync --frozen' to fail. - Migrate lang/py from tox/setuptools to uv + ruff - Add uv.lock and [project]/[dependency-groups] to pyproject.toml - Remove tox.ini and setup.cfg - Update build.sh (ruff/coverage/mypy targets) - Convert test-lang-py.yml to uv (drops py3.9 CI, adds 3.14) - Exclude lang/py/uv.lock from RAT license check Version pinned to 1.12.2 and packages.find restricted to avro* to fix flat-layout package discovery. * AVRO-4232: [Python] Use pinned ruff (uv run) instead of uvx in build.sh uvx fetches the latest ruff, whose stricter default lint rules flag 252 pre-existing issues in the (not-yet-modernized) branch-1.12 source. Use 'uv run ruff' to run the version pinned in uv.lock (0.15.1), matching main and keeping lint reproducible.
What is the purpose of the change
Use
uvfor management andrufffor linting and formattingVerifying this change
This is mostly changes in Python package management (pyproject.toml and tox.ini)
The Python source files have small modifications caused by linting/formatting issues
Documentation
build.sh