Skip to content

Commit 4c53c9c

Browse files
authored
Merge pull request #388 from Labelbox/ms/html-instructions
add back html instructions
2 parents be2bce6 + ef4bdc8 commit 4c53c9c

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Fix
44
* Make `TypedArray` class compatible with `numpy` versions `>= 1.22.0`
55
* `project.upsert_review_queue` quotas can now be in the inclusive range [0,1]
6+
* Restore support for upserting html instructions to a project
67

78
# Version 3.11.0 (2021-12-15)
89

labelbox/schema/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ def upsert_instructions(self, instructions_file: str):
317317
318318
Args:
319319
instructions_file (str): Path to a local file.
320-
* Must be a pdf file
320+
* Must be a pdf or html file
321321
322322
Raises:
323323
ValueError:
324324
* project must be setup
325-
* instructions file must have a ".pdf" extension
325+
* instructions file must have a ".pdf" or ".html" extension
326326
"""
327327

328328
if self.setup_complete is None:
@@ -338,10 +338,11 @@ def upsert_instructions(self, instructions_file: str):
338338
f"This function has only been tested to work with the Editor front end. Found %s",
339339
frontend.name)
340340

341-
supported_instruction_formats = (".pdf")
341+
supported_instruction_formats = (".pdf", ".html")
342342
if not instructions_file.endswith(supported_instruction_formats):
343343
raise ValueError(
344-
f"instructions_file must be a pdf. Found {instructions_file}")
344+
f"instructions_file must be a pdf or html file. Found {instructions_file}"
345+
)
345346

346347
lfo = list(self.labeling_frontend_options())[-1]
347348
instructions_url = self.client.upload_file(instructions_file)

tests/integration/test_project.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
import pytest
4+
import requests
45

56
from labelbox import Project, LabelingFrontend
67
from labelbox.exceptions import InvalidQueryError
@@ -97,7 +98,22 @@ def test_attach_instructions(client, project):
9798

9899
with pytest.raises(ValueError) as exc_info:
99100
project.upsert_instructions('/tmp/file.invalid_file_extension')
100-
assert "instructions_file must be a pdf. Found" in str(exc_info.value)
101+
assert "instructions_file must be a pdf or html file. Found" in str(
102+
exc_info.value)
103+
104+
105+
def test_html_instructions(configured_project):
106+
html_file_path = '/tmp/instructions.html'
107+
sample_html_str = "<html></html>"
108+
109+
with open(html_file_path, 'w') as file:
110+
file.write(sample_html_str)
111+
112+
configured_project.upsert_instructions(html_file_path)
113+
updated_ontology = configured_project.ontology().normalized
114+
115+
instructions = updated_ontology.pop('projectInstructions')
116+
assert requests.get(instructions).text == sample_html_str
101117

102118

103119
def test_same_ontology_after_instructions(

0 commit comments

Comments
 (0)