Auto-lint Python, and run all formatters #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available: N/A
Description of changes:
Similar to how #12 previously enabled automatic formatting-on-commit (via Prettier) for TypeScript sections of the codebase, this PR:
rufffrom the chainlit image's dev dependencies)bin/format-python.ts,lint-staged.config.mjs, andpackage.json- as per the first commitnpm run formatto align any files that hadn't been formatted yet in Add linters and use uv for Python package #12.Implementation notes:
huskygit hooks andlint-stagedtogether provide the functionality for automatically linting/formatting files before commit as implemented in #12. They live in NodeJS world, and are activated when the developernpm installs the project.ruffon the other hand, which powers our Python linting/formatting, is specified as a dependency of thechainlit_image/foundational-llm-chat_app/pyproject.tomlproject. This presents complexity because of the many ways users might manage their Python virtual environments (Poetry, uv, venv, etc), and the fact that a developer technically doesn't need to have the Python venv set up at all to deploy the solution today (since the container build will happen in Docker/finch/etc).In this solution:
bin/format-python.tsattempts to provide an OS-agnostic invocation ofruff format ...that should work either on macOS or Windows, and with either Python or uv or any other venv manager on the condition that the environment is created atchainlit_image/foundational-llm-chat_app/.venv.Testing done:
npm run formatworks and generated the formatting changes proposednpm run formatlint-stagedto completeBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.