Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit77939d2

Browse files
authored
Update platform from CPython 3.11.5 (RustPython#5060)
* Update platform and test from CPython 3.11.5* sys.dllhandle (=0)* Unmark fixed test of test_sysconfig---------Co-authored-by: CPython Developers <>
1 parent9cf18a8 commit77939d2

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

‎Lib/platform.py‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
If called from the command line, it prints the platform
77
information concatenated as single string to stdout. The output
8-
format isuseable as part of a filename.
8+
format isusable as part of a filename.
99
1010
"""
1111
# This module is maintained by Marc-Andre Lemburg <mal@egenix.com>.
@@ -116,7 +116,6 @@
116116
importos
117117
importre
118118
importsys
119-
importsubprocess
120119
importfunctools
121120
importitertools
122121

@@ -169,7 +168,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
169168
170169
Note that the function has intimate knowledge of how different
171170
libc versions add symbols to the executable and thus is probably
172-
onlyuseable for executables compiled using gcc.
171+
onlyusable for executables compiled using gcc.
173172
174173
The file is read and scanned in chunks of chunksize bytes.
175174
@@ -187,12 +186,15 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
187186

188187
executable=sys.executable
189188

189+
ifnotexecutable:
190+
# sys.executable is not set.
191+
returnlib,version
192+
190193
V=_comparable_version
191-
ifhasattr(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)
196198
withopen(executable,'rb')asf:
197199
binary=f.read(chunksize)
198200
pos=0
@@ -283,6 +285,7 @@ def _syscmd_ver(system='', release='', version='',
283285
stdin=subprocess.DEVNULL,
284286
stderr=subprocess.DEVNULL,
285287
text=True,
288+
encoding="locale",
286289
shell=True)
287290
except (OSError,subprocess.CalledProcessError)aswhy:
288291
#print('Command %s failed: %s' % (cmd, why))
@@ -609,7 +612,10 @@ def _syscmd_file(target, default=''):
609612
# XXX Others too ?
610613
returndefault
611614

612-
importsubprocess
615+
try:
616+
importsubprocess
617+
exceptImportError:
618+
returndefault
613619
target=_follow_symlinks(target)
614620
# "file" output is locale dependent: force the usage of the C locale
615621
# to get deterministic behavior.
@@ -748,11 +754,16 @@ def from_subprocess():
748754
"""
749755
Fall back to `uname -p`
750756
"""
757+
try:
758+
importsubprocess
759+
exceptImportError:
760+
returnNone
751761
try:
752762
returnsubprocess.check_output(
753763
['uname','-p'],
754764
stderr=subprocess.DEVNULL,
755765
text=True,
766+
encoding="utf8",
756767
).strip()
757768
except (OSError,subprocess.CalledProcessError):
758769
pass
@@ -776,6 +787,8 @@ class uname_result(
776787
except when needed.
777788
"""
778789

790+
_fields= ('system','node','release','version','machine','processor')
791+
779792
@functools.cached_property
780793
defprocessor(self):
781794
return_unknown_as_blank(_Processor.get())
@@ -789,7 +802,7 @@ def __iter__(self):
789802
@classmethod
790803
def_make(cls,iterable):
791804
# override factory to affect length check
792-
num_fields=len(cls._fields)
805+
num_fields=len(cls._fields)-1
793806
result=cls.__new__(cls,*iterable)
794807
iflen(result)!=num_fields+1:
795808
msg=f'Expected{num_fields} arguments, got{len(result)}'
@@ -803,7 +816,7 @@ def __len__(self):
803816
returnlen(tuple(iter(self)))
804817

805818
def__reduce__(self):
806-
returnuname_result,tuple(self)[:len(self._fields)]
819+
returnuname_result,tuple(self)[:len(self._fields)-1]
807820

808821

809822
_uname_cache=None

‎Lib/test/test_platform.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def clear_caches(self):
7878
deftest_architecture(self):
7979
res=platform.architecture()
8080

81-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
8281
@os_helper.skip_unless_symlink
82+
@support.requires_subprocess()
8383
deftest_architecture_via_symlink(self):# issue3762
8484
withsupport.PythonSymlink()aspy:
8585
cmd="-c","import platform; print(platform.architecture())"
@@ -269,7 +269,16 @@ def test_uname_slices(self):
269269
self.assertEqual(res[:],expected)
270270
self.assertEqual(res[:5],expected[:5])
271271

272+
deftest_uname_fields(self):
273+
self.assertIn('processor',platform.uname()._fields)
274+
275+
deftest_uname_asdict(self):
276+
res=platform.uname()._asdict()
277+
self.assertEqual(len(res),6)
278+
self.assertIn('processor',res)
279+
272280
@unittest.skipIf(sys.platformin ['win32','OpenVMS'],"uname -p not used")
281+
@support.requires_subprocess()
273282
deftest_uname_processor(self):
274283
"""
275284
On some systems, the processor must match the output
@@ -346,6 +355,7 @@ def test_mac_ver(self):
346355
else:
347356
self.assertEqual(res[2],'PowerPC')
348357

358+
349359
@unittest.skipUnless(sys.platform=='darwin',"OSX only test")
350360
deftest_mac_ver_with_fork(self):
351361
# Issue7895: platform.mac_ver() crashes when using fork without exec
@@ -362,6 +372,7 @@ def test_mac_ver_with_fork(self):
362372
# parent
363373
support.wait_process(pid,exitcode=0)
364374

375+
@unittest.skipIf(support.is_emscripten,"Does not apply to Emscripten")
365376
deftest_libc_ver(self):
366377
# check that libc_ver(executable) doesn't raise an exception
367378
ifos.path.isdir(sys.executable)and \

‎Lib/test/test_sysconfig.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ def test_get_scheme_names(self):
346346
wanted.extend(['nt_user','osx_framework_user','posix_user'])
347347
self.assertEqual(get_scheme_names(),tuple(sorted(wanted)))
348348

349-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
350349
@skip_unless_symlink
351350
@requires_subprocess()
352351
deftest_symlink(self):# Issue 7880

‎vm/src/stdlib/sys.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ mod sys {
7171
constPS1:&str =">>>>> ";
7272
#[pyattr(name ="ps2")]
7373
constPS2:&str ="..... ";
74+
7475
#[cfg(windows)]
7576
#[pyattr(name ="_vpath")]
7677
constVPATH:Option<&'staticstr> =None;// TODO: actual VPATH value
7778

79+
#[cfg(windows)]
80+
#[pyattr(name ="dllhandle")]
81+
constDLLHANDLE:usize =0;
82+
7883
#[pyattr]
7984
fndefault_prefix(_vm:&VirtualMachine) ->&'staticstr{
8085
// TODO: the windows one doesn't really make sense

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp