in submitit/helpers.py [0:0]
def __enter__(self) -> None:
self.original_dir = Path.cwd()
# Get the repository root
root_dir = str(self.root_dir)
sub = "--recurse-submodules" if self.with_submodules else "-s"
# Make a shallow git clone
if not self.snapshot_dir.exists():
self.snapshot_dir.parent.mkdir(parents=True, exist_ok=True)
subprocess.check_call(["git", "clone", "--depth=2", f"file://{root_dir}", str(self.snapshot_dir)])
# Get a list of all the checked in files that we can pass to rsync
# Is Rsync faster than a `git pull` ?
with tempfile.NamedTemporaryFile() as tfile:
# https://stackoverflow.com/a/51689219/4876946
run_cmd(f"git ls-files {sub} | grep -v ^16 | cut -f2- > {tfile.name}", cwd=root_dir, shell=True)
exclude = list(itertools.chain.from_iterable(("--exclude", pat) for pat in self.exclude))
with open(tfile.name, "a", encoding="utf8") as o:
for inc in self.include:
print(inc, file=o)
run_cmd(["rsync", "-a", "--files-from", tfile.name, root_dir, str(self.snapshot_dir)] + exclude)
os.chdir(self.snapshot_dir)