Skip to content

Commit ce6278e

Browse files
author
roman_yakovenko
committed
it is better to use "os.name" instead of "sys.platform" for platform specific logic - thanks to Aron Xu
1 parent db2d883 commit ce6278e

File tree

9 files changed

+23
-16
lines changed

9 files changed

+23
-16
lines changed

docs/history/history.rest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Thanks to all the people that have contributed patches, bug reports and suggesti
2323
* Gustavo Carneiro
2424
* Christopher Bruns
2525
* Alejandro Dubrovsky
26+
* Aron Xu
2627

2728
-----------
2829
SVN Version
@@ -63,6 +64,10 @@ SVN Version
6364
11. "__int128_t" and "__uint128_t" types were introduced. Many thanks to Gustavo Carneiro
6465
for providing the patch.
6566

67+
12. Thanks to Aron Xu, for pointing out that it is better to use "os.name",
68+
instead of "sys.platform" for platform specific logic
69+
70+
6671
-----------
6772
Version 1.0
6873
-----------

pygccxml/binary_parsers/undname.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class undname_creator_t:
7373
compiler and demangled name produced by "nm" utility.
7474
"""
7575
def __init__( self ):
76-
if 'win32' in sys.platform:
76+
if 'nt' == os.name:
7777
import ctypes.wintypes
7878
self.__undname = ctypes.windll.dbghelp.UnDecorateSymbolName
7979
self.__undname.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint]
@@ -209,7 +209,7 @@ def format_decl(self, decl, hint=None):
209209
"""
210210
name = None
211211
if hint is None:
212-
if 'win32' in sys.platform:
212+
if 'nt' == os.name:
213213
hint = 'msvc'
214214
else:
215215
hint = 'nm'

pygccxml/parser/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def raise_on_wrong_settings( self ):
173173
super( gccxml_configuration_t, self ).raise_on_wrong_settings()
174174
if os.path.isfile( self.gccxml_path ):
175175
return
176-
if sys.platform == 'win32':
176+
if os.name == 'nt':
177177
gccxml_name = 'gccxml' + '.exe'
178178
environment_var_delimiter = ';'
179179
elif os.name == 'posix':

pygccxml/parser/source_reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __create_command_line(self, file, xmlfile):
9595
#returns
9696
cmd = []
9797
#first is gccxml executable
98-
if 'win32' in sys.platform:
98+
if 'nt' == os.name:
9999
cmd.append( '"%s"' % os.path.normpath( self.__config.gccxml_path ) )
100100
else:
101101
cmd.append( '%s' % os.path.normpath( self.__config.gccxml_path ) )
@@ -118,7 +118,7 @@ def __create_command_line(self, file, xmlfile):
118118
if self.__config.compiler:
119119
cmd.append( " --gccxml-compiler %s" % self.__config.compiler )
120120
cmd_line = ' '.join(cmd)
121-
if 'win32' in sys.platform :
121+
if 'nt' == os.name:
122122
cmd_line = '"%s"' % cmd_line
123123
self.logger.info( 'gccxml cmd: %s' % cmd_line )
124124
return cmd_line
@@ -284,7 +284,7 @@ def __file_full_name( self, file ):
284284
raise RuntimeError( "pygccxml error: file '%s' does not exist" % file )
285285

286286
def __produce_full_file( self, file_path ):
287-
if 'win' in sys.platform or 'linux' in sys.platform:
287+
if os.name in ['nt', 'posix']:
288288
file_path = file_path.replace( r'\/', os.path.sep )
289289
if os.path.isabs( file_path ):
290290
return file_path

pygccxml/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class native_compiler:
170170

171171
@staticmethod
172172
def get_version():
173-
if 'win' not in sys.platform:
173+
if 'nt' != os.name:
174174
return None #not implemented yet
175175
else:
176176
from distutils import msvccompiler

unittests/autoconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class cxx_parsers_cfg:
3939
, compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() )
4040

