Skip to content

Commit be0a939

Browse files
authored
Merge pull request #282 from cdragos/chore/streamline-linting
chore: streamline linting and formatting process
2 parents e4eb379 + 9f59f71 commit be0a939

File tree

10 files changed

+60
-131
lines changed

10 files changed

+60
-131
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"extensions": [
1010
"ms-python.python",
1111
"ms-python.debugpy",
12-
"ms-python.black-formatter"
12+
"charliermarsh.ruff"
1313
],
1414
"settings": {
1515
"extensions.verifySignature": false

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: |
2828
python -m pip install --upgrade pip
2929
pip install ".[dev]"
30-
- name: 🧹 Lint with flake8
30+
- name: 🧹 Lint
3131
run: |
3232
make check_code_quality
3333
- name: Check types with mypy

.pre-commit-config.yaml

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,19 @@ 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-
33-
- repo: https://github.com/PyCQA/flake8
34-
rev: 7.1.0
26+
- repo: https://github.com/PyCQA/bandit
27+
rev: 1.7.9
3528
hooks:
36-
- id: flake8
37-
name: Flake8 Checks
38-
entry: flake8
39-
additional_dependencies: [Flake8-pyproject]
40-
41-
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]
29+
- id: bandit
30+
args: ["-c", "pyproject.toml"]
31+
additional_dependencies: ["bandit[toml]"]
5432

55-
- repo: https://github.com/asottile/pyupgrade
56-
rev: v3.16.0
33+
- repo: https://github.com/astral-sh/ruff-pre-commit
34+
rev: v0.5.1
5735
hooks:
58-
- id: pyupgrade
59-
args: [--py38-plus]
36+
- id: ruff-format
37+
- id: ruff
38+
args: [--fix, --exit-non-zero-on-fix]

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
],
1313
"editor.formatOnSave": true,
1414
"[python]": {
15-
"editor.defaultFormatter": "ms-python.black-formatter"
15+
"editor.defaultFormatter": "charliermarsh.ruff"
1616
},
17-
"python.formatting.provider": "none",
1817
"python.testing.pytestEnabled": false,
1918
"editor.inlineSuggest.showToolbar": "onHover"
2019
}

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pip install -e ".[dev]"
2828

2929
### Devcontainer
3030

31-
This project comes with a [convenient devcontainer](https://www.loom.com/share/a183c4a351ed4700a79476fedf08ab9b) that makes it easier to run tests and has black configured to run on save.
31+
This project comes with a [convenient devcontainer](https://www.loom.com/share/a183c4a351ed4700a79476fedf08ab9b) that makes it easier to run tests and has lint configured to run on save.
3232

3333
On rare occasions a full rebuild is needed, you can do it in VSCode by pressing `Ctrl+Shift+P` and running `Dev Containers: Rebuild Container`.
3434

@@ -57,10 +57,10 @@ def example_function(param1: int, param2: str) -> bool:
5757
We provide a `Makefile` to format and ensure code quality. **Be sure to run them before creating a PR**.
5858

5959
```bash
60-
# format code with `black` and `isort`
60+
# format code with `ruff`
6161
make style
6262

63-
# check code with flake8
63+
# check code with `ruff`
6464
make check_code_quality
6565
```
6666

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +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)
13-
# stop the build if there are Python syntax errors or undefined names
14-
flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics
15-
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators
16-
flake8 $(check_dirs) --count --max-line-length=120 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics
11+
ruff format $(check_dirs) --check
12+
ruff check $(check_dirs)
1713

1814
publish:
1915
python setup.py sdist bdist_wheel

pyproject.toml

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

5-
6-
[tool.flake8]
7-
exclude = ".venv"
8-
max-complexity = 10
9-
max-line-length = 120
10-
extend-ignore = """
11-
W503,
12-
E203,
13-
E701,
14-
C901,
15-
"""
16-
per-file-ignores = """
17-
__init__.py: F401
18-
"""
19-
20-
[tool.black]
21-
line-length = 120
22-
23-
[tool.isort]
24-
line_length = 120
25-
profile = "black"
26-
275
[tool.bandit]
286
target = ["test", "roboflow"]
297
tests = ["B201", "B301"]
308

31-
[tool.autoflake]
32-
check = true
33-
imports = ["cv2", "roboflow"]
34-
359
[tool.ruff]
3610
target-version = "py38"
37-
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
38-
select = ["E", "F"]
39-
ignore = []
11+
line-length = 120
4012

41-
# Allow autofix for all enabled rules (when `--fix`) is provided.
42-
fixable = [
13+
[tool.ruff.lint]
14+
select = [
15+
"ALL",
16+
]
17+
ignore = [
4318
"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",
5619
"ANN",
5720
"ARG",
21+
"B",
5822
"BLE",
23+
"C",
5924
"COM",
60-
"DJ",
25+
"D",
6126
"DTZ",
6227
"EM",
6328
"ERA",
64-
"EXE",
6529
"FBT",
66-
"ICN",
67-
"INP",
30+
"FIX",
31+
"FLY",
32+
"FURB",
6833
"ISC",
69-
"NPY",
70-
"PD",
71-
"PGH",
34+
"N",
35+
"PERF",
7236
"PIE",
73-
"PL",
37+
"PLR",
38+
"PLW",
7439
"PT",
7540
"PTH",
76-
"PYI",
7741
"RET",
78-
"RSE",
7942
"RUF",
43+
"S",
8044
"SIM",
8145
"SLF",
82-
"TCH",
83-
"TID",
46+
"T",
47+
"TD",
8448
"TRY",
85-
"UP",
86-
"YTT",
8749
]
88-
unfixable = []
8950

9051
# Exclude a variety of commonly ignored directories.
9152
exclude = [
@@ -116,31 +77,26 @@ exclude = [
11677
"tests/manual/debugme.py", # file is intentionally broken
11778
]
11879

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

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

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

133-
[tool.ruff.per-file-ignores]
134-
"__init__.py" = ["E402", "F401"]
87+
[tool.ruff.lint.per-file-ignores]
88+
"__init__.py" = [
89+
"E402", # Module level import not at top of file
90+
"F401", # Imported but unused
91+
]
13592

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

13997
[tool.mypy]
14098
python_version = "3.8"
141-
exclude = [
142-
"^build/"
143-
]
99+
exclude = ["^build/"]
144100

145101
[[tool.mypy.overrides]]
146102
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@
3131
extras_require={
3232
"desktop": ["opencv-python==4.8.0.74"],
3333
"dev": [
34-
"flake8",
35-
"black==22.3.0",
36-
"isort",
34+
"mypy",
3735
"responses",
36+
"ruff",
3837
"twine",
39-
"wheel",
40-
"mypy",
41-
"types-requests",
4238
"types-pyyaml",
39+
"types-requests",
4340
"types-setuptools",
4441
"types-tqdm",
42+
"wheel",
4543
],
4644
},
4745
entry_points={

0 commit comments

Comments
 (0)