Skip to content

chore(ci): replace flake8 with Ruff as a linter #2495

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

Merged
merged 8 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ repos:
entry: poetry run black
language: system
types: [python]
- id: isort
name: formatting::isort
entry: poetry run isort
language: system
types: [python]
- repo: local
hooks:
- id: flake8
name: linting::flake8
entry: poetry run flake8
- id: ruff
name: linting-format::ruff
entry: poetry run ruff
language: system
types: [python]
- repo: https://github.com/igorshubovych/markdownlint-cli
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ You might find useful to run both the documentation website and the API referenc
| Category | Convention |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Docstring** | We use a slight variation of Numpy convention with markdown to help generate more readable API references. |
| **Style guide** | We use black as well as flake8 extensions to enforce beyond good practices [PEP8](https://pep8.org/). We use type annotations and enforce static type checking at CI (mypy). |
| **Style guide** | We use black as well as [Ruff](https://beta.ruff.rs/docs/) extensions to enforce beyond good practices [PEP8](https://pep8.org/). We use type annotations and enforce static type checking at CI (mypy). |
| **Core utilities** | Core utilities use a Class, always accept `service` as a constructor parameter, can work in isolation, and are also available in other languages implementation. |
| **Utilities** | Utilities are not as strict as core and focus on solving a developer experience problem while following the project [Tenets](https://awslabs.github.io/aws-lambda-powertools-python/#tenets). |
| **Exceptions** | Specific exceptions live within utilities themselves and use `Error` suffix e.g. `MetricUnitError`. |
Expand Down Expand Up @@ -106,7 +106,7 @@ Looking at the existing issues is a great way to find something to contribute on

This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.
<[email protected]> with any additional questions or comments.

## Security issue notifications

Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ dev-gitpod:
pre-commit install

format:
poetry run isort aws_lambda_powertools tests examples
poetry run black aws_lambda_powertools tests examples

lint: format
poetry run flake8 aws_lambda_powertools tests examples
poetry run ruff aws_lambda_powertools tests examples

lint-docs:
docker run -v ${PWD}:/markdown 06kellyjac/markdownlint-cli "docs"
Expand Down
28 changes: 27 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ mypy = "^1.1.1"
types-python-dateutil = "^2.8.19.6"
httpx = ">=0.23.3,<0.25.0"
sentry-sdk = "^1.22.2"
ruff = "^0.0.272"

[tool.coverage.run]
source = ["aws_lambda_powertools"]
Expand Down
76 changes: 76 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Enable rules.
select = [
"A",
"C4",
"C90",
"COM",
#"D", # pydocstyle - not enabled temporarily
"E",
"ERA",
"FA",
"FIX",
"F",
"I",
"ICN",
"ISC",
"PLE",
"PLC",
"PLR",
"PLW",
"PL",
"PYI",
"Q",
"PTH",
"TD",
"W"
]

# Ignore specific rules
ignore = [
"W291", # https://beta.ruff.rs/docs/rules/trailing-whitespace/
"PLR0913", # https://beta.ruff.rs/docs/rules/too-many-arguments/
"PLR2004", #https://beta.ruff.rs/docs/rules/magic-value-comparison/
"PLW0603", #https://beta.ruff.rs/docs/rules/global-statement/
"COM812", # Trailing comma missing - disabled temporarily
"PLC1901", # Compare-to-empty-string - disabled temporarily
"ERA001", # Found commented-out code - disabled temporarily
"PLW", # Warning category - disabled temporarily
"PLR", # Refactoring category - disabled temporarily
"PLC", # Convention category - disabled temporarily
"PLE", # Error category - disabled temporarily
"ISC", # flake8-implicit-str-concat - disabled temporarily
"E501", # Line too long - disabled temporarily
"I001", # isort - disabled temporarily
]

# Exclude files and directories
exclude = ["docs", ".eggs", "setup.py", "example", ".aws-sam", ".git", "dist", ".md", ".yaml", "example/samconfig.toml", ".txt", ".ini"]

# Maximum line length
line-length = 120


#fix = true
#fixable = ["I", "COM812", "W"]

# See: https://github.com/astral-sh/ruff/issues/128
typing-modules = ["aws_lambda_powertools.utilities.parser.types"]

[mccabe]
# Maximum cyclomatic complexity
max-complexity = 15

[pylint]
# Maximum number of nested blocks
max-branches = 15
# Maximum number of if statements in a function
max-statements = 70

[isort]
split-on-trailing-comma = true

[per-file-ignores]
# Ignore specific rules for specific files
"tests/e2e/utils/data_builder/__init__.py" = ["F401"]
"tests/e2e/utils/data_fetcher/__init__.py" = ["F401"]
"aws_lambda_powertools/utilities/data_classes/s3_event.py" = ["A003"]