4141
gccxml.define_symbols.append( gccxml_version )
42-
if 'win' in sys.platform:
42+
if 'nt' == os.name:
4343
gccxml.define_symbols.append( '__PYGCCXML_%s__' % gccxml.compiler.upper() )
4444
if 'msvc9' == gccxml.compiler:
4545
gccxml.define_symbols.append( '_HAS_TR1=0' )

unittests/complex_types_tester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# accompanying file LICENSE_1_0.txt or copy at
44
# http://www.boost.org/LICENSE_1_0.txt)
55

6+
import os
67
import sys
78
import unittest
89
import autoconfig
@@ -32,7 +33,7 @@ def test( self ):
3233

3334
def create_suite():
3435
suite = unittest.TestSuite()
35-
if sys.platform != 'win32':
36+
if os.name != 'nt':
3637
suite.addTest( unittest.makeSuite(tester_t))
3738
return suite
3839

unittests/declarations_tester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# accompanying file LICENSE_1_0.txt or copy at
44
# http://www.boost.org/LICENSE_1_0.txt)
55

6+
import os
67
import sys
78
import pprint
89
import unittest
@@ -205,7 +206,7 @@ def create_suite():
205206
suite = unittest.TestSuite()
206207
suite.addTest( unittest.makeSuite(file_by_file_tester_t))
207208
suite.addTest( unittest.makeSuite(all_at_once_tester_t))
208-
#~ if sys.platform == 'win32' and autoconfig.get_pdb_global_ns():
209+
#~ if os.name == 'nt' and autoconfig.get_pdb_global_ns():
209210
#~ suite.addTest( unittest.makeSuite(pdb_based_tester_t))
210211

211212
return suite

unittests/undname_creator_tester.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class tester_t( parser_test_case.parser_test_case_t ):
2121

2222
@property
2323
def known_issues( self ):
24-
if 'win32' in sys.platform:
24+
if 'nt' == os.name:
2525
issues = set([
2626
# array as function argument: 'int FA10_i_i(int * const)'
2727
'?FA10_i_i@@YAHQAH@Z'
@@ -101,7 +101,7 @@ def __tester_impl( self, fname, expected_symbols ):
101101
for blob in parser.loaded_symbols:
102102
if isinstance( blob, tuple ):
103103
blob = blob[0]
104-
if 'win32' in sys.platform:
104+
if 'nt' == os.name:
105105
#TODO: find out where undecorate function is exposed on linux
106106
undname = binary_parsers.undecorate_blob( blob )
107107
if "`" in undname:
@@ -131,15 +131,15 @@ def __tester_impl( self, fname, expected_symbols ):
131131
self.fail( os.linesep.join(msg) )
132132

133133
def test_map_file( self ):
134-
if 'win32' in sys.platform:
134+
if 'nt' == os.name:
135135
self.__tester_impl( self.map_file, 71 )
136136

137137
def test_dll_file( self ):
138-
if 'win32' in sys.platform:
138+
if 'nt' == os.name:
139139
self.__tester_impl( self.dll_file, 71 )
140140

141141
def test_z_compare_parsers( self ):
142-
if 'win32' not in sys.platform:
142+
if 'nt' != os.name:
143143
return
144144
dsymbols, dparser = binary_parsers.merge_information( self.global_ns, self.dll_file, runs_under_unittest=True )
145145
msymbols, mparser = binary_parsers.merge_information( self.global_ns, self.map_file, runs_under_unittest=True )
@@ -158,7 +158,7 @@ def test_z_compare_parsers( self ):
158158
self.failUnless( was_error == False )
159159

160160
def test_so_file( self ):
161-
if 'linux2' in sys.platform:
161+
if 'posix' in os.name:
162162
self.__tester_impl( self.so_file, 64 )
163163

164164
def dont_test_print( self ):

0 commit comments

Comments
 (0)