Skip to content

Commit

Permalink
feat(client): Add missing vfolder mkdir options (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregataa committed Jun 3, 2022
1 parent adf579c commit b376fa6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/431.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing options (`parents`, `exist_ok`) for the `mkdir` CLI command and functional API in the client SDK
8 changes: 6 additions & 2 deletions src/ai/backend/client/cli/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ def cp(filenames):
@vfolder.command()
@click.argument('name', type=str)
@click.argument('path', type=str)
def mkdir(name, path):
@click.option('-p', '--parents', default=False, is_flag=True,
help='Make missing parents of this path as needed')
@click.option('-e', '--exist-ok', default=False, is_flag=True,
help='Skip an error caused by file not found')
def mkdir(name, path, parents, exist_ok):
'''Create an empty directory in the virtual folder.
\b
Expand All @@ -297,7 +301,7 @@ def mkdir(name, path):
'''
with Session() as session:
try:
session.VFolder(name).mkdir(path)
session.VFolder(name).mkdir(path, parents=parents, exist_ok=exist_ok)
print_done('Done.')
except Exception as e:
print_error(e)
Expand Down
9 changes: 8 additions & 1 deletion src/ai/backend/client/func/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,18 @@ async def upload(
return await uploader.upload()

@api_function
async def mkdir(self, path: Union[str, Path]):
async def mkdir(
self,
path: Union[str, Path],
parents: Optional[bool] = False,
exist_ok: Optional[bool] = False,
):
rqst = Request('POST',
'/folders/{}/mkdir'.format(self.name))
rqst.set_json({
'path': path,
'parents': parents,
'exist_ok': exist_ok,
})
async with rqst.fetch() as resp:
return await resp.text()
Expand Down

0 comments on commit b376fa6

Please sign in to comment.