5
5
6
6
If called from the command line, it prints the platform
7
7
information concatenated as single string to stdout. The output
8
- format is useable as part of a filename.
8
+ format is usable as part of a filename.
9
9
10
10
"""
11
11
# This module is maintained by Marc-Andre Lemburg <mal@egenix.com>.
116
116
import os
117
117
import re
118
118
import sys
119
- import subprocess
120
119
import functools
121
120
import itertools
122
121
@@ -169,7 +168,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
169
168
170
169
Note that the function has intimate knowledge of how different
171
170
libc versions add symbols to the executable and thus is probably
172
- only useable for executables compiled using gcc.
171
+ only usable for executables compiled using gcc.
173
172
174
173
The file is read and scanned in chunks of chunksize bytes.
175
174
@@ -187,12 +186,15 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
187
186
188
187
executable = sys .executable
189
188
189
+ if not executable :
190
+ # sys.executable is not set.
191
+ return lib , version
192
+
190
193
V = _comparable_version
191
- if hasattr (os .path , 'realpath' ):
192
- # Python 2.2 introduced os.path.realpath(); it is used
193
- # here to work around problems with Cygwin not being
194
- # able to open symlinks for reading
195
- executable = os .path .realpath (executable )
194
+ # We use os.path.realpath()
195
+ # here to work around problems with Cygwin not being
196
+ # able to open symlinks for reading
197
+ executable = os .path .realpath (executable )
196
198
with open (executable , 'rb' ) as f :
197
199
binary = f .read (chunksize )
198
200
pos = 0
@@ -283,6 +285,7 @@ def _syscmd_ver(system='', release='', version='',
283
285
stdin = subprocess .DEVNULL ,
284
286
stderr = subprocess .DEVNULL ,
285
287
text = True ,
288
+ encoding = "locale" ,
286
289
shell = True )
287
290
except (OSError , subprocess .CalledProcessError ) as why :
288
291
#print('Command %s failed: %s' % (cmd, why))
@@ -609,7 +612,10 @@ def _syscmd_file(target, default=''):
609
612
# XXX Others too ?
610
613
return default
611
614
612
- import subprocess
615
+ try :
616
+ import subprocess
617
+ except ImportError :
618
+ return default
613
619
target = _follow_symlinks (target )
614
620
# "file" output is locale dependent: force the usage of the C locale
615
621
# to get deterministic behavior.
@@ -748,11 +754,16 @@ def from_subprocess():
748
754
"""
749
755
Fall back to `uname -p`
750
756
"""
757
+ try :
758
+ import subprocess
759
+ except ImportError :
760
+ return None
751
761
try :
752
762
return subprocess .check_output (
753
763
['uname' , '-p' ],
754
764
stderr = subprocess .DEVNULL ,
755
765
text = True ,
766
+ encoding = "utf8" ,
756
767
).strip ()
757
768
except (OSError , subprocess .CalledProcessError ):
758
769
pass
@@ -776,6 +787,8 @@ class uname_result(
776
787
except when needed.
777
788
"""
778
789
790
+ _fields = ('system' , 'node' , 'release' , 'version' , 'machine' , 'processor' )
791
+
779
792
@functools .cached_property
780
793
def processor (self ):
781
794
return _unknown_as_blank (_Processor .get ())
@@ -789,7 +802,7 @@ def __iter__(self):
789
802
@classmethod
790
803
def _make (cls , iterable ):
791
804
# override factory to affect length check
792
- num_fields = len (cls ._fields )
805
+ num_fields = len (cls ._fields ) - 1
793
806
result = cls .__new__ (cls , * iterable )
794
807
if len (result ) != num_fields + 1 :
795
808
msg = f'Expected { num_fields } arguments, got { len (result )} '
@@ -803,7 +816,7 @@ def __len__(self):
803
816
return len (tuple (iter (self )))
804
817
805
818
def __reduce__ (self ):
806
- return uname_result , tuple (self )[:len (self ._fields )]
819
+ return uname_result , tuple (self )[:len (self ._fields ) - 1 ]
807
820
808
821
809
822
_uname_cache = None
0 commit comments