Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/pymongo-4.6.2
Browse files Browse the repository at this point in the history
shyuep authored Feb 26, 2024
2 parents 857f0d7 + e8d965e commit ff39574
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions monty/shutil.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,9 @@ def copy_r(src: str | Path, dst: str | Path) -> None:
os.makedirs(absdst, exist_ok=True)
for f in os.listdir(abssrc):
fpath = Path(abssrc, f)
if Path(fpath).is_file():
if fpath.is_symlink():
continue
elif fpath.is_file():
shutil.copy(fpath, absdst)
elif str(fpath) not in str(absdst):
copy_r(fpath, Path(absdst, f))
@@ -77,7 +79,7 @@ def compress_file(
filepath = Path(filepath)
if compression not in ["gz", "bz2"]:
raise ValueError("Supported compression formats are 'gz' and 'bz2'.")
if filepath.suffix.lower() != f".{compression}":
if filepath.suffix.lower() != f".{compression}" and not filepath.is_symlink():
with open(filepath, "rb") as f_in, zopen(
f"{filepath}.{compression}", "wb"
) as f_out:
4 changes: 2 additions & 2 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ ruamel.yaml==0.18.6
msgpack==1.0.7
tqdm==4.66.2
pymongo==4.6.2
pandas==2.2.0
orjson==3.9.14
pandas==2.2.1
orjson==3.9.15
types-orjson==3.6.2
types-requests==2.31.0.20240125
5 changes: 5 additions & 0 deletions tests/test_shutil.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,11 @@ def setup_method(self):
os.mkdir(os.path.join(test_dir, "cpr_src", "sub"))
with open(os.path.join(test_dir, "cpr_src", "sub", "testr"), "w") as f:
f.write("what2")
if os.name != "nt":
os.symlink(
os.path.join(test_dir, "cpr_src", "test"),
os.path.join(test_dir, "cpr_src", "mysymlink"),
)

def test_recursive_copy_and_compress(self):
copy_r(os.path.join(test_dir, "cpr_src"), os.path.join(test_dir, "cpr_dst"))

0 comments on commit ff39574

Please sign in to comment.