Skip to content

Commit d53389d

Browse files
committed
chore: address comments on the PR
1 parent 08b732a commit d53389d

14 files changed

+54
-38
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ style:
1010
check_code_quality:
1111
ruff format $(check_dirs) --check
1212
ruff check $(check_dirs)
13-
pyright $(check_dirs)
13+
mypy $(check_dirs)
1414

1515
publish:
1616
python setup.py sdist bdist_wheel

pyproject.toml

+20-8
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,23 @@ convention = "google"
9292
# Preserve types, even if a file imports `from __future__ import annotations`.
9393
keep-runtime-typing = true
9494

95-
[tool.pyright]
96-
pythonVersion = "3.8"
97-
exclude = ["build", ".venv", "venv*", "docs", "Tests"]
98-
venvPath = "."
99-
venv = ".venv"
100-
reportMissingImports = false
101-
reportUnboundVariable = false
102-
reportIncompatibleMethodOverride = false
95+
[tool.mypy]
96+
python_version = "3.8"
97+
exclude = ["^build/"]
98+
99+
[[tool.mypy.overrides]]
100+
module = [
101+
"_datetime.*",
102+
"filetype.*",
103+
# IPython is an optional dependency
104+
"IPython.display.*",
105+
# ipywidgets is an optional dependency
106+
"ipywidgets.*",
107+
# matplotlib typing is not available for Python 3.8
108+
# remove this when we stop supporting Python 3.8
109+
"matplotlib.*",
110+
"requests_toolbelt.*",
111+
"torch.*",
112+
"ultralytics.*",
113+
]
114+
ignore_missing_imports = true

roboflow/__init__.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import time
55
from getpass import getpass
6+
from pathlib import Path
67
from urllib.parse import urlparse
78

89
import requests
@@ -59,20 +60,23 @@ def check_key(api_key, model, notebook, num_retries=0):
5960
return "onboarding"
6061

6162

63+
def auth(api_key):
64+
r = check_key(api_key)
65+
w = r["workspace"]
66+
67+
return Roboflow(api_key, w)
68+
69+
6270
def login(workspace=None, force=False):
6371
os_name = os.name
6472

6573
if os_name == "nt":
66-
default_path = os.path.join(os.getenv("USERPROFILE", ""), "roboflow/config.json")
74+
default_path = str(Path.home() / "roboflow" / "config.json")
6775
else:
68-
default_path = os.path.join(os.getenv("HOME", ""), ".config/roboflow/config.json")
76+
default_path = str(Path.home() / ".config" / "roboflow" / "config.json")
6977

7078
# default configuration location
71-
conf_location = os.getenv(
72-
"ROBOFLOW_CONFIG_DIR",
73-
default=default_path,
74-
)
75-
79+
conf_location = os.getenv("ROBOFLOW_CONFIG_DIR", default=default_path)
7680
if os.path.isfile(conf_location) and not force:
7781
write_line("You are already logged into Roboflow. To make a different login," "run roboflow.login(force=True).")
7882
return None
@@ -275,7 +279,7 @@ def project(self, project_name, the_workspace=None):
275279

276280
dataset_info = dataset_info.json()["project"]
277281

278-
return Project(self.api_key or "", dataset_info)
282+
return Project(self.api_key, dataset_info)
279283

280284
def __str__(self):
281285
"""to string function"""

roboflow/adapters/rfapi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import os
3+
import urllib
34
from typing import Optional
4-
from urllib import parse
55

66
import requests
77
from requests_toolbelt.multipart.encoder import MultipartEncoder
@@ -164,7 +164,7 @@ def _upload_url(api_key, project_url, **kwargs):
164164
url = f"{API_URL}/dataset/{project_url}/upload?api_key={api_key}"
165165

166166
if kwargs:
167-
querystring = parse.urlencode(kwargs, doseq=True)
167+
querystring = urllib.parse.urlencode(kwargs, doseq=True)
168168
url += f"&{querystring}"
169169

170170
return url

roboflow/models/classification.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import io
33
import json
44
import os
5+
import urllib
56
from typing import Optional
6-
from urllib import parse
77

