Skip to content

Commit 465b3b3

Browse files
committed
Remove os.path in utils.py
1 parent 3df6d40 commit 465b3b3

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

pytensor/utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections import OrderedDict
1010
from collections.abc import Callable
1111
from functools import partial
12+
from pathlib import Path
1213

1314

1415
__all__ = [
@@ -109,7 +110,7 @@ def get_unbound_function(unbound):
109110
return unbound
110111

111112

112-
def maybe_add_to_os_environ_pathlist(var, newpath):
113+
def maybe_add_to_os_environ_pathlist(var: str, newpath: Path | str):
113114
"""Unfortunately, Conda offers to make itself the default Python
114115
and those who use it that way will probably not activate envs
115116
correctly meaning e.g. mingw-w64 g++ may not be on their PATH.
@@ -123,16 +124,18 @@ def maybe_add_to_os_environ_pathlist(var, newpath):
123124
124125
`var` will typically be 'PATH'."""
125126

126-
import os
127+
newpath = Path(newpath)
127128

128-
if os.path.isabs(newpath):
129-
try:
130-
oldpaths = os.environ[var].split(os.pathsep)
131-
if newpath not in oldpaths:
132-
newpaths = os.pathsep.join([newpath, *oldpaths])
133-
os.environ[var] = newpaths
134-
except Exception:
135-
pass
129+
if not newpath.is_absolute():
130+
return
131+
132+
try:
133+
oldpaths = os.environ[var].split(os.pathsep)
134+
if not any(newpath.samefile(p) for p in oldpaths):
135+
newpaths = os.pathsep.join([str(newpath), *oldpaths])
136+
os.environ[var] = newpaths
137+
except Exception:
138+
pass
136139

137140

138141
def subprocess_Popen(command, **params):

0 commit comments

Comments
 (0)