Unverified Commit 6affd9cd authored by NielsRogge's avatar NielsRogge Committed by GitHub
Browse files

[PushToHub] Make it possible to upload folders (#23920)

Add first draft
parent 4aa13224
...@@ -701,9 +701,31 @@ class PushToHubMixin: ...@@ -701,9 +701,31 @@ class PushToHubMixin:
for f in os.listdir(working_dir) for f in os.listdir(working_dir)
if f not in files_timestamps or os.path.getmtime(os.path.join(working_dir, f)) > files_timestamps[f] if f not in files_timestamps or os.path.getmtime(os.path.join(working_dir, f)) > files_timestamps[f]
] ]
# filter for actual files + folders at the root level
modified_files = [
f
for f in modified_files
if os.path.isfile(os.path.join(working_dir, f)) or os.path.isdir(os.path.join(working_dir, f))
]
operations = [] operations = []
# upload standalone files
for file in modified_files: for file in modified_files:
operations.append(CommitOperationAdd(path_or_fileobj=os.path.join(working_dir, file), path_in_repo=file)) operations.append(CommitOperationAdd(path_or_fileobj=os.path.join(working_dir, file), path_in_repo=file))
if os.path.isdir(os.path.join(working_dir, file)):
# go over individual files of folder
for f in os.listdir(os.path.join(working_dir, file)):
operations.append(
CommitOperationAdd(
path_or_fileobj=os.path.join(working_dir, file, f), path_in_repo=os.path.join(file, f)
)
)
else:
operations.append(
CommitOperationAdd(path_or_fileobj=os.path.join(working_dir, file), path_in_repo=file)
)
logger.info(f"Uploading the following files to {repo_id}: {','.join(modified_files)}") logger.info(f"Uploading the following files to {repo_id}: {','.join(modified_files)}")
return create_commit( return create_commit(
repo_id=repo_id, operations=operations, commit_message=commit_message, token=token, create_pr=create_pr repo_id=repo_id, operations=operations, commit_message=commit_message, token=token, create_pr=create_pr
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment