Skip to content

Commit 057c101

Browse files
committed
flake
1 parent 0f9db84 commit 057c101

15 files changed

+135
-72
lines changed

datalabeling/create_annotation_spec_set.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
# [START datalabeling_create_annotation_spec_set_beta]
2121
def create_annotation_spec_set(project_id):
22-
"""Creates a data labeling annotation spec set for the given Google Cloud project.
22+
"""Creates a data labeling annotation spec set for the given
23+
Google Cloud project.
2324
"""
2425
from google.cloud import datalabeling_v1beta1 as datalabeling
2526
client = datalabeling.DataLabelingServiceClient()
@@ -58,6 +59,7 @@ def create_annotation_spec_set(project_id):
5859
return response
5960
# [END datalabeling_create_annotation_spec_set_beta]
6061

62+
6163
if __name__ == '__main__':
6264
parser = argparse.ArgumentParser(
6365
description=__doc__,

datalabeling/create_annotation_spec_set_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
# limitations under the License.
1616

1717
import os
18-
import pytest
1918

20-
from google.cloud import datalabeling_v1beta1 as datalabeling
2119
import create_annotation_spec_set
20+
from google.cloud import datalabeling_v1beta1 as datalabeling
21+
import pytest
2222

2323
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
2424

2525

2626
@pytest.mark.slow
2727
def test_create_annotation_spec_set(capsys):
28-
response = create_annotation_spec_set.create_annotation_spec_set(PROJECT_ID)
28+
response = create_annotation_spec_set.create_annotation_spec_set(
29+
PROJECT_ID)
2930
out, _ = capsys.readouterr()
3031
assert 'The annotation_spec_set resource name:' in out
3132

datalabeling/create_instruction.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
# [START datalabeling_create_instruction_beta]
2121
def create_instruction(project_id, data_type, instruction_gcs_uri):
2222
""" Creates a data labeling PDF instruction for the given Google Cloud
23-
project. The PDF file should be uploaded to the project in Google Cloud Storage.
23+
project. The PDF file should be uploaded to the project in
24+
Google Cloud Storage.
2425
"""
2526
from google.cloud import datalabeling_v1beta1 as datalabeling
2627
client = datalabeling.DataLabelingServiceClient()
@@ -58,6 +59,7 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
5859
return result
5960
# [END datalabeling_create_instruction_beta]
6061

62+
6163
if __name__ == '__main__':
6264
parser = argparse.ArgumentParser(
6365
description=__doc__,
@@ -66,7 +68,7 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
6668

6769
parser.add_argument(
6870
'--project-id',
69-
help='Project ID. Required.',
71+
help='Project ID. Required.',
7072
required=True
7173
)
7274

@@ -84,4 +86,8 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
8486

8587
args = parser.parse_args()
8688

87-
create_instruction(args.project_id, args.data_type, args.instruction_gcs_uri)
89+
create_instruction(
90+
args.project_id,
91+
args.data_type,
92+
args.instruction_gcs_uri
93+
)

datalabeling/create_instruction_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
1515
# limitations under the License.
1616

1717
import os
18-
import pytest
1918

2019
import create_instruction
2120
from google.cloud import datalabeling_v1beta1 as datalabeling
21+
import pytest
2222

2323
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
24-
INSTRUCTION_GCS_URI = 'gs://cloud-samples-data/datalabeling/instruction/test.pdf'
24+
INSTRUCTION_GCS_URI = 'gs://cloud-samples-data/datalabeling',\
25+
'/instruction/test.pdf'
2526

2627

2728
@pytest.mark.slow
2829
def test_create_instruction(capsys):
29-
result = create_instruction.create_instruction(PROJECT_ID, 'IMAGE',
30-
INSTRUCTION_GCS_URI)
30+
result = create_instruction.create_instruction(
31+
PROJECT_ID,
32+
'IMAGE',
33+
INSTRUCTION_GCS_URI
34+
)
3135
out, _ = capsys.readouterr()
3236
assert 'The instruction resource name: ' in out
3337

datalabeling/export_data.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# [START datalabeling_export_data_beta]
2121
def export_data(dataset_resource_name, annotated_dataset_resource_name,
22-
export_gcs_uri):
22+
export_gcs_uri):
2323
"""Exports a dataset from the given Google Cloud project."""
2424
from google.cloud import datalabeling_v1beta1 as datalabeling
2525
client = datalabeling.DataLabelingServiceClient()
@@ -30,7 +30,11 @@ def export_data(dataset_resource_name, annotated_dataset_resource_name,
3030
output_config = datalabeling.types.OutputConfig(
3131
gcs_destination=gcs_destination)
3232

33-
response = client.export_data(dataset_resource_name, annotated_dataset_resource_name, output_config)
33+
response = client.export_data(
34+
dataset_resource_name,
35+
annotated_dataset_resource_name,
36+
output_config
37+
)
3438

3539
print('Dataset ID: {}\n'.format(response.result().dataset))
3640
print('Output config:')
@@ -39,6 +43,7 @@ def export_data(dataset_resource_name, annotated_dataset_resource_name,
3943
response.result().output_config.gcs_destination.output_uri))
4044
# [END datalabeling_export_data_beta]
4145

46+
4247
if __name__ == '__main__':
4348
parser = argparse.ArgumentParser(
4449
description=__doc__,
@@ -65,5 +70,8 @@ def export_data(dataset_resource_name, annotated_dataset_resource_name,
6570

6671
args = parser.parse_args()
6772

68-
export_data(args.dataset_resource_name,
69-
args.annotated_dataset_resource_name, args.export_gcs_uri)
73+
export_data(
74+
args.dataset_resource_name,
75+
args.annotated_dataset_resource_name,
76+
args.export_gcs_uri
77+
)

datalabeling/import_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ def import_data(dataset_resource_name, data_type, input_gcs_uri):
3333

3434
result = response.result()
3535

36-
# The format of resource name: project_id/{project_id}/datasets/{dataset_id}
36+
# The format of resource name:
37+
# project_id/{project_id}/datasets/{dataset_id}
3738
print('Dataset resource name: {}\n'.format(result.dataset))
3839

3940
return result
4041
# [END datalabeling_import_data_beta]
4142

43+
4244
if __name__ == '__main__':
4345
parser = argparse.ArgumentParser(
4446
description=__doc__,

datalabeling/import_data_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# limitations under the License.
1616

1717
import os
18-
import pytest
1918

2019
import import_data
2120
import manage_dataset
21+
import pytest
2222

2323
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
2424
INPUT_GCS_URI = 'gs://cloud-samples-data/datalabeling/image/image_dataset.csv'

datalabeling/label_image.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919

2020
# [START datalabeling_label_image_beta]
21-
def label_image(dataset_resource_name, instruction_resource_name, annotation_spec_set_resource_name):
21+
def label_image(dataset_resource_name, instruction_resource_name,
22+
annotation_spec_set_resource_name):
2223
"""Labels an image dataset."""
2324
from google.cloud import datalabeling_v1beta1 as datalabeling
2425
client = datalabeling.DataLabelingServiceClient()
@@ -32,7 +33,7 @@ def label_image(dataset_resource_name, instruction_resource_name, annotation_spe
3233

3334
feature = datalabeling.enums.LabelImageRequest.Feature.CLASSIFICATION
3435

35-
image_classification_config = datalabeling.types.ImageClassificationConfig(
36+
config = datalabeling.types.ImageClassificationConfig(
3637
annotation_spec_set=annotation_spec_set_resource_name,
3738
allow_multi_label=False,
3839
answer_aggregation_type=datalabeling.enums.StringAggregationType
@@ -43,13 +44,14 @@ def label_image(dataset_resource_name, instruction_resource_name, annotation_spe
4344
dataset_resource_name,
4445
basic_config,
4546
feature,
46-
image_classification_config=image_classification_config
47+
image_classification_config=config
4748
)
4849

4950
print('Label_image operation name: {}'.format(response.operation.name))
5051
return response
5152
# [END datalabeling_label_image_beta]
5253

54+
5355
if __name__ == '__main__':
5456
parser = argparse.ArgumentParser(
5557
description=__doc__,
@@ -76,5 +78,8 @@ def label_image(dataset_resource_name, instruction_resource_name, annotation_spe
7678

7779
args = parser.parse_args()
7880

79-
label_image(args.dataset_resource_name, args.instruction_resource_name,
80-
args.annotation_spec_set_resource_name)
81+
label_image(
82+
args.dataset_resource_name,
83+
args.instruction_resource_name,
84+
args.annotation_spec_set_resource_name
85+
)

datalabeling/label_image_test.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
# limitations under the License.
1616

1717
import os
18-
import pytest
1918

20-
from google.cloud import datalabeling_v1beta1 as datalabeling
2119
import create_annotation_spec_set
2220
import create_instruction
21+
from google.cloud import datalabeling_v1beta1 as datalabeling
2322
import import_data
2423
import label_image
2524
import manage_dataset
25+
import pytest
2626

2727
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
28+
INPUT_GCS_URI = 'gs://cloud-samples-data/datalabeling/image/image_dataset.csv'
2829

2930

3031
@pytest.fixture(scope='function')
@@ -33,8 +34,7 @@ def dataset():
3334
dataset = manage_dataset.create_dataset(PROJECT_ID)
3435

3536
# import some data to it
36-
import_data.import_data(dataset.name, 'IMAGE',
37-
'gs://cloud-samples-data/datalabeling/image/image_dataset.csv')
37+
import_data.import_data(dataset.name, 'IMAGE', INPUT_GCS_URI)
3838

3939
yield dataset
4040

@@ -45,13 +45,14 @@ def dataset():
4545
@pytest.fixture(scope='function')
4646
def annotation_spec_set():
4747
# create a temporary annotation_spec_set
48-
annotation_spec_set = create_annotation_spec_set.create_annotation_spec_set(PROJECT_ID)
48+
response = create_annotation_spec_set.create_annotation_spec_set(
49+
PROJECT_ID)
4950

50-
yield annotation_spec_set
51+
yield response
5152

5253
# tear down
5354
client = datalabeling.DataLabelingServiceClient()
54-
client.delete_annotation_spec_set(annotation_spec_set.name)
55+
client.delete_annotation_spec_set(response.name)
5556

5657

5758
@pytest.fixture(scope='function')
@@ -68,20 +69,25 @@ def instruction():
6869
client.delete_instruction(instruction.name)
6970

7071

71-
# Passing in dataset as the last argument in test_label_image since it needs to be deleted before the annotation_spec_set can be deleted.
72+
# Passing in dataset as the last argument in test_label_image since it needs
73+
# to be deleted before the annotation_spec_set can be deleted.
7274
@pytest.mark.slow
7375
def test_label_image(capsys, annotation_spec_set, instruction, dataset):
7476

7577
# Start labeling.
76-
response = label_image.label_image(dataset.name, instruction.name, annotation_spec_set.name)
78+
response = label_image.label_image(
79+
dataset.name,
80+
instruction.name,
81+
annotation_spec_set.name
82+
)
7783
out, _ = capsys.readouterr()
7884
assert 'Label_image operation name: ' in out
7985
operation_name = response.operation.name
8086

8187
# Cancels the labeling operation.
8288
response.cancel()
83-
assert response.cancelled() == True
89+
assert response.cancelled() is True
8490

8591
client = datalabeling.DataLabelingServiceClient()
86-
cancel_response = client.transport._operations_client.cancel_operation(
92+
client.transport._operations_client.cancel_operation(
8793
operation_name)

datalabeling/label_text.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919

2020
# [START datalabeling_label_text_beta]
21-
def label_text(dataset_resource_name, instruction_resource_name, annotation_spec_set_resource_name):
21+
def label_text(dataset_resource_name, instruction_resource_name,
22+
annotation_spec_set_resource_name):
2223
"""Labels a text dataset."""
2324
from google.cloud import datalabeling_v1beta1 as datalabeling
2425
client = datalabeling.DataLabelingServiceClient()
@@ -30,22 +31,24 @@ def label_text(dataset_resource_name, instruction_resource_name, annotation_spec
3031
replica_count=1
3132
)
3233

33-
feature = datalabeling.enums.LabelTextRequest.Feature.TEXT_ENTITY_EXTRACTION
34+
feature = (datalabeling.enums.LabelTextRequest.
35+
Feature.TEXT_ENTITY_EXTRACTION)
3436

35-
text_entity_extraction_config = datalabeling.types.TextEntityExtractionConfig(
37+
config = datalabeling.types.TextEntityExtractionConfig(
3638
annotation_spec_set=annotation_spec_set_resource_name)
3739

3840
response = client.label_text(
3941
dataset_resource_name,
4042
basic_config,
4143
feature,
42-
text_entity_extraction_config=text_entity_extraction_config
44+
text_entity_extraction_config=config
4345
)
4446

4547
print('Label_text operation name: {}'.format(response.operation.name))
4648
return response
4749
# [END datalabeling_label_text_beta]
4850

51+
4952
if __name__ == '__main__':
5053
parser = argparse.ArgumentParser(
5154
description=__doc__,
@@ -72,4 +75,8 @@ def label_text(dataset_resource_name, instruction_resource_name, annotation_spec
7275

7376
args = parser.parse_args()
7477

75-
label_text(args.dataset_resource_name, args.instruction_resource_name, args.annotation_spec_set_resource_name)
78+
label_text(
79+
args.dataset_resource_name,
80+
args.instruction_resource_name,
81+
args.annotation_spec_set_resource_name
82+
)

0 commit comments

Comments
 (0)