Skip to content

Commit 80bb5fa

Browse files
authored
Merge pull request #126 from facultyai/add-projectid-param-to-datasets-open
Add `project_id` parameter to datasets.open function
2 parents f8f050a + ba9423d commit 80bb5fa

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

faculty/datasets/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def etag(project_path, project_id=None, object_client=None):
483483

484484

485485
@contextlib.contextmanager
486-
def open(project_path, mode="r", temp_dir=None, **kwargs):
486+
def open(project_path, mode="r", temp_dir=None, project_id=None, **kwargs):
487487
"""Open a file from a project's datasets for reading.
488488
489489
This downloads the file into a temporary directory before opening it, so if
@@ -501,9 +501,13 @@ def open(project_path, mode="r", temp_dir=None, **kwargs):
501501
saved into temporarily. Note that on SherlockML servers, the default
502502
temporary directory can break with large files, so if your file is
503503
upwards of 2GB, it is recommended to specify temp_dir='/project'.
504+
project_id : str, optional
505+
The project to get files from. You need to have access to this project
506+
for it to work. Defaults to the project set by FACULTY_PROJECT_ID in
507+
your environment.
504508
"""
505509

506-
if _isdir(project_path):
510+
if _isdir(project_path, project_id=project_id):
507511
raise DatasetsError("Can't open directories.")
508512

509513
if any(char in mode for char in ("w", "a", "x")):
@@ -513,7 +517,7 @@ def open(project_path, mode="r", temp_dir=None, **kwargs):
513517
local_path = os.path.join(tmpdir, os.path.basename(project_path))
514518

515519
try:
516-
get(project_path, local_path)
520+
get(project_path, local_path, project_id=project_id)
517521
with io.open(local_path, mode, **kwargs) as file_object:
518522
yield file_object
519523
finally:

0 commit comments

Comments
 (0)