Skip to content

Commit 9d8ad39

Browse files
author
Matt Sokoloff
committed
wip
1 parent c3ac3a9 commit 9d8ad39

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
build:
33
docker build -t local/labelbox-python:test .
44

5+
6+
test-local: build
7+
docker run -it -v ${PWD}:/usr/src -w /usr/src \
8+
-e LABELBOX_TEST_ENVIRON="staging" \
9+
-e LABELBOX_TEST_API_KEY_STAGING=${LABELBOX_TEST_API_KEY_LOCAL} \
10+
local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx
11+
12+
513
test-staging: build
614
docker run -it -v ${PWD}:/usr/src -w /usr/src \
715
-e LABELBOX_TEST_ENVIRON="staging" \

labelbox/schema/annotation_import.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,7 @@ def _fetch_remote_ndjson(self, url: str) -> List[Dict[str, Any]]:
124124

125125
@classmethod
126126
def _build_import_predictions_query(cls, file_args: str, vars: str):
127-
cls.validate_cls()
128-
query_str = """mutation createAnnotationImportPyApi($parent_id : ID!, $name: String!, $predictionType : PredictionType!, %s) {
129-
createAnnotationImport(data: {
130-
%s : $parent_id
131-
name: $name
132-
%s
133-
predictionType: $predictionType
134-
}) {
135-
__typename
136-
... on ModelAssistedLabelingPredictionImport {%s}
137-
... on ModelErrorAnalysisPredictionImport {%s}
138-
}}""" % (vars, cls.id_name, file_args,
139-
query.results_query_part(MALPredictionImport),
140-
query.results_query_part(MEAPredictionImport))
141-
return query_str
127+
raise NotImplementedError("")
142128

143129
@classmethod
144130
def validate_cls(cls):
@@ -182,8 +168,7 @@ def _create_from_url(cls, client, parent_id, name, url):
182168
params={
183169
"fileUrl": url,
184170
"parent_id": parent_id,
185-
'name': name,
186-
'predictionType': cls.import_type.value
171+
'name': name
187172
})
188173
return cls(client, response['createAnnotationImport'])
189174

@@ -215,8 +200,7 @@ def _create_from_bytes(cls, client, parent_id, name, bytes_data,
215200
"file": None,
216201
"contentLength": content_len,
217202
"parent_id": parent_id,
218-
"name": name,
219-
"predictionType": cls.import_type.value
203+
"name": name
220204
}
221205
operations = json.dumps({"variables": variables, "query": query_str})
222206
data = {
@@ -226,8 +210,9 @@ def _create_from_bytes(cls, client, parent_id, name, bytes_data,
226210
file_data = (file_name, bytes_data, NDJSON_MIME_TYPE)
227211
files = {file_name: file_data}
228212

229-
response = client.execute(data=data, files=files)
230-
return cls(client, response['createAnnotationImport'])
213+
print(data)
214+
breakpoint()
215+
return client.execute(data=data, files=files)
231216

232217
@classmethod
233218
def _create_from_objects(cls, client, parent_id, name, predictions):
@@ -268,14 +253,26 @@ def get_parent_id(self):
268253

269254
@classmethod
270255
def create_from_file(cls, client, model_run_id, name, path):
271-
return cls._create_from_file(client=client,
256+
breakpoint()
257+
return cls(client, cls._create_from_file(client=client,
272258
parent_id=model_run_id,
273259
name=name,
274-
path=path)
260+
path=path)['createModelErrorAnalysisPredictionImport'])
275261

276262
@classmethod
277263
def create_from_objects(cls, client, model_run_id, name, predictions):
278-
return cls._create_from_objects(client, model_run_id, name, predictions)
264+
return cls(client, cls._create_from_objects(client, model_run_id, name, predictions)['createModelErrorAnalysisPredictionImport'])
265+
266+
@classmethod
267+
def _build_import_predictions_query(cls, file_args: str, vars: str):
268+
query_str = """mutation createAnnotationImportPyApi($parent_id : ID!, $name: String!, %s) {
269+
createModelErrorAnalysisPredictionImport(data: {
270+
%s : $parent_id
271+
name: $name
272+
%s
273+
}) {%s}
274+
}""" % (vars, cls.id_name, file_args,query.results_query_part(cls))
275+
return query_str
279276

280277

281278
class MALPredictionImport(AnnotationImport):
@@ -288,11 +285,26 @@ def get_parent_id(self):
288285

289286
@classmethod
290287
def create_from_file(cls, client, project_id, name, path):
291-
return cls._create_from_file(client=client,
288+
return cls(client, cls._create_from_file(client=client,
292289
parent_id=project_id,
293290
name=name,
294-
path=path)
291+
path=path)['createModelAssistedLabelingPredictionImport'])
295292

296293
@classmethod
297294
def create_from_objects(cls, client, project_id, name, predictions):
298-
return cls._create_from_objects(client, project_id, name, predictions)
295+
return cls(client, cls._create_from_objects(client, project_id, name, predictions)['createModelAssistedLabelingPredictionImport'])
296+
297+
@classmethod
298+
def _build_import_predictions_query(cls, file_args: str, vars: str):
299+
query_str = """mutation createAnnotationImportPyApi($parent_id : ID!, $name: String!, %s) {
300+
createModelAssistedLabelingPredictionImport(data: {
301+
%s : $parent_id
302+
name: $name
303+
%s
304+
}) {%s}
305+
}""" % (vars, cls.id_name, file_args,
306+
query.results_query_part(cls))
307+
return query_str
308+
309+
310+

tests/integration/bulk_import/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def ontology():
105105
@pytest.fixture
106106
def configured_project(client, ontology, rand_gen):
107107
project = client.create_project(name=rand_gen(str))
108-
dataset = client.create_dataset(name=rand_gen(str), projects=project)
108+
dataset = client.create_dataset(name=rand_gen(str))
109109
editor = list(
110110
client.get_labeling_frontends(
111111
where=LabelingFrontend.name == "editor"))[0]

tests/integration/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131

3232
class Environ(Enum):
33+
LOCAL = 'local'
3334
PROD = 'prod'
3435
STAGING = 'staging'
3536

@@ -52,13 +53,17 @@ def environ() -> Environ:
5253
def graphql_url(environ: str) -> str:
5354
if environ == Environ.PROD:
5455
return 'https://api.labelbox.com/graphql'
56+
elif environ == Environ.STAGING:
57+
return 'http://host.docker.internal:8080/graphql'
5558
return 'https://staging-api.labelbox.com/graphql'
5659

5760

5861
def testing_api_key(environ: str) -> str:
5962
if environ == Environ.PROD:
6063
return os.environ["LABELBOX_TEST_API_KEY_PROD"]
61-
return os.environ["LABELBOX_TEST_API_KEY_STAGING"]
64+
elif environ == Environ.STAGING:
65+
return os.environ["LABELBOX_TEST_API_KEY_STAGING"]
66+
return os.environ["LABELBOX_TEST_API_KEY_LOCAL"]
6267

6368

6469
def cancel_invite(client, invite_id):

0 commit comments

Comments
 (0)