yolov5/utils
Glenn Jocher 853505339a
Fix `increment_path()` explicit file vs dir handling (#5523)
Resolves https://github.com/ultralytics/yolov5/pull/5341#issuecomment-961774729

Tests:
```python
import glob
import re
from pathlib import Path


def increment_path(path, exist_ok=False, sep='', mkdir=False):
    # Increment file or directory path, i.e. runs/exp --> runs/exp{sep}2, runs/exp{sep}3, ... etc.
    path = Path(path)  # os-agnostic
    if path.exists() and not exist_ok:
        path, suffix = (path.with_suffix(''), path.suffix) if path.is_file() else (path, '')
        dirs = glob.glob(f"{path}{sep}*")  # similar paths
        matches = [re.search(rf"%s{sep}(\d+)" % path.stem, d) for d in dirs]
        i = [int(m.groups()[0]) for m in matches if m]  # indices
        n = max(i) + 1 if i else 2  # increment number
        path = Path(f"{path}{sep}{n}{suffix}")  # increment path
    if mkdir:
        path.mkdir(parents=True, exist_ok=True)  # make directory
    return path


print(increment_path('runs'))
print(increment_path('export.py'))
print(increment_path('abc.def.dir'))
print(increment_path('abc.def.file'))
```
2021-11-05 15:46:20 +01:00
..
aws Fix `yaml.safe_load()` ignore emoji errors (#5060) 2021-10-05 13:41:52 -07:00
flask_rest_api precommit: isort (#5493) 2021-11-04 17:24:25 +01:00
google_app_engine Add pre-commit CI actions (#4982) 2021-10-28 18:35:01 +02:00
loggers precommit: isort (#5493) 2021-11-04 17:24:25 +01:00
__init__.py Update `sys.path.append(str(ROOT))` (#4852) 2021-09-18 15:02:08 +02:00
activations.py Fix float zeros format (#5491) 2021-11-03 23:36:53 +01:00
augmentations.py precommit: isort (#5493) 2021-11-04 17:24:25 +01:00
autoanchor.py Fix float zeros format (#5491) 2021-11-03 23:36:53 +01:00
autobatch.py Add `autobatch` feature for best `batch-size` estimation (#5092) 2021-10-25 13:56:13 +02:00
callbacks.py Optimised Callback Class to Reduce Code and Fix Errors (#4688) 2021-09-07 18:32:15 +02:00
datasets.py precommit: isort (#5493) 2021-11-04 17:24:25 +01:00
downloads.py Update autodownload fallbacks to v6.0 assets (#5177) 2021-10-13 19:58:38 -07:00
general.py Fix `increment_path()` explicit file vs dir handling (#5523) 2021-11-05 15:46:20 +01:00
loss.py Fix float zeros format (#5491) 2021-11-03 23:36:53 +01:00
metrics.py Adjust legend labels for classes without instances (#5174) 2021-10-14 11:57:00 -07:00
plots.py precommit: isort (#5493) 2021-11-04 17:24:25 +01:00
torch_utils.py Fix float zeros format (#5491) 2021-11-03 23:36:53 +01:00