9
9
from collections import OrderedDict
10
10
from collections .abc import Callable
11
11
from functools import partial
12
+ from pathlib import Path
12
13
13
14
14
15
__all__ = [
@@ -109,7 +110,7 @@ def get_unbound_function(unbound):
109
110
return unbound
110
111
111
112
112
- def maybe_add_to_os_environ_pathlist (var , newpath ):
113
+ def maybe_add_to_os_environ_pathlist (var : str , newpath : Path | str ):
113
114
"""Unfortunately, Conda offers to make itself the default Python
114
115
and those who use it that way will probably not activate envs
115
116
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):
123
124
124
125
`var` will typically be 'PATH'."""
125
126
126
- import os
127
+ newpath = Path ( newpath )
127
128
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
136
139
137
140
138
141
def subprocess_Popen (command , ** params ):
0 commit comments