Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 129b17d

Browse files
committed
More style changes and little cleanups.
Remove __init__ that just called base class __init__ with same args. Fold long argument lists into fewer, shorter lines. Remove parens in tuple unpacks. Don't put multiple statements on one line with a semicolon. In find_library_file() compute the library_filename() upfront.
1 parent df1e092 commit 129b17d

1 file changed

Lines changed: 33 additions & 63 deletions

File tree

Lib/distutils/unixccompiler.py

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,10 @@ class UnixCCompiler(CCompiler):
7979
dylib_lib_extension = ".dylib"
8080
static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
8181

82-
83-
84-
def __init__(self,
85-
verbose=0,
86-
dry_run=0,
87-
force=0):
88-
CCompiler.__init__(self, verbose, dry_run, force)
89-
90-
def preprocess(self,
91-
source,
92-
output_file=None,
93-
macros=None,
94-
include_dirs=None,
95-
extra_preargs=None,
96-
extra_postargs=None):
97-
(_, macros, include_dirs) = \
82+
def preprocess(self, source,
83+
output_file=None, macros=None, include_dirs=None,
84+
extra_preargs=None, extra_postargs=None):
85+
ignore, macros, include_dirs = \
9886
self._fix_compile_args(None, macros, include_dirs)
9987
pp_opts = gen_preprocess_options(macros, include_dirs)
10088
pp_args = self.preprocessor + pp_opts
@@ -117,17 +105,12 @@ def preprocess(self,
117105
except DistutilsExecError, msg:
118106
raise CompileError, msg
119107

120-
def compile(self,
121-
sources,
122-
output_dir=None,
123-
macros=None,
124-
include_dirs=None,
125-
debug=0,
126-
extra_preargs=None,
127-
extra_postargs=None):
128-
(output_dir, macros, include_dirs) = \
108+
def compile(self, sources,
109+
output_dir=None, macros=None, include_dirs=None, debug=0,
110+
extra_preargs=None, extra_postargs=None):
111+
output_dir, macros, include_dirs = \
129112
self._fix_compile_args(output_dir, macros, include_dirs)
130-
(objects, skip_sources) = self._prep_compile(sources, output_dir)
113+
objects, skip_sources = self._prep_compile(sources, output_dir)
131114

132115
# Figure out the options for the compiler command line.
133116
pp_opts = gen_preprocess_options(macros, include_dirs)
@@ -142,27 +125,24 @@ def compile(self,
142125
# Compile all source files that weren't eliminated by
143126
# '_prep_compile()'.
144127
for i in range(len(sources)):
145-
src = sources[i] ; obj = objects[i]
128+
src = sources[i]
129+
obj = objects[i]
146130
if skip_sources[src]:
147131
log.debug("skipping %s (%s up-to-date)", src, obj)
148132
else:
149133
self.mkpath(os.path.dirname(obj))
150134
try:
151135
self.spawn(self.compiler_so + cc_args +
152-
[src, '-o', obj] +
153-
extra_postargs)
136+
[src, '-o', obj] + extra_postargs)
154137
except DistutilsExecError, msg:
155138
raise CompileError, msg
156139

157140
# Return *all* object filenames, not just the ones we just built.
158141
return objects
159142

160-
def create_static_lib(self,
161-
objects,
162-
output_libname,
163-
output_dir=None,
164-
debug=0):
165-
(objects, output_dir) = self._fix_object_args(objects, output_dir)
143+
def create_static_lib(self, objects, output_libname,
144+
output_dir=None, debug=0):
145+
objects, output_dir = self._fix_object_args(objects, output_dir)
166146

167147
output_filename = \
168148
self.library_filename(output_libname, output_dir=output_dir)
@@ -186,25 +166,16 @@ def create_static_lib(self,
186166
else:
187167
log.debug("skipping %s (up-to-date)", output_filename)
188168

189-
def link(self,
190-
target_desc,
191-
objects,
192-
output_filename,
193-
output_dir=None,
194-
libraries=None,
195-
library_dirs=None,
196-
runtime_library_dirs=None,
197-
export_symbols=None,
198-
debug=0,
199-
extra_preargs=None,
200-
extra_postargs=None,
201-
build_temp=None):
202-
(objects, output_dir) = self._fix_object_args(objects, output_dir)
203-
(libraries, library_dirs, runtime_library_dirs) = \
169+
def link(self, target_desc, objects,
170+
output_filename, output_dir=None, libraries=None,
171+
library_dirs=None, runtime_library_dirs=None,
172+
export_symbols=None, debug=0, extra_preargs=None,
173+
extra_postargs=None, build_temp=None):
174+
objects, output_dir = self._fix_object_args(objects, output_dir)
175+
libraries, library_dirs, runtime_library_dirs = \
204176
self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
205177

206-
lib_opts = gen_lib_options(self,
207-
library_dirs, runtime_library_dirs,
178+
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
208179
libraries)
209180
if type(output_dir) not in (StringType, NoneType):
210181
raise TypeError, "'output_dir' must be a string or None"
@@ -261,14 +232,14 @@ def library_option(self, lib):
261232
return "-l" + lib
262233

263234
def find_library_file(self, dirs, lib, debug=0):
235+
shared_f = self.library_filename(lib, lib_type='shared')
236+
dylib_f = self.library_filename(lib, lib_type='dylib')
237+
static_f = self.library_filename(lib, lib_type='static')
238+
264239
for dir in dirs:
265-
shared = os.path.join(
266-
dir, self.library_filename(lib, lib_type='shared'))
267-
dylib = os.path.join(
268-
dir, self.library_filename(lib, lib_type='dylib'))
269-
static = os.path.join(
270-
dir, self.library_filename(lib, lib_type='static'))
271-
240+
shared = os.path.join(dir, shared_f)
241+
dylib = os.path.join(dir, dylib_f)
242+
static = os.path.join(dir, static_f)
272243
# We're second-guessing the linker here, with not much hard
273244
# data to go on: GCC seems to prefer the shared library, so I'm
274245
# assuming that *all* Unix C compilers do. And of course I'm
@@ -279,7 +250,6 @@ def find_library_file(self, dirs, lib, debug=0):
279250
return shared
280251
elif os.path.exists(static):
281252
return static
282-
283-
else:
284-
# Oops, didn't find it in *any* of 'dirs'
285-
return None
253+
254+
# Oops, didn't find it in *any* of 'dirs'
255+
return None

0 commit comments

Comments
 (0)