Skip to content

Commit 36d1315

Browse files
authored
Fix development issues and poetry install (specifically related to arm64/Apply Silicon) - Drop Python 3.6 support" (#392)
* Drop Python 3.6 * Installing fine :feelsgood: * Bump minor, CHANGELOG and adapt circleci * 👃 BLACK 👃 * Merge master * Try pinning importlib-metadata * Change flake8 command * Remove flake8 - use ruff * 💣 👃 pipx run no_implicit_optional nucleus 👃 💣 * ✨ 👃 BLACK 👃 ✨ * Use ruff in pre-commit * mypy 🤦‍♂️ --------- Co-authored-by: Gunnar Atli Thoroddsen <Error: gh: Not Found (HTTP 404)gh: This API operation needs the user scope. To request it, run: gh auth refresh -h github.com -s user>
1 parent 5d6c221 commit 36d1315

18 files changed

+2937
-1895
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
docker:
1111
# Important: Don't change this otherwise we will stop testing the earliest
1212
# python version we have to support.
13-
- image: python:3.6-buster
13+
- image: python:3.7-buster
1414
resource_class: medium
1515
parallelism: 6
1616
steps:
@@ -37,11 +37,11 @@ jobs:
3737
- run:
3838
name: Black Formatting Check # Only validation, without re-formatting
3939
command: |
40-
poetry run black --check -t py36 .
40+
poetry run black --check .
4141
- run:
42-
name: Flake8 Lint Check # Uses setup.cfg for configuration
42+
name: Ruff Lint Check # See pyproject.tooml [tool.ruff]
4343
command: |
44-
poetry run flake8 . --count --statistics
44+
poetry run ruff .
4545
- run:
4646
name: Pylint Lint Check # Uses .pylintrc for configuration
4747
command: |
@@ -155,7 +155,7 @@ workflows:
155155
- test_client_installation:
156156
matrix:
157157
parameters:
158-
python_version: ['3.6', '3.7', '3.8', '3.9', '3.10']
158+
python_version: ['3.7', '3.8', '3.9', '3.10', '3.11']
159159
context: Nucleus
160160
build_test_publish:
161161
jobs:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
hooks:
1313
- id: system
1414
name: flake8
15-
entry: poetry run flake8 nucleus tests
15+
entry: poetry run ruff nucleus
1616
pass_filenames: false
1717
language: system
1818

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
disable=
33
bad-continuation,
44
no-else-return,
5+
no-name-in-module,
56
too-few-public-methods,
67
line-too-long,
78
duplicate-code,

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
9+
## [0.16.0](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.16.0) - 2023-09-18
10+
11+
### Removed
12+
- Support for Python 3.6 - it is end of life for more than a year
13+
14+
### Fixed
15+
- Development environment for Python 3.11
16+
-
17+
818
## [0.15.11](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.15.11) - 2023-09-15
919

1020
### Added

nucleus/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def __init__(
170170
self,
171171
api_key: Optional[str] = None,
172172
use_notebook: bool = False,
173-
endpoint: str = None,
173+
endpoint: Optional[str] = None,
174174
):
175175
self.api_key = self._set_api_key(api_key)
176176
self.tqdm_bar = tqdm.tqdm
@@ -343,7 +343,9 @@ def get_job(self, job_id: str) -> AsyncJob:
343343
return AsyncJob.from_json(payload=payload, client=self)
344344

345345
def get_model(
346-
self, model_id: str = None, model_run_id: str = None
346+
self,
347+
model_id: Optional[str] = None,
348+
model_run_id: Optional[str] = None,
347349
) -> Model:
348350
"""Fetches a model by its ID.
349351
@@ -388,7 +390,10 @@ def delete_model_run(self, model_run_id: str):
388390
)
389391

390392
def create_dataset_from_project(
391-
self, project_id: str, last_n_tasks: int = None, name: str = None
393+
self,
394+
project_id: str,
395+
last_n_tasks: Optional[int] = None,
396+
name: Optional[str] = None,
392397
) -> Dataset:
393398
"""Create a new dataset from an existing Scale or Rapid project.
394399
@@ -922,7 +927,10 @@ def delete_slice(self, slice_id: str) -> dict:
922927

