Skip to content

Commit

Permalink
feat: ✨ bring pre-commit from supervision
Browse files Browse the repository at this point in the history
Signed-off-by: Onuralp SEZER <[email protected]>
  • Loading branch information
onuralpszr committed Sep 13, 2023
1 parent f26827a commit 03d3ac3
Show file tree
Hide file tree
Showing 34 changed files with 328 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
python -m pip install --upgrade pip
pip install ".[dev]"
- name: 🚀 Publish to PyPi
env:
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
PYPI_TEST_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }}
run: |
make publish -e PYPI_USERNAME=$PYPI_USERNAME -e PYPI_PASSWORD=$PYPI_PASSWORD -e PYPI_TEST_PASSWORD=$PYPI_TEST_PASSWORD
make publish -e PYPI_USERNAME=$PYPI_USERNAME -e PYPI_PASSWORD=$PYPI_PASSWORD -e PYPI_TEST_PASSWORD=$PYPI_TEST_PASSWORD
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
run: |
make check_code_quality
- name: 🧪 Test
env:
env:
ROBOFLOW_API_KEY: ${{ secrets.ROBOFLOW_API_KEY }}
PROJECT_NAME: ${{ secrets.PROJECT_NAME }}
PROJECT_VERSION: ${{ secrets.PROJECT_VERSION }}
run: "python -m unittest"
run: "python -m unittest"
80 changes: 80 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

ci:
autofix_prs: true
autoupdate_schedule: weekly
autofix_commit_msg: "fix(pre_commit): 🎨 auto format pre-commit hooks"
autoupdate_commit_msg: "chore(pre_commit): ⬆ pre_commit autoupdate"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-toml
- id: check-case-conflict
- id: check-added-large-files
args: ['--maxkb=2048']
exclude: ^logo/
- id: detect-private-key
- id: forbid-new-submodules
- id: pretty-format-json
args: ['--autofix', '--no-sort-keys', '--indent=4']
- id: end-of-file-fixer
- id: mixed-line-ending

# - repo: https://github.com/asottile/pyupgrade
# rev: v3.9.0
# hooks:
# - id: pyupgrade
# name: Upgrade code
# args: [--py38-plus]

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

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
name: Flake8 Checks
entry: flake8
additional_dependencies: [Flake8-pyproject]


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

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]


- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.288
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ All notable changes to this project will be documented in this file.

## 1.1.5

[stub]
[stub]
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ abstract: >-
keywords:
- computer vision
- image processing
license: MIT
license: MIT
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ make style
make check_code_quality
```

**Note** These tests will be run automatically when you commit thanks to git hooks.
**Note** These tests will be run automatically when you commit thanks to git hooks.
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ RUN apt-get update && apt-get install make && rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
COPY . .
RUN pip install -e ".[dev]"
ENTRYPOINT [ "/bin/bash" ]
ENTRYPOINT [ "/bin/bash" ]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ check_code_quality:
isort --check-only --profile black $(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
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators
flake8 $(check_dirs) --count --max-line-length=88 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics

publish:
python setup.py sdist bdist_wheel
twine check dist/*
twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --verbose
twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --verbose
2 changes: 1 addition & 1 deletion docs/core/dataset.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.core.dataset
:::roboflow.core.dataset
2 changes: 1 addition & 1 deletion docs/core/model.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.core.model
:::roboflow.core.model
2 changes: 1 addition & 1 deletion docs/core/project.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.core.project
:::roboflow.core.project
2 changes: 1 addition & 1 deletion docs/core/version.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.core.version
:::roboflow.core.version
2 changes: 1 addition & 1 deletion docs/core/workspace.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.core.workspace
:::roboflow.core.workspace
2 changes: 1 addition & 1 deletion docs/models/classification.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.models.classification
:::roboflow.models.classification
2 changes: 1 addition & 1 deletion docs/models/instance-segmentation.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.models.instance_segmentation
:::roboflow.models.instance_segmentation
2 changes: 1 addition & 1 deletion docs/models/object-detection.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.models.object_detection
:::roboflow.models.object_detection
2 changes: 1 addition & 1 deletion docs/models/semantic-segmentation.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:::roboflow.models.semantic_segmentation
:::roboflow.models.semantic_segmentation
2 changes: 1 addition & 1 deletion docs/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:root {
--md-primary-fg-color:#8315F9;
}
}
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ markdown_extensions:
- pymdownx.tabbed:
alternate_style: true
- toc:
permalink: true
permalink: true
108 changes: 107 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,110 @@ requires = [
"setuptools>=57",
"wheel"
]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"



[tool.flake8]
exclude = ".venv"
max-complexity = 10
max-line-length = 88
extend-ignore = """
W503,
E203,
E701,
C901,
"""
per-file-ignores = """
__init__.py: F401
"""

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

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

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


[tool.black]
target-version = ["py38"]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| docs
)/
'''

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

# 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"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"yarn-error.log",
"yarn.lock",
"docs",
]

# Same as Black.
line-length = 88

# 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]
convention = "google"

[tool.ruff.per-file-ignores]
"__init__.py" = ["E402","F401"]

[tool.ruff.pylint]
max-args = 20
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ supervision
urllib3>=1.26.6
tqdm>=4.41.0
PyYAML>=5.3.1
requests_toolbelt
requests_toolbelt
4 changes: 2 additions & 2 deletions roboflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def initialize_roboflow(the_workspace=None):
"To use this method, you must first login - run roboflow.login()"
)
else:
if the_workspace == None:
if the_workspace is None:
active_workspace = Roboflow().workspace()
else:
active_workspace = Roboflow().workspace(the_workspace)
Expand Down Expand Up @@ -242,7 +242,7 @@ def __init__(
notebook="undefined",
):
self.api_key = api_key
if self.api_key == None:
if self.api_key is None:
self.api_key = load_roboflow_api_key()

self.model_format = model_format
Expand Down
6 changes: 3 additions & 3 deletions roboflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_conditional_configuration_variable(key, default):
else:
config = {}

if os.getenv(key) != None:
if os.getenv(key) is not None:
return os.getenv(key)
elif key in config.keys():
return config[key]
Expand Down Expand Up @@ -86,7 +86,7 @@ def load_roboflow_api_key():
RF_WORKSPACES = get_conditional_configuration_variable("workspaces", default={})

# DEFAULT_WORKSPACE = get_conditional_configuration_variable("default_workspace", default=None)
if RF_WORKSPACE == None:
if RF_WORKSPACE is None:
RF_API_KEY = None
else:
RF_API_KEY = None
Expand All @@ -95,7 +95,7 @@ def load_roboflow_api_key():
if workspace["url"] == RF_WORKSPACE:
RF_API_KEY = workspace["apiKey"]
# ENV API_KEY OVERRIDE
if os.getenv("RF_API_KEY") != None:
if os.getenv("RF_API_KEY") is not None:
RF_API_KEY = os.getenv("RF_API_KEY")

return RF_API_KEY
Loading

0 comments on commit 03d3ac3

Please sign in to comment.