forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ruff for Python formatting and linting (streamlit#8849)
## Describe your changes This PR replaces black (formatting), isort (import sorting), and autoflake (linting) with [ruff](https://github.com/astral-sh/ruff) - an extremely fast and modern Python linter and code formatter. It also activates a couple of linting rules that we have been following implicitly for the last couple of months (e.g., usage of modern annotations). ## Testing Plan - No logical changes -> no additional tests required. --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
- Loading branch information
1 parent
a3e99aa
commit a36cbcc
Showing
170 changed files
with
626 additions
and
663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ eggs/ | |
test-reports | ||
htmlcov | ||
.hypothesis | ||
.ruff_cache | ||
|
||
# Test fixtures | ||
cffi_bin | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# In addition to the standard set of exclusions, omit all tests: | ||
extend-exclude = ["lib/streamlit/proto", "lib/streamlit/emojis.py"] | ||
include = ["lib/**/*.py", "lib/**/*.pyi", "e2e_playwright/**/*.py", "scripts/**/*.py"] | ||
target-version = 'py38' | ||
line-length = 88 | ||
|
||
[lint] | ||
select = [ | ||
"B", # flake8-bugbear | ||
"C4", # Helps you write better list/set/dict comprehensions. | ||
"E", # pycodestyle errors | ||
"FA", # Verifies files use from __future__ import annotations if a type is used in the module that can be rewritten using PEP 563. | ||
"F", # pyflakes | ||
"I", # isort - Import sorting | ||
"ISC", # Encourage correct string literal concatenation. | ||
"LOG", # Checks for issues using the standard library logging module. | ||
"NPY", # Linting rules for numpy | ||
"Q", # Linting rules for quites | ||
"RUF100", # Unused noqa directive | ||
"T20", # Check for Print statements in python files. | ||
"TID", # Helps you write tidier imports. | ||
"UP", # pyupgrade | ||
"W", # pycodestyle warnings | ||
] | ||
ignore = [ | ||
"B008", # Checks for function calls in default function arguments. | ||
"B904", # Checks for raise statements in exception handlers that lack a from clause. | ||
"E501", # Checks for lines that exceed the specified maximum character length. | ||
"ISC001", # Checks for implicitly concatenated strings on a single line. | ||
"NPY002", # Checks for the use of legacy np.random function calls. | ||
"PYI036", # Checks for incorrect function signatures on __exit__ and __aexit__ methods. | ||
"PYI041", # Checks for parameter annotations that contain redundant unions between builtin numeric types (e.g., int | float). | ||
"PYI051", # Checks for redundant unions between a Literal and a builtin supertype of that Literal. | ||
"UP031", # Checks for printf-style string formatting, and offers to replace it with str.format calls. | ||
] | ||
# Do not lint files in tests, scripts, and vendor directory: | ||
exclude = ["lib/tests/**", "lib/streamlit/vendor/**", "scripts/**", ".github/**"] | ||
|
||
[lint.per-file-ignores] | ||
"e2e_playwright/**" = ["T20", "B018"] | ||
"lib/streamlit/__init__.py" = ["E402"] | ||
|
||
[lint.flake8-tidy-imports] | ||
# Disallow all relative imports. | ||
ban-relative-imports = "all" | ||
|
||
[lint.isort] | ||
known-first-party = ["streamlit", "shared", "tests", "e2e_playwright"] | ||
|
||
[lint.flake8-comprehensions] | ||
# Allow dict calls that make use of keyword arguments (e.g., dict(a=1, b=2)). | ||
allow-dict-calls-with-keyword-arguments = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
|
||
x = st.slider("Enter a number", 0, 20, 0) | ||
|
||
for i in range(x): | ||
for _ in range(x): | ||
st.write("Hello example") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.