Skip to content

Commit

Permalink
fix semicolon regex
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptofine committed Nov 9, 2023
1 parent 1ac3a5e commit f23787d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions imdataset_creator/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from string import Formatter
from typing import Any, ClassVar

from pathvalidate import sanitize_filename, sanitize_filepath
from typing_extensions import SupportsIndex


Expand Down Expand Up @@ -39,7 +40,7 @@ def get_field(self, field_name: str, _: Sequence[Any], kwargs: Mapping[str, Any]
return super().get_field(field_name, _, kwargs)


escaped_split = re.compile(r"[^\\],")
escaped_split = re.compile(r"(?<!\\),")
condition_fmt = re.compile(r"^(?P<prompt>[^\?:]+)\?(?P<true>(?:[^:])*):?(?P<false>.*)$") # present?yes:no
replacement_fmt = re.compile(r"'(?P<from>[^']+)'='(?P<to>[^']*)'")

Expand Down Expand Up @@ -83,11 +84,13 @@ def __format__(self, format_spec: str):
newpth = "_".join(newpth.split(" "))
elif fmt == "underscore_parts":
newpth = "_".join(Path(newpth).parts)
elif fmt == "sanitize":
newpth = sanitize_filename(newpth, platform="auto")

elif not patterns_used:
raise ValueError(f"Unknown format specifier: {fmt!r}")

return str(newpth)
return newpth

def __getitem__(self, __key: SupportsIndex | slice) -> str:
return MalleablePath(super().__getitem__(__key))
Expand Down Expand Up @@ -117,5 +120,5 @@ def from_src(cls, src: Path, pth: Path):
src=MalleablePath(src),
relative_path=MalleablePath(pth.relative_to(src).parent),
file=MalleablePath(pth.stem),
ext=pth.suffix[1:],
ext=pth.suffix[1:], # Can't think of a MP usecase here. If anyone does, I'm happy to change this
)

0 comments on commit f23787d

Please sign in to comment.