Skip to content

Commit 889ee39

Browse files
committed
chore: streamline linting and formatting process
- Replace black, isort, and pyupgrade with ruff - Update pyproject.toml with optimized ruff configurations - Remove unused configurations from pyproject.toml - Update Makefile to use ruff for linting and formatting - Update dev dependencies in setup.py This change consolidates multiple tools into a single, more efficient linter and formatter (ruff).
1 parent e4eb379 commit 889ee39

File tree

6 files changed

+47
-116
lines changed

6 files changed

+47
-116
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,9 @@ repos:
2020
- id: forbid-new-submodules
2121
- id: mixed-line-ending
2222
- id: pretty-format-json
23-
args: ['--autofix', '--no-sort-keys', '--indent=4']
23+
args: ["--autofix", "--no-sort-keys", "--indent=4"]
2424
- id: trailing-whitespace
2525

26-
27-
- repo: https://github.com/PyCQA/isort
28-
rev: 5.13.2
29-
hooks:
30-
- id: isort
31-
name: Sort imports
32-
3326
- repo: https://github.com/PyCQA/flake8
3427
rev: 7.1.0
3528
hooks:
@@ -38,22 +31,16 @@ repos:
3831
entry: flake8
3932
additional_dependencies: [Flake8-pyproject]
4033

34+
- repo: https://github.com/PyCQA/bandit
35+
rev: 1.7.9
36+
hooks:
37+
- id: bandit
38+
args: ["-c", "pyproject.toml"]
39+
additional_dependencies: ["bandit[toml]"]
4140

42-
- repo: https://github.com/PyCQA/bandit
43-
rev: 1.7.9
44-
hooks:
45-
- id: bandit
46-
args: ["-c", "pyproject.toml"]
47-
additional_dependencies: ["bandit[toml]"]
48-
49-
- repo: https://github.com/astral-sh/ruff-pre-commit
50-
rev: v0.5.0
51-
hooks:
52-
- id: ruff
53-
args: [--fix, --exit-non-zero-on-fix]
54-
55-
- repo: https://github.com/asottile/pyupgrade
56-
rev: v3.16.0
41+
- repo: https://github.com/astral-sh/ruff-pre-commit
42+
rev: v0.5.1
5743
hooks:
58-
- id: pyupgrade
59-
args: [--py38-plus]
44+
- id: ruff-format
45+
- id: ruff
46+
args: [--fix, --exit-non-zero-on-fix]

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export PYTHONPATH = .
44
check_dirs := roboflow
55

66
style:
7-
black $(check_dirs)
8-
isort --profile black $(check_dirs)
7+
ruff format $(check_dirs)
8+
ruff check $(check_dirs) --fix
99

1010
check_code_quality:
11-
black --check $(check_dirs)
12-
isort --check-only --profile black $(check_dirs)
11+
ruff format $(check_dirs) --check
12+
ruff check $(check_dirs)
1313
# stop the build if there are Python syntax errors or undefined names
1414
flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics
1515
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators

pyproject.toml

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
requires = ["setuptools>=57", "wheel"]
33
build-backend = "setuptools.build_meta"
44

5-
65
[tool.flake8]
76
exclude = ".venv"
87
max-complexity = 10
@@ -17,75 +16,25 @@ per-file-ignores = """
1716
__init__.py: F401
1817
"""
1918

20-
[tool.black]
21-
line-length = 120
22-
23-
[tool.isort]
24-
line_length = 120
25-
profile = "black"
26-
2719
[tool.bandit]
2820
target = ["test", "roboflow"]
2921
tests = ["B201", "B301"]
3022

31-
[tool.autoflake]
32-
check = true
33-
imports = ["cv2", "roboflow"]
34-
3523
[tool.ruff]
3624
target-version = "py38"
37-
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
38-
select = ["E", "F"]
39-
ignore = []
25+
# Same as Black.
26+
line-length = 120
4027

41-
# Allow autofix for all enabled rules (when `--fix`) is provided.
42-
fixable = [
43-
"A",
44-
"B",
45-
"C",
46-
"D",
47-
"E",
48-
"F",
49-
"G",
50-
"I",
51-
"N",
52-
"Q",
53-
"S",
54-
"T",
55-
"W",
56-
"ANN",
57-
"ARG",
58-
"BLE",
59-
"COM",
60-
"DJ",
61-
"DTZ",
62-
"EM",
63-
"ERA",
64-
"EXE",
65-
"FBT",
66-
"ICN",
67-
"INP",
68-
"ISC",
69-
"NPY",
70-
"PD",
71-
"PGH",
72-
"PIE",
73-
"PL",
74-
"PT",
75-
"PTH",
76-
"PYI",
77-
"RET",
78-
"RSE",
79-
"RUF",
80-
"SIM",
81-
"SLF",
82-
"TCH",
83-
"TID",
84-
"TRY",
85-
"UP",
86-
"YTT",
28+
[tool.ruff.lint]
29+
select = [
30+
"E", # pycodestyle errors
31+
"F", # pyflakes
32+
"I", # isort
33+
"UP", # pyupgrade
34+
]
35+
ignore = [
36+
"E501", # line too long, handled by black
8737
]
88-
unfixable = []
8938

9039
# Exclude a variety of commonly ignored directories.
9140
exclude = [
@@ -116,31 +65,26 @@ exclude = [
11665
"tests/manual/debugme.py", # file is intentionally broken
11766
]
11867

119-
# Same as Black.
120-
line-length = 120
12168

12269
# Allow unused variables when underscore-prefixed.
12370
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
12471

125-
[tool.ruff.flake8-quotes]
126-
inline-quotes = "double"
127-
multiline-quotes = "double"
128-
docstring-quotes = "double"
129-
130-
[tool.ruff.pydocstyle]
72+
[tool.ruff.lint.pydocstyle]
13173
convention = "google"
13274

133-
[tool.ruff.per-file-ignores]
134-
"__init__.py" = ["E402", "F401"]
75+
[tool.ruff.lint.per-file-ignores]
76+
"__init__.py" = [
77+
"E402", # Module level import not at top of file
78+
"F401", # Imported but unused
79+
]
13580

136-
[tool.ruff.pylint]
137-
max-args = 20
81+
[tool.ruff.lint.pyupgrade]
82+
# Preserve types, even if a file imports `from __future__ import annotations`.
83+
keep-runtime-typing = true
13884

13985
[tool.mypy]
14086
python_version = "3.8"
141-
exclude = [
142-
"^build/"
143-
]
87+
exclude = ["^build/"]
14488

14589
[[tool.mypy.overrides]]
14690
module = [

roboflow/core/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,17 +401,18 @@ def upload(
401401

402402
if not is_file and not is_dir:
403403
raise RuntimeError(
404-
"The provided image path [ {} ] is not a valid path. Please provide a"
405-
" path to an image or a directory.".format(image_path)
404+
f"The provided image path [ {image_path} ] is not a valid path. Please provide a"
405+
" path to an image or a directory."
406406
)
407407

408408
if is_file:
409409
is_image = is_hosted or self.check_valid_image(image_path)
410410

411411
if not is_image:
412412
raise RuntimeError(
413-
"The image you provided {} is not a supported file format. We"
414-
" currently support: {}.".format(image_path, ", ".join(ACCEPTED_IMAGE_FORMATS))
413+
"The image you provided {} is not a supported file format. We" " currently support: {}.".format(
414+
image_path, ", ".join(ACCEPTED_IMAGE_FORMATS)
415+
)
415416
)
416417

417418
self.single_upload(

roboflow/util/versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def get_wrong_dependencies_versions(
9-
dependencies_versions: List[Tuple[str, str, str]]
9+
dependencies_versions: List[Tuple[str, str, str]],
1010
) -> List[Tuple[str, str, str, str]]:
1111
"""
1212
Get a list of mismatching dependencies with current version installed.

setup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@
3232
"desktop": ["opencv-python==4.8.0.74"],
3333
"dev": [
3434
"flake8",
35-
"black==22.3.0",
36-
"isort",
35+
"mypy",
3736
"responses",
37+
"ruff",
3838
"twine",
39-
"wheel",
40-
"mypy",
41-
"types-requests",
4239
"types-pyyaml",
40+
"types-requests",
4341
"types-setuptools",
4442
"types-tqdm",
43+
"wheel",
4544
],
4645
},
4746
entry_points={

0 commit comments

Comments
 (0)