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

Add precommit for linting and formatting #9123

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

kdaily
Copy link
Member

@kdaily kdaily commented Dec 5, 2024

Description of changes:

First in a series of commits to lint and format the v2 branch of this repository.

Adds a precommit hook configuration file and enables whitespace linting, isort for imports, and ruff to lint and format. It adds configuration to pyproject.toml for ruff as well with the same configuration as the develop branch, with the exception of ignoring unused imports (F401). This exception will be dropped at a later date.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@kdaily kdaily force-pushed the kdaily-add-precommit-hook branch 6 times, most recently from 85393a5 to f932015 Compare December 6, 2024 19:02
@kdaily kdaily force-pushed the kdaily-add-precommit-hook branch 4 times, most recently from 0fb1fd7 to 6156454 Compare December 17, 2024 21:26
@kdaily kdaily marked this pull request as ready for review December 19, 2024 18:05
@kdaily kdaily requested a review from a team December 19, 2024 18:05
@kdaily kdaily force-pushed the kdaily-add-precommit-hook branch from 6156454 to 46cb394 Compare December 24, 2024 19:11
Copy link
Contributor

@aemous aemous left a comment

Choose a reason for hiding this comment

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

Looks good to me. Left one non-blocking comment to consider.

@@ -0,0 +1,33 @@
exclude: "\
^(\
.changes|\
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking: should awscli/data, be on this list?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should leave that directory in. There are only JSON files in it, and they should be subject to the end of file fixer check; the rest of the checks aren't applicable anyways.

Indeed, running the basic linting catches that one file does not have a trailing newline:

https://github.com/aws/aws-cli/pull/9157/files#diff-031ec82ae188f9206c76aa4ae0fc601a34c9af77e340adba262922c9f4b7012e

Copy link
Member

Choose a reason for hiding this comment

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

Does the linter actively change these? If they're getting re-updated with each release, we should avoid them.

Copy link
Member Author

@kdaily kdaily Jan 6, 2025

Choose a reason for hiding this comment

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

Does the linter actively change these?

It only adds the single new line that was missing. cli.json contains the top level documentation descriptions, it is not changed in each release. metadata.json was only added for additional metadata in the user agent string.

@kdaily kdaily requested review from ashovlin and hssyoo January 6, 2025 22:33
.pre-commit-config.yaml Outdated Show resolved Hide resolved
pyproject.toml Outdated
line-length = 79
indent-width = 4

target-version = "py38"
Copy link
Member

Choose a reason for hiding this comment

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

Is this still right? Are we waiting until botocore raises pins? I think the CLI v2 can be a little more aggressive.

Copy link
Member Author

Choose a reason for hiding this comment

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

I assumed since our minimum version is Python 3.8, thats what we would have here. After a closer reading of the ruff docs, it would effectively be set to py38 because we have this in our pyproject.toml too:

requires-python = ">=3.8"

From the docs:

If you're already using a pyproject.toml file, we recommend project.requires-python instead, as it's based on Python packaging standards, and will be respected by other tools. For example, Ruff treats the following as identical to target-version = "py38":

[project]
requires-python = ">=3.8"

Copy link
Member

@nateprewitt nateprewitt Jan 7, 2025

Choose a reason for hiding this comment

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

Cool, we can probably yank this then and let requires-python be the single source of truth.

pyproject.toml Outdated Show resolved Hide resolved
@kdaily kdaily force-pushed the kdaily-add-precommit-hook branch from 46cb394 to 252fa9b Compare January 7, 2025 16:40
@kdaily kdaily requested review from nateprewitt and aemous January 7, 2025 16:40
First pass at adding a pre-commit hook to enforce
formatting and linting standards.

This adds the pre-commit command to run on a
limited set of directories. Subsequent changes
will remove excluded folders and run formatting on
them as well.

The command will use the standard pre-commit hooks
for yaml, whitespace, and end of line linting.

It also uses `ruff` configured identically to
the develop branch, except for disabling
unused import checks ("F401"), as there are known
imports that are unused in the module but imported
in other modules. This is common in `compat` but
in other places as well. It also adds the `I` flag
to perform import sorting.

The intention is to start enforcing formatting and
linting standards on edited code. Running the
pre-commit hook manually will make numerous
changes that should be broken into multiple
phases. Additional PRs will work to get the
codebase up-to-date passing all standards.
@kdaily kdaily force-pushed the kdaily-add-precommit-hook branch from 252fa9b to 0cb6373 Compare January 7, 2025 18:00
@kdaily kdaily merged commit 680e4bd into aws:v2 Jan 8, 2025
42 of 45 checks passed
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (c9d26de) to head (0cb6373).
Report is 101 commits behind head on v2.

Additional details and impacted files
@@    Coverage Diff     @@
##   v2   #9123   +/-   ##
==========================
==========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

5 participants