onuralpszr commited on
Commit
b4da4e7
1 Parent(s): 8f4be85

feat: ✨ ruff/python style and pre-commit added for github

Browse files

Signed-off-by: Onuralp SEZER <[email protected]>

Files changed (4) hide show
  1. .gitignore +1 -1
  2. .pre-commit-config.yaml +54 -0
  3. app.py +6 -5
  4. pyproject.toml +109 -0
.gitignore CHANGED
@@ -166,4 +166,4 @@ cython_debug/
166
 
167
  # YoloV8 files
168
  yolov8s-seg.pt
169
- yolov8s.pt
 
166
 
167
  # YoloV8 files
168
  yolov8s-seg.pt
169
+ yolov8s.pt
.pre-commit-config.yaml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ci:
3
+ autofix_prs: true
4
+ autoupdate_schedule: weekly
5
+ autofix_commit_msg: "fix(pre_commit): 🎨 auto format pre-commit hooks"
6
+ autoupdate_commit_msg: "chore(pre_commit): ⬆ pre_commit autoupdate"
7
+
8
+ repos:
9
+ - repo: https://github.com/pre-commit/pre-commit-hooks
10
+ rev: v4.5.0
11
+ hooks:
12
+ - id: end-of-file-fixer
13
+ - id: trailing-whitespace
14
+ exclude: test/.*\.py
15
+ - id: check-yaml
16
+ - id: check-docstring-first
17
+ - id: check-executables-have-shebangs
18
+ - id: check-toml
19
+ - id: check-case-conflict
20
+ - id: check-added-large-files
21
+ - id: detect-private-key
22
+ - id: forbid-new-submodules
23
+ - id: pretty-format-json
24
+ exclude: demo.ipynb
25
+ args: ['--autofix', '--no-sort-keys', '--indent=4']
26
+ - id: end-of-file-fixer
27
+ - id: mixed-line-ending
28
+
29
+
30
+
31
+ - repo: https://github.com/PyCQA/bandit
32
+ rev: '1.7.6'
33
+ hooks:
34
+ - id: bandit
35
+ args: ["-c", "pyproject.toml"]
36
+ additional_dependencies: ["bandit[toml]"]
37
+
38
+ - repo: https://github.com/pycqa/isort
39
+ rev: 5.13.0
40
+ hooks:
41
+ - id: isort
42
+ name: isort (python)
43
+ - id: isort
44
+ name: isort (pyi)
45
+ types: [pyi]
46
+
47
+
48
+ - repo: https://github.com/astral-sh/ruff-pre-commit
49
+ rev: v0.1.7
50
+ hooks:
51
+ - id: ruff
52
+ args: [--fix, --exit-non-zero-on-fix]
53
+ - id: ruff-format
54
+ types_or: [ python, pyi, jupyter ]
app.py CHANGED
@@ -22,7 +22,8 @@ DUPLICATE = """
22
  <img src="https://bit.ly/3gLdBN6" alt="Duplicate Space" style="margin-right: 10px;">
23
  </a>
24
  </div>
25
- """
 
26
 
27
  def load_model(img):
28
  # Load model, get results and return detections/labels
@@ -60,7 +61,7 @@ def annotator(
60
  colorcir,
61
  colorlabel,
62
  colorhalo,
63
- colortri
64
  ):
65
  """
66
  Function that changes the color of annotators
@@ -126,12 +127,12 @@ def annotator(
126
  # Draw HeatMapAnnotator
127
  heatmap_annotator = sv.HeatMapAnnotator()
128
  img = heatmap_annotator.annotate(img, detections=detections)
129
-
130
  if "Dot" in annotators:
131
  # Draw DotAnnotator
132
  dot_annotator = sv.DotAnnotator()
133
  img = dot_annotator.annotate(img, detections=detections)
134
-
135
  if "Triangle" in annotators:
136
  # Draw TriangleAnnotator
137
  tri_annotator = sv.TriangleAnnotator(sv.Color.from_hex(str(colortri)))
@@ -179,7 +180,7 @@ with gr.Blocks(theme=purple_theme) as app:
179
  "Pixelate",
180
  "HeatMap",
181
  "Dot",
182
- "Triangle"
183
  ],
184
  value=["BoundingBox", "Mask"],
185
  label="Select Annotators:",
 
22
  <img src="https://bit.ly/3gLdBN6" alt="Duplicate Space" style="margin-right: 10px;">
23
  </a>
24
  </div>
25
+ """ # noqa: E501 title/docs
26
+
27
 
