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

[ci] use Ruff linter instead of isort #6755

Merged
merged 29 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3f15a23
Update append-comment.sh
StrikerRUS Dec 14, 2024
7ea1a24
Update static_analysis.yml
StrikerRUS Dec 14, 2024
4d576fd
Update static_analysis.yml
StrikerRUS Dec 14, 2024
38e0469
Update basic.py
StrikerRUS Dec 14, 2024
4517bc1
Update basic.py
StrikerRUS Dec 14, 2024
f34a888
Update .pre-commit-config.yaml
StrikerRUS Dec 14, 2024
ac6cca0
Update basic.py
StrikerRUS Dec 14, 2024
108e6a2
Update basic.py
StrikerRUS Dec 14, 2024
b583b45
Update basic.py
StrikerRUS Dec 14, 2024
0105e50
Update basic.py
StrikerRUS Dec 14, 2024
e396c48
Update basic.py
StrikerRUS Dec 14, 2024
3510f74
Update pyproject.toml
StrikerRUS Dec 14, 2024
42a4faa
Update pyproject.toml
StrikerRUS Dec 14, 2024
1a4907a
Update pyproject.toml
StrikerRUS Dec 14, 2024
6326dea
Update pyproject.toml
StrikerRUS Dec 14, 2024
a72a0e6
Update interactive_plot_example.ipynb
StrikerRUS Dec 14, 2024
40a9c8f
Update pyproject.toml
StrikerRUS Dec 14, 2024
6648c7b
Update append-comment.sh
StrikerRUS Dec 14, 2024
79f1395
Update basic.py
StrikerRUS Dec 14, 2024
bd12804
Update basic.py
StrikerRUS Dec 14, 2024
cc0e5f6
Update pyproject.toml
StrikerRUS Dec 14, 2024
28034f4
Update .pre-commit-config.yaml
StrikerRUS Dec 14, 2024
de0a23b
Update basic.py
StrikerRUS Dec 14, 2024
aba520f
Update basic.py
StrikerRUS Dec 15, 2024
9e020c0
Update test_basic.R
StrikerRUS Dec 15, 2024
ab21c88
Update rank_objective.hpp
StrikerRUS Dec 15, 2024
1cf908d
Update histogram_16_64_256.cu
StrikerRUS Dec 15, 2024
f6dcaf4
Update static_analysis.yml
StrikerRUS Dec 15, 2024
4cb519e
ensure alphabetical order of rules
StrikerRUS Dec 15, 2024
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
10 changes: 2 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: ["--settings-path", "python-package/pyproject.toml"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.0
rev: v0.8.3
hooks:
# Run the linter.
- id: ruff
Expand All @@ -40,7 +34,7 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/crate-ci/typos
rev: v1.23.2
rev: v1.28.3
hooks:
- id: typos
args: ["--force-exclude"]
Expand Down
2 changes: 1 addition & 1 deletion R-package/tests/testthat/test_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ test_that("early stopping works with lgb.cv()", {
# never changes, its first iteration was the best oone
expect_equal(bst$best_iter, 1L)

# best_score should be taken from the first metri
# best_score should be taken from the first metric
expect_equal(bst$best_score, 0.2)

# early stopping should have happened, since constant_metric was the first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"try:\n",
" # To enable interactive mode you should install ipywidgets\n",
" # https://github.com/jupyter-widgets/ipywidgets\n",
" from ipywidgets import interact, SelectMultiple\n",
" from ipywidgets import SelectMultiple, interact\n",
"\n",
" INTERACTIVE = True\n",
"except ImportError:\n",
Expand Down
8 changes: 4 additions & 4 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2507,13 +2507,13 @@ def _compare_params_for_warning(
compare_result : bool
Returns whether two dictionaries with params are equal.
"""
for k in other_params:
for k, v in other_params.items():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fix PLC0206 in new Ruff version.

if k not in ignore_keys:
if k not in params or params[k] != other_params[k]:
if k not in params or params[k] != v:
return False
for k in params:
for k, v in params.items():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fix PLC0206 in new Ruff version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh wow, I'm impressed that a linter could look in this far and find something like this! Really nice.

if k not in ignore_keys:
if k not in other_params or params[k] != other_params[k]:
if k not in other_params or v != other_params[k]:
return False
return True

Expand Down
24 changes: 10 additions & 14 deletions python-package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ minimum-version = "build-system.requires"

# end:build-system

[tool.isort]
include_trailing_comma = true
line_length = 120
# "vertical hanging indent", to match what ruff-format does
# ref: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html#3-vertical-hanging-indent
multi_line_output = 3
skip_glob = [
"*/external_libs/*",
"*/lightgbm-python/*",
]

[tool.mypy]
disallow_untyped_defs = true
exclude = 'build/*|compile/*|docs/*|examples/*|external_libs/*|lightgbm-python/*|tests/*'
Expand Down Expand Up @@ -140,7 +129,7 @@ ignore = [
"PLR1714",
# (pylint) Magic value used in comparison
"PLR2004",
# (pylint) for loop veriable overwritten by assignment target
# (pylint) for loop variable overwritten by assignment target
"PLW2901",
# (pylint) use 'elif' instead of 'else' then 'if', to reduce indentation
"PLR5501"
Expand All @@ -152,10 +141,12 @@ select = [
"C4",
# pydocstyle
"D",
# pycodestyle
# pycodestyle (errors)
"E",
# pyflakes
"F",
# isort
"I",
# NumPy-specific rules
"NPY",
# pylint
Expand All @@ -166,11 +157,13 @@ select = [
"SIM401",
# flake8-print
"T",
# pycodestyle (warnings)
"W",
]

[tool.ruff.lint.per-file-ignores]
"docs/conf.py" = [
# (flake8-bugbear) raise exceptions with "raise ... from errr"
# (flake8-bugbear) raise exceptions with "raise ... from err"
"B904",
# (flake8-print) flake8-print
"T"
Expand All @@ -196,3 +189,6 @@ select = [

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.isort]
known-first-party = ["lightgbm"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

2 changes: 1 addition & 1 deletion src/objective/rank_objective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class LambdarankNDCG : public RankingObjective {
}
const double worst_score = score[sorted_idx[worst_idx]];
double sum_lambdas = 0.0;
// start accmulate lambdas by pairs that contain at least one document above truncation level
// start accumulate lambdas by pairs that contain at least one document above truncation level
for (data_size_t i = 0; i < cnt - 1 && i < truncation_level_; ++i) {
if (score[sorted_idx[i]] == kMinScore) { continue; }
for (data_size_t j = i + 1; j < cnt; ++j) {
Expand Down
2 changes: 1 addition & 1 deletion src/treelearner/kernels/histogram_16_64_256.cu
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ __global__ void KERNEL_NAME(const uchar* feature_data_base,
// size of threads that process this feature4
const unsigned int subglobal_size = lsize * (1 << power_feature_workgroups);

// equavalent thread ID in this subgroup for this feature4
// equivalent thread ID in this subgroup for this feature4
const unsigned int subglobal_tid = gtid - feature_id * subglobal_size;


Expand Down
Loading