@@ -120,43 +120,41 @@ def save_strings(val) -> None:
120
120
global Save_Strings
121
121
Save_Strings = val
122
122
123
- #
124
- # Avoid unnecessary function calls by recording a Boolean value that
125
- # tells us whether or not os.path.splitdrive() actually does anything
126
- # on this system, and therefore whether we need to bother calling it
127
- # when looking up path names in various methods below.
128
- #
129
123
130
124
do_splitdrive = None
131
- _my_splitdrive = None
125
+ _my_splitdrive = None
132
126
133
127
def initialize_do_splitdrive () -> None :
134
- global do_splitdrive
135
- global has_unc
136
- drive , path = os .path .splitdrive ('X:/foo' )
137
- # splitunc is removed from python 3.7 and newer
138
- # so we can also just test if splitdrive works with UNC
139
- has_unc = (hasattr (os .path , 'splitunc' )
140
- or os .path .splitdrive (r'\\split\drive\test' )[0 ] == r'\\split\drive' )
141
-
142
- do_splitdrive = not not drive or has_unc
143
-
144
- global _my_splitdrive
145
- if has_unc :
146
- def splitdrive (p ):
128
+ """Set up splitdrive usage.
129
+
130
+ Avoid unnecessary function calls by recording a flag that tells us whether
131
+ or not :func:`os.path.splitdrive` actually does anything on this system,
132
+ and therefore whether we need to bother calling it when looking up path
133
+ names in various methods below.
134
+
135
+ If :data:`do_splitdrive` is True, :func:`_my_splitdrive` will be a real
136
+ function which we can call. As all supported Python versions' ntpath module
137
+ now handle UNC paths correctly, we no longer special-case that.
138
+
139
+ Deferring the setup of ``_my_splitdrive`` also lets unit tests do
140
+ their thing and test UNC path handling on a POSIX host.
141
+ """
142
+ global do_splitdrive , _my_splitdrive
143
+
144
+ do_splitdrive = bool (os .path .splitdrive ('X:/foo' )[0 ])
145
+
146
+ if do_splitdrive :
147
+ def _my_splitdrive (p ):
147
148
if p [1 :2 ] == ':' :
148
149
return p [:2 ], p [2 :]
149
150
if p [0 :2 ] == '//' :
150
151
# Note that we leave a leading slash in the path
151
152
# because UNC paths are always absolute.
152
153
return '//' , p [1 :]
153
154
return '' , p
154
- else :
155
- def splitdrive (p ):
156
- if p [1 :2 ] == ':' :
157
- return p [:2 ], p [2 :]
158
- return '' , p
159
- _my_splitdrive = splitdrive
155
+ # TODO: the os routine should work and be better debugged than ours,
156
+ # but unit test test_unc_path fails on POSIX platforms. Resolve someday.
157
+ # _my_splitdrive = os.path.splitdrive
160
158
161
159
# Keep some commonly used values in global variables to skip to
162
160
# module look-up costs.
@@ -1238,7 +1236,10 @@ def __init__(self, path = None) -> None:
1238
1236
self .pathTop = os .getcwd ()
1239
1237
else :
1240
1238
self .pathTop = path
1241
- self .defaultDrive = _my_normcase (_my_splitdrive (self .pathTop )[0 ])
1239
+ if do_splitdrive :
1240
+ self .defaultDrive = _my_normcase (_my_splitdrive (self .pathTop )[0 ])
1241
+ else :
1242
+ self .defaultDrive = ""
1242
1243
1243
1244
self .Top = self .Dir (self .pathTop )
1244
1245
self .Top ._path = '.'
@@ -1554,11 +1555,15 @@ class DirNodeInfo(SCons.Node.NodeInfoBase):
1554
1555
def str_to_node (self , s ):
1555
1556
top = self .fs .Top
1556
1557
root = top .root
1558
+ # Python 3.13/Win changed isabs() - after you split C:/foo/bar,
1559
+ # the path part is no longer considerd absolute. Save the passed
1560
+ # path for the isabs check so we can get the right answer.
1561
+ path = s
1557
1562
if do_splitdrive :
1558
1563
drive , s = _my_splitdrive (s )
1559
1564
if drive :
1560
1565
root = self .fs .get_root (drive )
1561
- if not os .path .isabs (s ):
1566
+ if not os .path .isabs (path ):
1562
1567
s = top .get_labspath () + '/' + s
1563
1568
return root ._lookup_abs (s , Entry )
1564
1569
@@ -2380,7 +2385,7 @@ def __init__(self, drive, fs) -> None:
2380
2385
# The // entry is necessary because os.path.normpath()
2381
2386
# preserves double slashes at the beginning of a path on Posix
2382
2387
# platforms.
2383
- if not has_unc :
2388
+ if not do_splitdrive :
2384
2389
self ._lookupDict ['//' ] = self
2385
2390
2386
2391
def _morph (self ) -> None :
@@ -2511,11 +2516,15 @@ class FileNodeInfo(SCons.Node.NodeInfoBase):
2511
2516
def str_to_node (self , s ):
2512
2517
top = self .fs .Top
2513
2518
root = top .root
2519
+ # Python 3.13/Win changed isabs() - after you split C:/foo/bar,
2520
+ # the path part is no longer considerd absolute. Save the passed
2521
+ # path for the isabs check so we can get the right answer.
2522
+ path = s
2514
2523
if do_splitdrive :
2515
2524
drive , s = _my_splitdrive (s )
2516
2525
if drive :
2517
2526
root = self .fs .get_root (drive )
2518
- if not os .path .isabs (s ):
2527
+ if not os .path .isabs (path ):
2519
2528
s = top .get_labspath () + '/' + s
2520
2529
return root ._lookup_abs (s , Entry )
2521
2530
@@ -3534,7 +3543,7 @@ def is_up_to_date(self) -> bool:
3534
3543
3535
3544
In all cases self is the target we're checking to see if it's up to date
3536
3545
"""
3537
- T = 0
3546
+ T = False
3538
3547
if T : Trace ('is_up_to_date(%s):' % self )
3539
3548
if not self .exists ():
3540
3549
if T : Trace (' not self.exists():' )
@@ -3730,7 +3739,10 @@ def filedir_lookup(self, p, fd=None):
3730
3739
if fd is None :
3731
3740
fd = self .default_filedir
3732
3741
dir , name = os .path .split (fd )
3733
- drive , d = _my_splitdrive (dir )
3742
+ if do_splitdrive :
3743
+ drive , d = _my_splitdrive (dir )
3744
+ else :
3745
+ drive , d = "" , dir
3734
3746
if not name and d [:1 ] in ('/' , OS_SEP ):
3735
3747
#return p.fs.get_root(drive).dir_on_disk(name)
3736
3748
return p .fs .get_root (drive )
0 commit comments