Skip to content

Commit

Permalink
Merge pull request #6 from idiap/fix-join-paths
Browse files Browse the repository at this point in the history
Correctly join paths in remove_experiment_folder
  • Loading branch information
eginhard authored Jun 28, 2024
2 parents 0f77de2 + 966db29 commit 6f1f613
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["trainer*"]

[project]
name = "coqui-tts-trainer"
version = "0.1.2"
version = "0.1.3"
description = "General purpose model trainer for PyTorch that is more flexible than it should be, by 🐸Coqui."
readme = "README.md"
requires-python = ">=3.9, <3.13"
Expand Down
24 changes: 24 additions & 0 deletions tests/test_generic_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pathlib import Path

from trainer.generic_utils import remove_experiment_folder


def test_remove_experiment_folder():
output_dir = Path("output")
run_dir = output_dir / "run"
run_dir.mkdir(exist_ok=True, parents=True)

remove_experiment_folder(run_dir)
assert not run_dir.is_dir()

run_dir.mkdir(exist_ok=True, parents=True)
checkpoint = run_dir / "checkpoint.pth"
checkpoint.touch(exist_ok=False)
remove_experiment_folder(run_dir)
assert checkpoint.is_file()

remove_experiment_folder(str(run_dir) + "/")
assert checkpoint.is_file()

checkpoint.unlink()
run_dir.rmdir()
2 changes: 1 addition & 1 deletion trainer/generic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def remove_experiment_folder(experiment_path: Union[str, os.PathLike[Any]]) -> N
"""Check folder if there is a checkpoint, otherwise remove the folder"""
experiment_path = str(experiment_path)
fs = fsspec.get_mapper(experiment_path).fs
checkpoint_files = fs.glob(experiment_path + "/*.pth")
checkpoint_files = fs.glob(os.path.join(experiment_path, "*.pth"))
if not checkpoint_files:
if fs.exists(experiment_path):
fs.rm(experiment_path, recursive=True)
Expand Down

0 comments on commit 6f1f613

Please sign in to comment.