88
import requests
99
from PIL import Image
@@ -63,7 +63,7 @@ def __init__(
6363
print(f"initalizing local classification model hosted at : {local}")
6464
self.base_url = local
6565

66-
def predict(self, image_path, hosted=False):
66+
def predict(self, image_path, hosted=False): # type: ignore[override]
6767
"""
6868
Run inference on an image.
6969
@@ -106,7 +106,7 @@ def predict(self, image_path, hosted=False):
106106
)
107107
else:
108108
# Create API URL for hosted image (slightly different)
109-
self.api_url += "&image=" + parse.quote_plus(image_path)
109+
self.api_url += "&image=" + urllib.parse.quote_plus(image_path)
110110
# POST to the API
111111
resp = requests.post(self.api_url)
112112
img_dims = {"width": "0", "height": "0"}

roboflow/models/inference.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import json
33
import os
44
import time
5+
import urllib
56
from typing import Optional, Tuple
6-
from urllib import parse
77
from urllib.parse import urljoin
88

99
import requests
@@ -72,7 +72,7 @@ def __get_image_params(self, image_path):
7272
"""
7373
validate_image_path(image_path)
7474

75-
hosted_image = parse.urlparse(image_path).scheme in ("http", "https")
75+
hosted_image = urllib.parse.urlparse(image_path).scheme in ("http", "https")
7676

7777
if hosted_image:
7878
image_dims = {"width": "Undefined", "height": "Undefined"}
@@ -121,7 +121,7 @@ def predict(self, image_path, prediction_type=None, **kwargs):
121121
params["api_key"] = self.__api_key
122122

123123
params.update(**kwargs)
124-
url = f"{self.api_url}?{parse.urlencode(params)}" # type: ignore[attr-defined]
124+
url = f"{self.api_url}?{urllib.parse.urlencode(params)}" # type: ignore[attr-defined]
125125
response = requests.post(url, **request_kwargs)
126126
response.raise_for_status()
127127

roboflow/models/instance_segmentation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
self.colors = {} if colors is None else colors
3636
self.preprocessing = {} if preprocessing is None else preprocessing
3737

38-
def predict(self, image_path, confidence=40):
38+
def predict(self, image_path, confidence=40): # type: ignore[override]
3939
"""
4040
Infers detections based on image from a specified model and image path.
4141

roboflow/models/keypoint_detection.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import io
33
import json
44
import os
5+
import urllib
56
from typing import Optional
6-
from urllib import parse
77

88
import requests
99
from PIL import Image
@@ -58,7 +58,7 @@ def __init__(
5858
print(f"initalizing local keypoint detection model hosted at : {local}")
5959
self.base_url = local
6060

61-
def predict(self, image_path, hosted=False):
61+
def predict(self, image_path, hosted=False): # type: ignore[override]
6262
"""
6363
Run inference on an image.
6464
@@ -101,7 +101,7 @@ def predict(self, image_path, hosted=False):
101101
)
102102
else:
103103
# Create API URL for hosted image (slightly different)
104-
self.api_url += "&image=" + parse.quote_plus(image_path)
104+
self.api_url += "&image=" + urllib.parse.quote_plus(image_path)
105105
# POST to the API
106106
resp = requests.post(self.api_url)
107107
img_dims = {"width": "0", "height": "0"}

roboflow/models/object_detection.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import os
66
import random
7-
from urllib import parse
7+
import urllib
88

99
import cv2
1010
import numpy as np
@@ -125,7 +125,7 @@ def load_model(
125125
format=format,
126126
)
127127

128-
def predict(
128+
def predict( # type: ignore[override]
129129
self,
130130
image_path,
131131
hosted=False,
@@ -234,7 +234,7 @@ def predict(
234234
raise ValueError("image_path must be a string or a numpy array.")
235235
else:
236236
# Create API URL for hosted image (slightly different)
237-
self.api_url += "&image=" + parse.quote_plus(image_path)
237+
self.api_url += "&image=" + urllib.parse.quote_plus(image_path)
238238
image_dims = {"width": "0", "height": "0"}
239239
# POST to the API
240240
resp = requests.post(self.api_url)

roboflow/models/semantic_segmentation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, api_key: str, version_id: str):
1818
super().__init__(api_key, version_id)
1919
self.api_url = f"{SEMANTIC_SEGMENTATION_URL}/{self.dataset_id}/{self.version}"
2020

21-
def predict(self, image_path: str, confidence: int = 50):
21+
def predict(self, image_path: str, confidence: int = 50): # type: ignore[override]
2222
"""
2323
Infers detections based on image from a specified model and image path.
2424

roboflow/models/video.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
""" # noqa: E501 // docs
6666
self.__api_key = api_key
6767

68-
def predict(
68+
def predict( # type: ignore[override]
6969
self,
7070
video_path: str,
7171
inference_type: str,

roboflow/util/image_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
import io
33
import os
4-
from urllib import parse
4+
import urllib
55

66
import cv2
77
import numpy as np
@@ -25,7 +25,7 @@ def check_image_url(url):
2525
:param url: URL of image
2626
:returns: Boolean
2727
"""
28-
if parse.urlparse(url).scheme not in ("http", "https"):
28+
if urllib.parse.urlparse(url).scheme not in ("http", "https"):
2929
return False
3030

3131
r = requests.head(url)

roboflow/util/prediction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def create_prediction_group(json_response, image_path, prediction_type, image_di
490490
""" # noqa: E501 // docs
491491

492492
colors = {} if colors is None else colors
493-
prediction_list: list[Prediction] = []
493+
prediction_list = []
494494

495495
if prediction_type in [OBJECT_DETECTION_MODEL, INSTANCE_SEGMENTATION_MODEL]:
496496
for prediction in json_response["predictions"]:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
extras_require={
3232
"desktop": ["opencv-python==4.8.0.74"],
3333
"dev": [
34-
"pyright",
34+
"mypy",
3535
"responses",
3636
"ruff",
3737
"twine",

0 commit comments

Comments
 (0)