in utils/hub_sync.py [0:0]
def main():
args = get_args()
if not (os.path.isdir(args.repo_path) and os.path.isdir(f"{args.repo_path}/.git")):
raise FileNotFoundError(f"Directory '{args.repo_path}' either doesn't exist or it's not a git clone directory. "
"Clone the desired repo first to '{args.repo_path}'.")
if len(args.patterns) == 0:
raise ValueError("At least one --pattern is required.")
print(f"* Processing {args.repo_path}")
if args.debug:
print(f"Tracking {len(args.patterns)} patterns:")
print(''.join(f"- {x}\n" for x in args.patterns))
hub_data = get_hub_data()
repo = Repository(args.repo_path)
hub_config_repo(hub_data, local_dir=args.repo_path)
files_dict = get_git_files_by_status(args.repo_path)
# we want untracked and modified files
uncommitted_files = get_new_and_modified_files(args.repo_path)
total_to_commit = 0
if len(uncommitted_files) > 0:
print(f"* Found {len(uncommitted_files)} uncommitted files:")
if args.debug:
print(''.join(f"- {f}\n" for f in uncommitted_files))
for pattern in args.patterns:
# *** new and modified files ***
# check that these are the files that match the pattern passed to git_add
uncommitted_files_matched = [f for f in uncommitted_files if fnmatch(f, pattern)]
print(f"* Found {len(uncommitted_files_matched)} uncommitted files matching pattern: {pattern}:")
if args.debug:
print(''.join(f"- {f}\n" for f in uncommitted_files_matched))
if len(uncommitted_files_matched) > 0:
total_to_commit += len(uncommitted_files_matched)
# # auto_lfs_track requires huggingface-hub-0.0.15, but transformers forces 0.0.12
repo.git_add(pattern=pattern) # , auto_lfs_track=True)
repo.git_commit(commit_message="new data")
if total_to_commit:
print(f"* Pushing {total_to_commit} files")
repo.git_push()
print("* Pushed")
else:
print("* Detected no new or modified files. Nothing to push.")