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

Commit 826c02d

Browse files
aiudirogfrozencemetery
authored andcommitted
Simplify setup.py
Pull out an Extension() helper and remove 2.6 support vestiges. [rharwood@redhat.com: squashed, wrote commit message]
1 parent 6c9489e commit 826c02d

File tree

1 file changed

+37
-48
lines changed

1 file changed

+37
-48
lines changed

‎setup.py‎

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from setuptools import Distribution
66
from setuptools.command.sdist import sdist
77
from setuptools.extension import Extension
8+
import subprocess
89
import platform
910
import re
1011
import sys
@@ -28,20 +29,12 @@
2829
file=sys.stderr)
2930
SOURCE_EXT = 'c'
3031

31-
get_output = None
3232

33-
try:
34-
import commands
35-
get_output = commands.getoutput
36-
except ImportError:
37-
import subprocess
33+
def get_output(*args, **kwargs):
34+
res = subprocess.check_output(*args, shell=True, **kwargs)
35+
decoded = res.decode('utf-8')
36+
return decoded.strip()
3837

39-
def _get_output(*args, **kwargs):
40-
res = subprocess.check_output(*args, shell=True, **kwargs)
41-
decoded = res.decode('utf-8')
42-
return decoded.strip()
43-
44-
get_output = _get_output
4538

4639
# get the compile and link args
4740
link_args, compile_args = [
@@ -231,14 +224,25 @@ def ext_modules(self):
231224
del self._cythonized_ext_modules
232225

233226

227+
def make_extension(name_fmt, module, **kwargs):
228+
"""Helper method to remove the repetition in extension declarations."""
229+
source = name_fmt.replace('.', '/') % module + '.' + SOURCE_EXT
230+
if not os.path.exists(source):
231+
raise OSError(source)
232+
return Extension(
233+
name_fmt % module,
234+
extra_link_args=link_args,
235+
extra_compile_args=compile_args,
236+
library_dirs=library_dirs,
237+
libraries=libraries,
238+
sources=[source],
239+
**kwargs
240+
)
241+
242+
234243
# detect support
235244
def main_file(module):
236-
return Extension('gssapi.raw.%s' % module,
237-
extra_link_args=link_args,
238-
extra_compile_args=compile_args,
239-
library_dirs=library_dirs,
240-
libraries=libraries,
241-
sources=['gssapi/raw/%s.%s' % (module, SOURCE_EXT)])
245+
return make_extension('gssapi.raw.%s', module)
242246

243247

244248
ENUM_EXTS = []
@@ -248,43 +252,28 @@ def extension_file(module, canary):
248252
if ENABLE_SUPPORT_DETECTION and not hasattr(GSSAPI_LIB, canary):
249253
print('Skipping the %s extension because it '
250254
'is not supported by your GSSAPI implementation...' % module)
251-
return None
252-
else:
253-
enum_ext_path = 'gssapi/raw/_enum_extensions/ext_%s.%s' % (module,
254-
SOURCE_EXT)
255-
if os.path.exists(enum_ext_path):
256-
ENUM_EXTS.append(
257-
Extension('gssapi.raw._enum_extensions.ext_%s' % module,
258-
extra_link_args=link_args,
259-
extra_compile_args=compile_args,
260-
sources=[enum_ext_path],
261-
library_dirs=library_dirs,
262-
libraries=libraries,
263-
include_dirs=['gssapi/raw/']))
264-
265-
return Extension('gssapi.raw.ext_%s' % module,
266-
extra_link_args=link_args,
267-
extra_compile_args=compile_args,
268-
library_dirs=library_dirs,
269-
libraries=libraries,
270-
sources=['gssapi/raw/ext_%s.%s' % (module,
271-
SOURCE_EXT)])
255+
return
256+
257+
try:
258+
ENUM_EXTS.append(
259+
make_extension('gssapi.raw._enum_extensions.ext_%s', module,
260+
include_dirs=['gssapi/raw/'])
261+
)
262+
except OSError:
263+
pass
264+
265+
return make_extension('gssapi.raw.ext_%s', module)
272266

273267

274268
def gssapi_modules(lst):
275269
# filter out missing files
276270
res = [mod for mod in lst if mod is not None]
277271

278272
# add in supported mech files
279-
MECHS_SUPPORTED = os.environ.get('GSSAPI_MECHS', 'krb5').split(',')
280-
for mech in MECHS_SUPPORTED:
281-
res.append(Extension('gssapi.raw.mech_%s' % mech,
282-
extra_link_args=link_args,
283-
extra_compile_args=compile_args,
284-
library_dirs=library_dirs,
285-
libraries=libraries,
286-
sources=['gssapi/raw/mech_%s.%s' % (mech,
287-
SOURCE_EXT)]))
273+
res.extend(
274+
make_extension('gssapi.raw.mech_%s', mech)
275+
for mech in os.environ.get('GSSAPI_MECHS', 'krb5').split(',')
276+
)
288277

289278
# add in any present enum extension files
290279
res.extend(ENUM_EXTS)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /