Skip to content

Commit 554a82e

Browse files
removed errors/warnings
1 parent ddb256f commit 554a82e

16 files changed

Lines changed: 874 additions & 442 deletions

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test WorkFlow
2+
3+
on:
4+
pull_request:
5+
branches: [main, develop]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: [3.7, 3.8, 3.9]
13+
14+
steps:
15+
- name: 🛎️ Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
ref: ${{ github.head_ref }}
19+
20+
- name: 🐍 Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: 🦾 Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install ".[dev]"
28+
- name: 🧹 Lint with flake8
29+
run: |
30+
make check_code_quality
31+
- name: 🧪 Test with pytest
32+
run: "python -m pytest ."

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# env specific
2+
config.json
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: style check_code_quality
2+
3+
export PYTHONPATH = .
4+
check_dirs := roboflow
5+
6+
style:
7+
black $(check_dirs)
8+
isort --profile black $(check_dirs)
9+
10+
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=88 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics
17+

roboflow/__init__.py

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,64 @@
11
import json
2-
import os
3-
import time
42
import sys
53

64
import requests
7-
from roboflow.core.workspace import Workspace
5+
6+
from roboflow.config import API_URL, APP_URL, DEMO_KEYS
87
from roboflow.core.project import Project
9-
from roboflow.config import *
8+
from roboflow.core.workspace import Workspace
9+
1010

1111
def check_key(api_key, model, notebook):
1212
if type(api_key) is not str:
1313
raise RuntimeError(
14-
"API Key is of Incorrect Type \n Expected Type: " + str(type("")) + "\n Input Type: " + str(type(api_key)))
15-
16-
if any(c for c in api_key if c.islower()): #check if any of the api key characters are lowercase
14+
"API Key is of Incorrect Type \n Expected Type: "
15+
+ str(type(""))
16+
+ "\n Input Type: "
17+
+ str(type(api_key))
18+
)
19+
20+
if any(
21+
c for c in api_key if c.islower()
22+
): # check if any of the api key characters are lowercase
1723
if api_key in DEMO_KEYS:
18-
#passthrough for public download of COCO-128 for the time being
24+
# passthrough for public download of COCO-128 for the time being
1925
return api_key
2026
else:
21-
#validate key normally
27+
# validate key normally
2228
response = requests.post(API_URL + "/?api_key=" + api_key)
2329
r = response.json()
2430

2531
if "error" in r or response.status_code != 200:
2632
raise RuntimeError(response.text)
2733
else:
2834
return r
29-
else: #then you're using a dummy key
30-
sys.stdout.write("upload and label your dataset, and get an API KEY here: " + APP_URL + "/?model=" + model + "&ref=" + notebook + "\n")
35+
else: # then you're using a dummy key
36+
sys.stdout.write(
37+
"upload and label your dataset, and get an API KEY here: "
38+
+ APP_URL
39+
+ "/?model="
40+
+ model
41+
+ "&ref="
42+
+ notebook
43+
+ "\n"
44+
)
3145
return "onboarding"
3246

3347

3448
def auth(api_key):
3549
r = check_key(api_key)
36-
w = r['workspace']
50+
w = r["workspace"]
3751

3852
return Roboflow(api_key, w)
3953

4054

41-
class Roboflow():
42-
def __init__(self, api_key="YOUR ROBOFLOW API KEY HERE", model_format="undefined", notebook="undefined"):
55+
class Roboflow:
56+
def __init__(
57+
self,
58+
api_key="YOUR ROBOFLOW API KEY HERE",
59+
model_format="undefined",
60+
notebook="undefined",
61+
):
4362
self.api_key = api_key
4463
self.model_format = model_format
4564
self.notebook = notebook
@@ -50,14 +69,14 @@ def auth(self):
5069
r = check_key(self.api_key, self.model_format, self.notebook)
5170

5271
if r == "onboarding":
53-
self.onboarding = True
72+
self.onboarding = True
5473
return self
5574
elif r in DEMO_KEYS:
5675
self.universe = True
5776
return self
5877
else:
59-
w = r['workspace']
60-
self.current_workspace=w
78+
w = r["workspace"]
79+
self.current_workspace = w
6180
return self
6281

6382
def workspace(self, the_workspace=None):
@@ -71,7 +90,9 @@ def workspace(self, the_workspace=None):
7190
if self.api_key in DEMO_KEYS:
7291
return Workspace({}, self.api_key, the_workspace, self.model_format)
7392

74-
list_projects = requests.get(API_URL + "/" + the_workspace + '?api_key=' + self.api_key).json()
93+
list_projects = requests.get(
94+
API_URL + "/" + the_workspace + "?api_key=" + self.api_key
95+
).json()
7596

7697
return Workspace(list_projects, self.api_key, the_workspace, self.model_format)
7798

@@ -89,19 +110,25 @@ def project(self, project_name, the_workspace=None):
89110
else:
90111
the_workspace = self.current_workspace
91112

92-
dataset_info = requests.get(API_URL + "/" + the_workspace + "/" + project_name + "?api_key=" + self.api_key)
113+
dataset_info = requests.get(
114+
API_URL
115+
+ "/"
116+
+ the_workspace
117+
+ "/"
118+
+ project_name
119+
+ "?api_key="
120+
+ self.api_key
121+
)
93122

94123
# Throw error if dataset isn't valid/user doesn't have permissions to access the dataset
95124
if dataset_info.status_code != 200:
96125
raise RuntimeError(dataset_info.text)
97126

98-
dataset_info = dataset_info.json()['project']
127+
dataset_info = dataset_info.json()["project"]
99128

100129
return Project(self.api_key, dataset_info)
101130

102131
def __str__(self):
103-
"""to string function
104-
"""
105-
json_value = {'api_key': self.api_key,
106-
'workspace': self.workspace}
107-
return json.dumps(json_value, indent=2)
132+
"""to string function"""
133+
json_value = {"api_key": self.api_key, "workspace": self.workspace}
134+
return json.dumps(json_value, indent=2)

roboflow/config.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import os
22

3-
OBJECT_DETECTION_MODEL = os.getenv("OBJECT_DETECTION_MODEL", default="ObjectDetectionModel")
3+
OBJECT_DETECTION_MODEL = os.getenv(
4+
"OBJECT_DETECTION_MODEL", default="ObjectDetectionModel"
5+
)
46
CLASSIFICATION_MODEL = os.getenv("CLASSIFICATION_MODEL", default="ClassificationModel")
57
PREDICTION_OBJECT = os.getenv("PREDICTION_OBJECT", default="Prediction")
68
API_URL = os.getenv("API_URL", default="https://api.roboflow.com")
79
APP_URL = os.getenv("APP_URL", default="https://app.roboflow.com")
8-
CLIP_FEATURIZE_URL = os.getenv("CLIP_FEATURIZE_URL", default="CLIP FEATURIZE URL NOT IN ENV")
9-
DEMO_KEYS = ['coco-128-sample', 'chess-sample-only-api-key']
10+
CLIP_FEATURIZE_URL = os.getenv(
11+
"CLIP_FEATURIZE_URL", default="CLIP FEATURIZE URL NOT IN ENV"
12+
)
13+
DEMO_KEYS = ["coco-128-sample", "chess-sample-only-api-key"]

roboflow/core/dataset.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
import os
2-
from roboflow.config import *
3-
import sys
4-
5-
class Dataset():
1+
class Dataset:
62
def __init__(self, name, version, model_format, location):
73
self.name = name
84
self.name = version
95
self.model_format = model_format
106
self.location = location
11-
#resolution
12-
#num_train, num_val, num_test
13-
#class_names
14-
15-
#def describe
16-
17-
#def visualize
18-
19-
#def sort_by_sim
20-
21-
#def sample
22-
23-
#def query

roboflow/core/model.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
class Model():
1+
class Model:
22
def __init__(self, model):
3-
self.id = model['id']
4-
5-
self.endpoint = model['endpoint']
6-
self.duration = model['end'] - model['start']
7-
self.statistics = {'recall': model['recall'], 'precision': model['precision'], 'map': model['map']}
8-
9-
3+
self.id = model["id"]
4+
self.endpoint = model["endpoint"]
5+
self.duration = model["end"] - model["start"]
6+
self.statistics = {
7+
"recall": model["recall"],
8+
"precision": model["precision"],
9+
"map": model["map"],
10+
}

0 commit comments

Comments
 (0)