Skip to content

Commit e2cfc7a

Browse files
authored
Add isort to autoformat and enforce import order and format (#160)
* isort then black * Add isort endl * Update comment * nit * empty * empty
1 parent a9652e7 commit e2cfc7a

34 files changed

+225
-211
lines changed

.circleci/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
name: MyPy typing check
3636
command: |
3737
poetry run mypy --ignore-missing-imports nucleus
38+
- run :
39+
name: Isort Import Formatting Check # Only validation, without re-formatting
40+
command: |
41+
poetry run isort --check-only .
3842
- run:
3943
name: Pytest Test Cases
4044
command: | # Run test suite, uses NUCLEUS_TEST_API_KEY env variable

.isort.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[settings]
2+
profile=black
3+
# Enforced in .flake8
4+
line_length=79

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ repos:
3232
pass_filenames: false
3333
language: system
3434

35-
35+
- repo: local
36+
hooks:
37+
- id: system
38+
name: isort
39+
entry: poetry run isort .
40+
pass_filenames: false
41+
language: system

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
import nucleus
6-
from tests.helpers import TEST_DATASET_NAME, TEST_DATASET_ITEMS
6+
from tests.helpers import TEST_DATASET_ITEMS, TEST_DATASET_NAME
77

88
assert "NUCLEUS_PYTEST_API_KEY" in os.environ, (
99
"You must set the 'NUCLEUS_PYTEST_API_KEY' environment variable to a valid "

nucleus/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
import os
3838
import time
39-
from typing import Dict, List, Optional, Union, Sequence
39+
from typing import Dict, List, Optional, Sequence, Union
4040

4141
import pkg_resources
4242
import pydantic
@@ -45,14 +45,15 @@
4545
import tqdm.notebook as tqdm_notebook
4646

4747
from nucleus.url_utils import sanitize_string_args
48+
4849
from .annotation import (
4950
BoxAnnotation,
51+
CategoryAnnotation,
5052
CuboidAnnotation,
53+
MultiCategoryAnnotation,
5154
Point,
5255
Point3D,
5356
PolygonAnnotation,
54-
CategoryAnnotation,
55-
MultiCategoryAnnotation,
5657
Segment,
5758
SegmentationAnnotation,
5859
)
@@ -114,10 +115,10 @@
114115
)
115116
from .prediction import (
116117
BoxPrediction,
118+
CategoryPrediction,
117119
CuboidPrediction,
118120
PolygonPrediction,
119121
SegmentationPrediction,
120-
CategoryPrediction,
121122
)
122123
from .retry_strategy import RetryStrategy
123124
from .scene import Frame, LidarScene

nucleus/annotation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
ANNOTATIONS_KEY,
1010
BOX_TYPE,
1111
CATEGORY_TYPE,
12-
MULTICATEGORY_TYPE,
1312
CUBOID_TYPE,
1413
DIMENSIONS_KEY,
1514
GEOMETRY_KEY,
@@ -20,6 +19,7 @@
2019
MASK_TYPE,
2120
MASK_URL_KEY,
2221
METADATA_KEY,
22+
MULTICATEGORY_TYPE,
2323
POLYGON_TYPE,
2424
POSITION_KEY,
2525
REFERENCE_ID_KEY,
@@ -28,8 +28,8 @@
2828
VERTICES_KEY,
2929
WIDTH_KEY,
3030
X_KEY,
31-
YAW_KEY,
3231
Y_KEY,
32+
YAW_KEY,
3333
Z_KEY,
3434
)
3535

nucleus/autocurate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
import datetime
8+
89
import requests
10+
911
from nucleus.constants import (
1012
JOB_CREATION_TIME_KEY,
1113
JOB_LAST_KNOWN_STATUS_KEY,

nucleus/data_transfer_object/dataset_info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from typing import List, Optional, Dict, Any
2-
1+
from typing import Any, Dict, List, Optional
32

43
from nucleus.data_transfer_object.dict_compatible_model import (
54
DictCompatibleModel,

nucleus/dataset.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from nucleus.job import AsyncJob
77
from nucleus.prediction import (
88
BoxPrediction,
9+
CategoryPrediction,
910
CuboidPrediction,
1011
PolygonPrediction,
1112
SegmentationPrediction,
12-
CategoryPrediction,
1313
from_json,
1414
)
1515
from nucleus.url_utils import sanitize_string_args
@@ -19,26 +19,27 @@
1919
format_prediction_response,
2020
serialize_and_write_to_presigned_url,
2121
)
22+
2223
from .annotation import (
2324
Annotation,
24-
check_all_mask_paths_remote,
2525
BoxAnnotation,
26-
PolygonAnnotation,
27-
CuboidAnnotation,
2826
CategoryAnnotation,
27+
CuboidAnnotation,
2928
MultiCategoryAnnotation,
29+
PolygonAnnotation,
3030
SegmentationAnnotation,
31+
check_all_mask_paths_remote,
3132
)
3233
from .constants import (
3334
ANNOTATIONS_KEY,
3435
AUTOTAG_SCORE_THRESHOLD,
3536
DEFAULT_ANNOTATION_UPDATE_MODE,
3637
EXPORTED_ROWS,
38+
KEEP_HISTORY_KEY,
3739
NAME_KEY,
3840
REFERENCE_IDS_KEY,
3941
REQUEST_ID_KEY,
4042
UPDATE_KEY,
41-
KEEP_HISTORY_KEY,
4243
)
4344
from .data_transfer_object.dataset_info import DatasetInfo
4445
from .data_transfer_object.dataset_size import DatasetSize

nucleus/dataset_item.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
from collections import Counter
21
import json
32
import os.path
3+
from collections import Counter
44
from dataclasses import dataclass
5-
from typing import Optional, Sequence, Dict, Any
65
from enum import Enum
6+
from typing import Any, Dict, Optional, Sequence
77

8-
from .annotation import is_local_path, Point3D
8+
from .annotation import Point3D, is_local_path
99
from .constants import (
10+
CAMERA_PARAMS_KEY,
11+
CX_KEY,
12+
CY_KEY,
13+
FX_KEY,
14+
FY_KEY,
15+
HEADING_KEY,
1016
IMAGE_URL_KEY,
1117
METADATA_KEY,
1218
ORIGINAL_IMAGE_URL_KEY,
13-
UPLOAD_TO_SCALE_KEY,
19+
POINTCLOUD_URL_KEY,
20+
POSITION_KEY,
1421
REFERENCE_ID_KEY,
1522
TYPE_KEY,
23+
UPLOAD_TO_SCALE_KEY,
1624
URL_KEY,
17-
CAMERA_PARAMS_KEY,
18-
POINTCLOUD_URL_KEY,
25+
W_KEY,
1926
X_KEY,
2027
Y_KEY,
2128
Z_KEY,
22-
W_KEY,
23-
POSITION_KEY,
24-
HEADING_KEY,
25-
FX_KEY,
26-
FY_KEY,
27-
CX_KEY,
28-
CY_KEY,
2929
)
3030

3131

nucleus/dataset_item_uploader.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
import json
33
import os
44
import time
5-
from typing import List, Any, TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Any, List
66

77
import aiohttp
88
import nest_asyncio
99

1010
from .constants import (
1111
DATASET_ID_KEY,
12-
UPDATE_KEY,
13-
ITEMS_KEY,
14-
IMAGE_URL_KEY,
15-
IMAGE_KEY,
1612
DEFAULT_NETWORK_TIMEOUT_SEC,
13+
IMAGE_KEY,
14+
IMAGE_URL_KEY,
15+
ITEMS_KEY,
16+
UPDATE_KEY,
1717
)
18-
from .payload_constructor import construct_append_payload
19-
from .retry_strategy import RetryStrategy
2018
from .dataset_item import DatasetItem
21-
from .upload_response import UploadResponse
2219
from .errors import NotFoundError
2320
from .logger import logger
21+
from .payload_constructor import construct_append_payload
22+
from .retry_strategy import RetryStrategy
23+
from .upload_response import UploadResponse
2424

2525
if TYPE_CHECKING:
2626
from . import NucleusClient

nucleus/job.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from dataclasses import dataclass
21
import time
2+
from dataclasses import dataclass
33
from typing import Dict, List
4+
45
import requests
6+
57
from nucleus.constants import (
68
JOB_CREATION_TIME_KEY,
79
JOB_ID_KEY,

nucleus/model.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from typing import List, Optional, Dict, Union
1+
from typing import Dict, List, Optional, Union
2+
3+
from .constants import METADATA_KEY, NAME_KEY, REFERENCE_ID_KEY
24
from .dataset import Dataset
5+
from .model_run import ModelRun
36
from .prediction import (
47
BoxPrediction,
58
CuboidPrediction,
69
PolygonPrediction,
710
SegmentationPrediction,
811
)
9-
from .model_run import ModelRun
10-
from .constants import (
11-
NAME_KEY,
12-
REFERENCE_ID_KEY,
13-
METADATA_KEY,
14-
)
1512

1613

1714
class Model:

nucleus/payload_constructor.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
from typing import List, Optional, Dict, Union
2-
from .dataset_item import DatasetItem
3-
from .scene import LidarScene
1+
from typing import Dict, List, Optional, Union
2+
43
from .annotation import (
54
BoxAnnotation,
6-
CuboidAnnotation,
7-
PolygonAnnotation,
85
CategoryAnnotation,
6+
CuboidAnnotation,
97
MultiCategoryAnnotation,
8+
PolygonAnnotation,
109
SegmentationAnnotation,
1110
)
12-
from .prediction import (
13-
BoxPrediction,
14-
CuboidPrediction,
15-
PolygonPrediction,
16-
SegmentationPrediction,
17-
CategoryPrediction,
18-
)
1911
from .constants import (
12+
ANNOTATION_METADATA_SCHEMA_KEY,
2013
ANNOTATION_UPDATE_KEY,
21-
NAME_KEY,
22-
METADATA_KEY,
23-
REFERENCE_ID_KEY,
2414
ANNOTATIONS_KEY,
2515
ITEMS_KEY,
26-
SCENES_KEY,
27-
UPDATE_KEY,
16+
LABELS_KEY,
17+
METADATA_KEY,
2818
MODEL_ID_KEY,
29-
ANNOTATION_METADATA_SCHEMA_KEY,
19+
NAME_KEY,
20+
REFERENCE_ID_KEY,
21+
SCENES_KEY,
3022
SEGMENTATIONS_KEY,
3123
TAXONOMY_NAME_KEY,
3224
TYPE_KEY,
33-
LABELS_KEY,
25+
UPDATE_KEY,
3426
)
27+
from .dataset_item import DatasetItem
28+
from .prediction import (
29+
BoxPrediction,
30+
CategoryPrediction,
31+
CuboidPrediction,
32+
PolygonPrediction,
33+
SegmentationPrediction,
34+
)
35+
from .scene import LidarScene
3536

3637

3738
def construct_append_payload(

nucleus/prediction.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,41 @@
33
as annotation types, but come with additional, optional data that can be attached
44
such as confidence or probability distributions.
55
"""
6-
from typing import Dict, Optional, List
6+
from typing import Dict, List, Optional
7+
78
from .annotation import (
89
BoxAnnotation,
910
CategoryAnnotation,
11+
CuboidAnnotation,
1012
Point,
13+
Point3D,
1114
PolygonAnnotation,
1215
Segment,
1316
SegmentationAnnotation,
14-
CuboidAnnotation,
15-
Point3D,
1617
)
1718
from .constants import (
1819
ANNOTATION_ID_KEY,
20+
ANNOTATIONS_KEY,
1921
BOX_TYPE,
20-
CUBOID_TYPE,
21-
POLYGON_TYPE,
2222
CATEGORY_TYPE,
23-
REFERENCE_ID_KEY,
24-
METADATA_KEY,
23+
CLASS_PDF_KEY,
24+
CONFIDENCE_KEY,
25+
CUBOID_TYPE,
26+
DIMENSIONS_KEY,
2527
GEOMETRY_KEY,
28+
HEIGHT_KEY,
2629
LABEL_KEY,
30+
MASK_URL_KEY,
31+
METADATA_KEY,
32+
POLYGON_TYPE,
33+
POSITION_KEY,
34+
REFERENCE_ID_KEY,
2735
TAXONOMY_NAME_KEY,
2836
TYPE_KEY,
37+
VERTICES_KEY,
38+
WIDTH_KEY,
2939
X_KEY,
3040
Y_KEY,
31-
WIDTH_KEY,
32-
HEIGHT_KEY,
33-
CLASS_PDF_KEY,
34-
CONFIDENCE_KEY,
35-
VERTICES_KEY,
36-
ANNOTATIONS_KEY,
37-
MASK_URL_KEY,
38-
POSITION_KEY,
39-
DIMENSIONS_KEY,
4041
YAW_KEY,
4142
)
4243

0 commit comments

Comments
 (0)