Migrate Python tooling to uv, Ruff, ty, and Poe #11

Open
mitsimi wants to merge 10 commits from mitsimi/BAC-ColorAnalyzer:migrate/proper-tooling into main
First-time contributor

Summary

This PR migrates the project to a modern Python development workflow based on Astral tooling and adds task aliases for the common commands.

The project now uses:

  • uv for dependency management, lockfile generation, and running commands inside the project environment
  • ruff for formatting and linting
  • ty for type checking
  • poethepoet for npm-style task aliases such as uv run poe lint, uv run poe lint-fix, and uv run poe dev

Code Changes

Most Python file changes are the result of running ruff format, so the codebase now has one consistent formatting style.

The non-formatting code changes are small fixes that were required for Ruff and ty to pass:

  • Import img_as_float from skimage.util instead of the top-level skimage package, which matches how the package exposes that function for type checking.
  • Make SelectedLabels session-state access explicit by using st.session_state.setdefault("SelectedLabels", {}), avoiding possible None handling issues.
  • Fix the uploader call to pass the required gamename argument to upload_image.
  • Relax the save_image argument typing because it is called with byte buffers, not only Streamlit UploadedFile objects.
  • Replace invalid NumPy annotations like np.ndarray[any, ...] with numpy.typing.NDArray.
  • Guard scraper parsing so BeautifulSoup attributes are checked before string operations.
  • Avoid mutating the scraper label list while iterating over the same list.

Why Add This Tooling?

The project did not have a reproducible Python dependency setup before. With uv, contributors can install the same dependency set from uv.lock and run the app without manually assembling a local Python environment.

Ruff gives the project a fast formatter and linter, which keeps style consistent and catches simple mistakes early. ty adds a lightweight type-checking step that found several real issues in the existing code, including missing arguments and unsafe optional values.

Poe adds a small npm-like command layer so contributors do not need to remember the underlying tool commands. The README now documents both variants:

uv run poe lint
uv run poe lint-fix
uv run poe dev

and, if Poe is installed globally:

poe lint
poe lint-fix
poe dev

Validation

Ran successfully:

uv run poe format-check
uv run poe lint
uv run poe typecheck
uv run poe check
## Summary This PR migrates the project to a modern Python development workflow based on Astral tooling and adds task aliases for the common commands. The project now uses: - `uv` for dependency management, lockfile generation, and running commands inside the project environment - `ruff` for formatting and linting - `ty` for type checking - `poethepoet` for npm-style task aliases such as `uv run poe lint`, `uv run poe lint-fix`, and `uv run poe dev` ## Code Changes Most Python file changes are the result of running `ruff format`, so the codebase now has one consistent formatting style. The non-formatting code changes are small fixes that were required for Ruff and ty to pass: - Import `img_as_float` from `skimage.util` instead of the top-level `skimage` package, which matches how the package exposes that function for type checking. - Make `SelectedLabels` session-state access explicit by using `st.session_state.setdefault("SelectedLabels", {})`, avoiding possible `None` handling issues. - Fix the uploader call to pass the required `gamename` argument to `upload_image`. - Relax the `save_image` argument typing because it is called with byte buffers, not only Streamlit `UploadedFile` objects. - Replace invalid NumPy annotations like `np.ndarray[any, ...]` with `numpy.typing.NDArray`. - Guard scraper parsing so BeautifulSoup attributes are checked before string operations. - Avoid mutating the scraper label list while iterating over the same list. ## Why Add This Tooling? The project did not have a reproducible Python dependency setup before. With `uv`, contributors can install the same dependency set from `uv.lock` and run the app without manually assembling a local Python environment. Ruff gives the project a fast formatter and linter, which keeps style consistent and catches simple mistakes early. ty adds a lightweight type-checking step that found several real issues in the existing code, including missing arguments and unsafe optional values. Poe adds a small npm-like command layer so contributors do not need to remember the underlying tool commands. The README now documents both variants: ```bash uv run poe lint uv run poe lint-fix uv run poe dev ``` and, if Poe is installed globally: ```bash poe lint poe lint-fix poe dev ``` ## Validation Ran successfully: ```bash uv run poe format-check uv run poe lint uv run poe typecheck uv run poe check ```
ci: run Python checks in Forgejo
All checks were successful
CI / Python checks (pull_request) Successful in 30s
9a5a9f9acf
All checks were successful
CI / Python checks (pull_request) Successful in 30s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u migrate/proper-tooling:mitsimi-migrate/proper-tooling
git switch mitsimi-migrate/proper-tooling

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff mitsimi-migrate/proper-tooling
git switch mitsimi-migrate/proper-tooling
git rebase main
git switch main
git merge --ff-only mitsimi-migrate/proper-tooling
git switch mitsimi-migrate/proper-tooling
git rebase main
git switch main
git merge --no-ff mitsimi-migrate/proper-tooling
git switch main
git merge --squash mitsimi-migrate/proper-tooling
git switch main
git merge --ff-only mitsimi-migrate/proper-tooling
git switch main
git merge mitsimi-migrate/proper-tooling
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pix3lpaw/BAC-ColorAnalyzer!11
No description provided.