923928
@deprecated("Prefer calling Dataset.delete_annotations instead.")
924929
def delete_annotations(
925-
self, dataset_id: str, reference_ids: list = None, keep_history=True
930+
self,
931+
dataset_id: str,
932+
reference_ids: Optional[list] = None,
933+
keep_history=True,
926934
) -> AsyncJob:
927935
dataset = self.get_dataset(dataset_id)
928936
return dataset.delete_annotations(reference_ids, keep_history)

nucleus/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
from typing import Optional
23

34
import requests
45

@@ -11,7 +12,7 @@
1112
class Connection:
1213
"""Wrapper of HTTP requests to the Nucleus endpoint."""
1314

14-
def __init__(self, api_key: str, endpoint: str = None):
15+
def __init__(self, api_key: str, endpoint: Optional[str] = None):
1516
self.api_key = api_key
1617
self.endpoint = endpoint
1718

nucleus/dataset.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,9 @@ def create_image_index(self):
12301230
return AsyncJob.from_json(response, self._client)
12311231

12321232
def create_object_index(
1233-
self, model_run_id: str = None, gt_only: bool = None
1233+
self,
1234+
model_run_id: Optional[str] = None,
1235+
gt_only: Optional[bool] = None,
12341236
):
12351237
"""Creates or updates object index by generating embeddings for objects that do not already have embeddings.
12361238
@@ -1439,7 +1441,7 @@ def export_embeddings(
14391441
return api_payload # type: ignore
14401442

14411443
def delete_annotations(
1442-
self, reference_ids: list = None, keep_history: bool = True
1444+
self, reference_ids: Optional[list] = None, keep_history: bool = True
14431445
) -> AsyncJob:
14441446
"""Deletes all annotations associated with the specified item reference IDs.
14451447
@@ -1555,7 +1557,9 @@ def export_scale_task_info(self):
15551557
)
15561558
return format_scale_task_info_response(response)
15571559

