Skip to content

Commit

Permalink
chore: streamline linting and formatting process
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
cdragos committed Jul 7, 2024
1 parent e4eb379 commit 889ee39
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 116 deletions.
37 changes: 12 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ repos:
- id: forbid-new-submodules
- id: mixed-line-ending
- id: pretty-format-json
args: ['--autofix', '--no-sort-keys', '--indent=4']
args: ["--autofix", "--no-sort-keys", "--indent=4"]
- id: trailing-whitespace


- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
name: Sort imports

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
Expand All @@ -38,22 +31,16 @@ repos:
entry: flake8
additional_dependencies: [Flake8-pyproject]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export PYTHONPATH = .
check_dirs := roboflow

style:
black $(check_dirs)
isort --profile black $(check_dirs)
ruff format $(check_dirs)
ruff check $(check_dirs) --fix

check_code_quality:
black --check $(check_dirs)
isort --check-only --profile black $(check_dirs)
ruff format $(check_dirs) --check
ruff check $(check_dirs)
# stop the build if there are Python syntax errors or undefined names
flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators
Expand Down
98 changes: 21 additions & 77 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
requires = ["setuptools>=57", "wheel"]
build-backend = "setuptools.build_meta"


[tool.flake8]
exclude = ".venv"
max-complexity = 10
Expand All @@ -17,75 +16,25 @@ per-file-ignores = """
__init__.py: F401
"""

[tool.black]
line-length = 120

[tool.isort]
line_length = 120
profile = "black"

[tool.bandit]
target = ["test", "roboflow"]
tests = ["B201", "B301"]

[tool.autoflake]
check = true
imports = ["cv2", "roboflow"]

[tool.ruff]
target-version = "py38"
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F"]
ignore = []
# Same as Black.
line-length = 120

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"I",
"N",
"Q",
"S",
"T",
"W",
"ANN",
"ARG",
"BLE",
"COM",
"DJ",
"DTZ",
"EM",
"ERA",
"EXE",
"FBT",
"ICN",
"INP",
"ISC",
"NPY",
"PD",
"PGH",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"RET",
"RSE",
"RUF",
"SIM",
"SLF",
"TCH",
"TID",
"TRY",
"UP",
"YTT",
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
]
ignore = [
"E501", # line too long, handled by black
]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
Expand Down Expand Up @@ -116,31 +65,26 @@ exclude = [
"tests/manual/debugme.py", # file is intentionally broken
]

# Same as Black.
line-length = 120

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

[tool.ruff.flake8-quotes]
inline-quotes = "double"
multiline-quotes = "double"
docstring-quotes = "double"

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

[tool.ruff.per-file-ignores]
"__init__.py" = ["E402", "F401"]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"E402", # Module level import not at top of file
"F401", # Imported but unused
]

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

[tool.mypy]
python_version = "3.8"
exclude = [
"^build/"
]
exclude = ["^build/"]

[[tool.mypy.overrides]]
module = [
Expand Down
9 changes: 5 additions & 4 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,18 @@ def upload(

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

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

if not is_image:
raise RuntimeError(
"The image you provided {} is not a supported file format. We"
" currently support: {}.".format(image_path, ", ".join(ACCEPTED_IMAGE_FORMATS))
"The image you provided {} is not a supported file format. We" " currently support: {}.".format(
image_path, ", ".join(ACCEPTED_IMAGE_FORMATS)
)
)

self.single_upload(
Expand Down
2 changes: 1 addition & 1 deletion roboflow/util/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def get_wrong_dependencies_versions(
dependencies_versions: List[Tuple[str, str, str]]
dependencies_versions: List[Tuple[str, str, str]],
) -> List[Tuple[str, str, str, str]]:
"""
Get a list of mismatching dependencies with current version installed.
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
"desktop": ["opencv-python==4.8.0.74"],
"dev": [
"flake8",
"black==22.3.0",
"isort",
"mypy",
"responses",
"ruff",
"twine",
"wheel",
"mypy",
"types-requests",
"types-pyyaml",
"types-requests",
"types-setuptools",
"types-tqdm",
"wheel",
],
},
entry_points={
Expand Down

0 comments on commit 889ee39

Please sign in to comment.