28
  def load_model(img):
29
  # Load model, get results and return detections/labels
 
61
  colorcir,
62
  colorlabel,
63
  colorhalo,
64
+ colortri,
65
  ):
66
  """
67
  Function that changes the color of annotators
 
127
  # Draw HeatMapAnnotator
128
  heatmap_annotator = sv.HeatMapAnnotator()
129
  img = heatmap_annotator.annotate(img, detections=detections)
130
+
131
  if "Dot" in annotators:
132
  # Draw DotAnnotator
133
  dot_annotator = sv.DotAnnotator()
134
  img = dot_annotator.annotate(img, detections=detections)
135
+
136
  if "Triangle" in annotators:
137
  # Draw TriangleAnnotator
138
  tri_annotator = sv.TriangleAnnotator(sv.Color.from_hex(str(colortri)))
 
180
  "Pixelate",
181
  "HeatMap",
182
  "Dot",
183
+ "Triangle",
184
  ],
185
  value=["BoundingBox", "Mask"],
186
  label="Select Annotators:",
pyproject.toml ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.isort]
2
+ line_length = 88
3
+ profile = "black"
4
+
5
+ [tool.bandit]
6
+ target = ["test", "supervision"]
7
+ tests = ["B201", "B301", "B318", "B314", "B303", "B413", "B412", "B410"]
8
+
9
+ [tool.autoflake]
10
+ check = true
11
+ imports = ["cv2", "supervision"]
12
+
13
+
14
+ [tool.black]
15
+ target-version = ["py38"]
16
+ line-length = 88
17
+ include = '\.pyi?$'
18
+ exclude = '''
19
+ /(
20
+ \.git
21
+ | \.hg
22
+ | \.mypy_cache
23
+ | \.tox
24
+ | \.venv
25
+ | _build
26
+ | buck-out
27
+ | build
28
+ | dist
29
+ | docs
30
+ )/
31
+ '''
32
+
33
+ [tool.ruff]
34
+ target-version = "py38"
35
+ # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
36
+ select = ["E", "F"]
37
+ ignore = []
38
+
39
+ # Allow autofix for all enabled rules (when `--fix`) is provided.
40
+ 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"]
41
+ unfixable = []
42
+
43
+ # Exclude a variety of commonly ignored directories.
44
+ exclude = [
45
+ ".bzr",
46
+ ".direnv",
47
+ ".eggs",
48
+ ".git",
49
+ ".git-rewrite",
50
+ ".hg",
51
+ ".mypy_cache",
52
+ ".nox",
53
+ ".pants.d",
54
+ ".pytype",
55
+ ".ruff_cache",
56
+ ".svn",
57
+ ".tox",
58
+ ".venv",
59
+ "__pypackages__",
60
+ "_build",
61
+ "buck-out",
62
+ "build",
63
+ "dist",
64
+ "node_modules",
65
+ "venv",
66
+ "yarn-error.log",
67
+ "yarn.lock",
68
+ "docs",
69
+ ]
70
+
71
+ # Same as Black.
72
+ line-length = 88
73
+ indent-width = 4
74
+
75
+ # Allow unused variables when underscore-prefixed.
76
+ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
77
+
78
+ [tool.ruff.flake8-quotes]
79
+ inline-quotes = "double"
80
+ multiline-quotes = "double"
81
+ docstring-quotes = "double"
82
+
83
+ [tool.ruff.pydocstyle]
84
+ convention = "google"
85
+
86
+ [tool.ruff.per-file-ignores]
87
+ "__init__.py" = ["E402","F401"]
88
+ "supervision/assets/list.py" = ["E501"]
89
+
90
+ [tool.ruff.lint.mccabe]
91
+ # Flag errors (`C901`) whenever the complexity level exceeds 5.
92
+ max-complexity = 20
93
+
94
+
95
+ [tool.ruff.pylint]
96
+ max-args = 20
97
+
98
+ [tool.ruff.format]
99
+ # Like Black, use double quotes for strings.
100
+ quote-style = "double"
101
+
102
+ # Like Black, indent with spaces, rather than tabs.
103
+ indent-style = "space"
104
+
105
+ # Like Black, respect magic trailing commas.
106
+ skip-magic-trailing-comma = false
107
+
108
+ # Like Black, automatically detect the appropriate line ending.
109
+ line-ending = "auto"