1558-
def calculate_evaluation_metrics(self, model, options: dict = None):
1560+
def calculate_evaluation_metrics(
1561+
self, model, options: Optional[dict] = None
1562+
):
15591563
"""Starts computation of evaluation metrics for a model on the dataset.
15601564
15611565
To update matches and metrics calculated for a model on a given dataset you

nucleus/dataset_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
import os.path
2+
import os
33
from collections import Counter
44
from dataclasses import dataclass
55
from enum import Enum

nucleus/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
logger = logging.getLogger(__name__)
66
logging.basicConfig()
77
logging.getLogger(
8-
requests.packages.urllib3.__package__ # pylint: disable=no-member
8+
requests.packages.urllib3.__package__ # type: ignore # pylint: disable=no-member
99
).setLevel(logging.ERROR)

nucleus/metrics/cuboid_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import wraps
2-
from typing import Dict, List, Tuple
2+
from typing import Dict, List, Optional, Tuple
33

44
import numpy as np
55

@@ -176,8 +176,8 @@ def get_batch_cuboid_corners(
176176
xyz: "np.ndarray",
177177
wlh: "np.ndarray",
178178
yaw: "np.ndarray",
179-
pitch: "np.ndarray" = None,
180-
roll: "np.ndarray" = None,
179+
pitch: Optional["np.ndarray"] = None,
180+
roll: Optional["np.ndarray"] = None,
181181
scale_convention: bool = True,
182182
) -> "np.ndarray":
183183
"""
@@ -211,7 +211,9 @@ def get_batch_cuboid_corners(
211211

212212

213213
def get_batch_rotation_matrices(
214-
yaw: "np.ndarray", pitch: "np.ndarray" = None, roll: "np.ndarray" = None
214+
yaw: "np.ndarray",
215+
pitch: Optional["np.ndarray"] = None,
216+
roll: Optional["np.ndarray"] = None,
215217
) -> "np.ndarray":
216218
if pitch is None:
217219
pitch = np.zeros_like(yaw)

nucleus/metrics/segmentation_loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class InMemoryLoader(SegmentationMaskLoader):
2525

2626
def __init__(self, url_to_array: Dict[str, "np.ndarray"]):
2727
self.url_to_array = url_to_array
28+
super().__init__()
2829

2930
def fetch(self, url: str):
3031
array = self.url_to_array[url]

nucleus/metrics/segmentation_to_poly_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def call_metric(
115115
if prediction:
116116
if self.mode == SegToPolyMode.GENERATE_GT_FROM_POLY:
117117
pred_img = self.loader.fetch(prediction.mask_url)
118-
ann_img, segments = rasterize_polygons_to_segmentation_mask(
118+
ann_img, segments = rasterize_polygons_to_segmentation_mask( # type: ignore
119119
annotations.polygon_annotations
120120
+ annotations.box_annotations, # type:ignore
121121
pred_img.shape,

nucleus/metrics/segmentation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def fast_confusion_matrix(
103103
mask = (label_true >= 0) & (label_true < n_class)
104104
hist = np.bincount(
105105
n_class * label_true[mask].astype(int) + label_pred[mask],
106-
minlength=n_class ** 2,
106+
minlength=n_class**2,
107107
).reshape(n_class, n_class)
108108
return hist
109109

nucleus/scene.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,10 @@ def validate(self):
596596
), "No list of items is accepted when uploading a video_location unless you are using privacy mode"
597597

598598
def add_item(
599-
self, item: DatasetItem, index: int = None, update: bool = False
599+
self,
600+
item: DatasetItem,
601+
index: Optional[int] = None,
602+
update: bool = False,
600603
) -> None:
601604
"""Adds DatasetItem to the specified index for videos uploaded as an array of images.
602605

nucleus/slice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def info(self) -> dict:
336336

337337
def append(
338338
self,
339-
reference_ids: List[str] = None,
339+
reference_ids: Optional[List[str]] = None,
340340
) -> dict:
341341
"""Appends existing DatasetItems from a Dataset to a Slice.
342342

nucleus/test_launch_integration.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def _run_model(
144144
def visualize_box_launch_bundle(
145145
img_file: str,
146146
load_predict_fn: Callable,
147-
load_model_fn: Callable = None,
148-
model: Any = None,
147+
load_model_fn: Optional[Callable] = None,
148+
model: Optional[Any] = None,
149149
show_image: bool = False,
150150
max_annotations: int = 5,
151151
) -> Image:
@@ -194,8 +194,8 @@ def visualize_box_launch_bundle(
194194
def run_category_launch_bundle(
195195
img_file: str,
196196
load_predict_fn: Callable,
197-
load_model_fn: Callable = None,
198-
model: Any = None,
197+
load_model_fn: Optional[Callable] = None,
198+
model: Optional[Any] = None,
199199
):
200200
"""
201201
Run this function locally to test if your image categorization model returns a format consumable by Launch + Nucleus
@@ -218,8 +218,8 @@ def run_category_launch_bundle(
218218
def visualize_line_launch_bundle(
219219
img_file: str,
220220
load_predict_fn: Callable,
221-
load_model_fn: Callable = None,
222-
model: Any = None,
221+
load_model_fn: Optional[Callable] = None,
222+
model: Optional[Any] = None,
223223
show_image: bool = False,
224224
max_annotations: int = 5,
225225
) -> Image:
@@ -266,8 +266,8 @@ def visualize_line_launch_bundle(
266266
def visualize_polygon_launch_bundle(
267267
img_file: str,
268268
load_predict_fn: Callable,
269-
load_model_fn: Callable = None,
270-
model: Any = None,
269+
load_model_fn: Optional[Callable] = None,
270+
model: Optional[Any] = None,
271271
show_image: bool = False,
272272
max_annotations: int = 5,
273273
) -> Image:

0 commit comments

Comments
 (0)