Skip to content

Commit e4eb379

Browse files
authored
Merge pull request #277 from cdragos/chore/enhance-precommit-and-update-docs
chore: enhance pre-commit setup and correct installation instructions
2 parents 6ad510b + 6e52f4b commit e4eb379

20 files changed

+99
-43
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ ci:
66

77
repos:
88
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v4.5.0
9+
rev: v4.6.0
1010
hooks:
11-
- id: end-of-file-fixer
12-
- id: trailing-whitespace
13-
- id: check-yaml
11+
- id: check-added-large-files
12+
- id: check-case-conflict
1413
- id: check-docstring-first
1514
- id: check-executables-have-shebangs
1615
- id: check-toml
17-
- id: check-case-conflict
18-
- id: check-added-large-files
16+
- id: check-yaml
1917
- id: detect-private-key
18+
- id: end-of-file-fixer
19+
- id: end-of-file-fixer
2020
- id: forbid-new-submodules
21+
- id: mixed-line-ending
2122
- id: pretty-format-json
2223
args: ['--autofix', '--no-sort-keys', '--indent=4']
23-
- id: end-of-file-fixer
24-
- id: mixed-line-ending
24+
- id: trailing-whitespace
2525

2626

2727
- repo: https://github.com/PyCQA/isort
@@ -31,7 +31,7 @@ repos:
3131
name: Sort imports
3232

3333
- repo: https://github.com/PyCQA/flake8
34-
rev: 6.1.0
34+
rev: 7.1.0
3535
hooks:
3636
- id: flake8
3737
name: Flake8 Checks
@@ -40,14 +40,20 @@ repos:
4040

4141

4242
- repo: https://github.com/PyCQA/bandit
43-
rev: '1.7.6'
43+
rev: 1.7.9
4444
hooks:
4545
- id: bandit
4646
args: ["-c", "pyproject.toml"]
4747
additional_dependencies: ["bandit[toml]"]
4848

4949
- repo: https://github.com/astral-sh/ruff-pre-commit
50-
rev: v0.1.9
50+
rev: v0.5.0
5151
hooks:
5252
- id: ruff
5353
args: [--fix, --exit-non-zero-on-fix]
54+
55+
- repo: https://github.com/asottile/pyupgrade
56+
rev: v3.16.0
57+
hooks:
58+
- id: pyupgrade
59+
args: [--py38-plus]

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ If you want to extend our Python library or if you find a bug, please open a PR!
55

66
Also be sure to test your code with the `unittest` command at the `/root` level directory.
77

8+
## Installation for Contributors
9+
10+
Before starting your work on the project, set up your development environment:
11+
12+
1. Clone the repository:
13+
```bash
14+
git clone https://github.com/roboflow-ai/roboflow-python.git
15+
cd roboflow-python
16+
```
17+
18+
2. Create and activate a virtual environment:
19+
```bash
20+
python3 -m venv env
21+
source env/bin/activate
22+
```
23+
24+
3.Install the package in editable mode with development dependencies:
25+
```bash
26+
pip install -e ".[dev]"
27+
```
28+
829
### Devcontainer
930

1031
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.
@@ -54,3 +75,25 @@ Before that, install the dependencies:
5475
```python
5576
python -m pip install mkdocs mkdocs-material mkdocstrings mkdocstrings[python]
5677
```
78+
79+
### Pre-commit Hooks
80+
81+
To ensure code quality and consistency, we use pre-commit hooks. Follow these steps to set up pre-commit in your development environment:
82+
83+
1. Install pre-commit:
84+
```bash
85+
pip install pre-commit
86+
```
87+
88+
2. Install the git hook scripts:
89+
```bash
90+
pre-commit install
91+
```
92+
93+
After installation, `pre-commit` will automatically run on git commit. The hooks perform checks and corrections related to code formatting, linting, and other rules as defined in the `.pre-commit-config.yaml` file.
94+
95+
Note: If you need to bypass pre-commit hooks temporarily, you can use the `--no-verify` flag:
96+
97+
```bash
98+
git commit --no-verify -m "Your commit message"
99+
```

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ Run the following command to install the Roboflow Python package:
4444
pip install roboflow
4545
```
4646

47+
For desktop features, use:
48+
49+
```bash
50+
pip install "roboflow[desktop]"
51+
```
52+
53+
4754
<details>
4855
<summary>Install from source</summary>
4956

@@ -54,7 +61,7 @@ pip install roboflow
5461
cd roboflow-python
5562
python3 -m venv env
5663
source env/bin/activate
57-
pip3 install -r requirements.txt
64+
pip install .
5865
```
5966
</details>
6067

roboflow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def check_key(api_key, model, notebook, num_retries=0):
2121
if not isinstance(api_key, str):
2222
raise RuntimeError(
23-
"API Key is of Incorrect Type \n Expected Type: " + str(type("")) + "\n Input Type: " + str(type(api_key))
23+
"API Key is of Incorrect Type \n Expected Type: " + str(str) + "\n Input Type: " + str(type(api_key))
2424
)
2525

2626
if any(c for c in api_key if c.islower()): # check if any of the api key characters are lowercase

roboflow/core/project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def version(self, version_number: int, local: Optional[str] = None):
335335
)
336336
return vers
337337

338-
raise RuntimeError("Version number {} is not found.".format(version_number))
338+
raise RuntimeError(f"Version number {version_number} is not found.")
339339

340340
def check_valid_image(self, image_path: str):
341341
"""
@@ -534,8 +534,8 @@ def _annotation_params(self, annotation_path):
534534
annotation_name = annotation_path["name"]
535535
annotation_string = annotation_path["rawText"]
536536
elif os.path.exists(annotation_path):
537-
with open(annotation_path, "r"):
538-
annotation_string = open(annotation_path, "r").read()
537+
with open(annotation_path):
538+
annotation_string = open(annotation_path).read()
539539
annotation_name = os.path.basename(annotation_path)
540540
elif self.type == "classification":
541541
print(f"-> using {annotation_path} as classname for classification project")

roboflow/core/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def deploy(self, model_type: str, model_path: str, filename: str = "weights/best
541541
elif "yolov5" in model_type or "yolov7" in model_type or "yolov9" in model_type:
542542
# parse from yaml for yolov5
543543

544-
with open(os.path.join(model_path, "opt.yaml"), "r") as stream:
544+
with open(os.path.join(model_path, "opt.yaml")) as stream:
545545
opts = yaml.safe_load(stream)
546546

547547
model_artifacts = {
@@ -651,7 +651,7 @@ def deploy_yolonas(self, model_type: str, model_path: str, filename: str = "weig
651651
f"architecture: <one of [yolo_nas_s, yolo_nas_m, yolo_nas_l]."
652652
f"s, m, l refer to small, medium, large architecture sizes, respectively>\n"
653653
)
654-
with open(os.path.join(model_path, "opt.yaml"), "r") as stream:
654+
with open(os.path.join(model_path, "opt.yaml")) as stream:
655655
opts = yaml.safe_load(stream)
656656
required_keys = ["imgsz", "batch_size", "architecture"]
657657
for key in required_keys:

roboflow/core/workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def project(self, project_id):
8282
# project_id = project_id.replace(self.url + "/", "")
8383

8484
if "/" in project_id:
85-
raise RuntimeError("The {} project is not available in this ({}) workspace".format(project_id, self.url))
85+
raise RuntimeError(f"The {project_id} project is not available in this ({self.url}) workspace")
8686

8787
dataset_info = rfapi.get_project(self.__api_key, self.url, project_id)
8888
dataset_info = dataset_info["project"]

roboflow/models/classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
ClassificationModel Object
4747
"""
4848
# Instantiate different API URL parameters
49-
super(ClassificationModel, self).__init__(api_key, id, version=version)
49+
super().__init__(api_key, id, version=version)
5050
self.__api_key = api_key
5151
self.id = id
5252
self.name = name

roboflow/models/instance_segmentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
preprocessing (dict): preprocessing to use for the image
2929
local (str): localhost address and port if pointing towards local inference engine
3030
"""
31-
super(InstanceSegmentationModel, self).__init__(api_key, version_id)
31+
super().__init__(api_key, version_id)
3232

3333
base_url = local or INSTANCE_SEGMENTATION_URL
3434
self.api_url = f"{base_url}/{self.dataset_id}/{self.version}"
@@ -57,7 +57,7 @@ def predict(self, image_path, confidence=40):
5757
5858
>>> prediction = model.predict("YOUR_IMAGE.jpg")
5959
""" # noqa: E501
60-
return super(InstanceSegmentationModel, self).predict(
60+
return super().predict(
6161
image_path,
6262
confidence=confidence,
6363
prediction_type=INSTANCE_SEGMENTATION_MODEL,

roboflow/models/keypoint_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
ClassificationModel Object
4545
"""
4646
# Instantiate different API URL parameters
47-
super(KeypointDetectionModel, self).__init__(api_key, id, version=version)
47+
super().__init__(api_key, id, version=version)
4848
self.__api_key = api_key
4949
self.id = id
5050
self.name = name

0 commit comments

Comments
 (0)