Skip to content

Commit 952b235

Browse files
committed
Grouped with other string/path modification functions
1 parent 8b1374a commit 952b235

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/murfey/util/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@
2424
logger = logging.getLogger("murfey.util")
2525

2626

27-
def posix_path(path: Path) -> str:
28-
"""
29-
Converts a Windows-style path into a Posix one. Used primarily when running
30-
subproceses in bash terminals, which can only accept Posix paths.
31-
"""
32-
path_parts = list(path.parts)
33-
# Check if it's a Windows-style path
34-
if path_parts[0].endswith((":/", ":\\")):
35-
path_parts[0] = "/" + path_parts[0].strip(":/\\").lower()
36-
posix_path = "/".join(path_parts)
37-
return posix_path
38-
return str(path)
39-
40-
4127
def read_config() -> configparser.ConfigParser:
4228
config = configparser.ConfigParser()
4329
try:
@@ -81,6 +67,22 @@ def secure_path(in_path: Path) -> Path:
8167
return Path("/".join(secured_parts))
8268

8369

70+
def posix_path(path: Path) -> str:
71+
"""
72+
Converts a Windows-style path into a Posix one. Used primarily when running
73+
subproceses in bash terminals on Windows devices, which can only accept
74+
Posix paths.
75+
"""
76+
path_parts = list(path.parts)
77+
# Check if it's a Windows-style path and converts it to a Posix one
78+
# e.g.: C:\Users\user -> /c/Users/user
79+
if path_parts[0].endswith((":/", ":\\")):
80+
path_parts[0] = "/" + path_parts[0].strip(":/\\").lower()
81+
posix_path = "/".join(path_parts)
82+
return posix_path
83+
return str(path)
84+
85+
8486
@lru_cache(maxsize=1)
8587
def get_machine_config(url: str, instrument_name: str = "", demo: bool = False) -> dict:
8688
_instrument_name: str | None = instrument_name or os.getenv("BEAMLINE")

0 commit comments

Comments
 (0)