Skip to content

Commit

Permalink
Improve windows specific path check
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Feb 23, 2024
1 parent a97a4c1 commit ced3a8e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ctapipe/core/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
import os
import pathlib
import re
import sys
from urllib.parse import urlparse

import traitlets
Expand Down Expand Up @@ -164,11 +166,7 @@ def validate(self, obj, value):
except ValueError:
return self.error(obj, value)

if len(url.scheme) == 1:
# looks like a windows drive letter, so assume it is
value = pathlib.Path(value)

elif url.scheme in ("http", "https"):
if url.scheme in ("http", "https"):
# here to avoid circular import, since every module imports
# from ctapipe.core
from ctapipe.utils.download import download_cached
Expand All @@ -182,6 +180,9 @@ def validate(self, obj, value):
value = get_dataset_path(value.partition("dataset://")[2])
elif url.scheme in ("", "file"):
value = pathlib.Path(url.netloc, url.path)
elif sys.platform == "win32" and re.match(r"^[A-Z]:\\", value):
# looks like a windows drive letter, so assume it is
value = pathlib.Path(value)
else:
return self.error(obj, value)

Expand Down

0 comments on commit ced3a8e

Please sign in to comment.