Skip to content

Commit

Permalink
Simplify setup.py
Browse files Browse the repository at this point in the history
Pull out an Extension() helper and remove 2.6 support vestiges.

[rharwood@redhat.com: squashed, wrote commit message]
  • Loading branch information
aiudirog authored and frozencemetery committed Jul 16, 2019
1 parent 6c9489e commit 826c02d
Showing 1 changed file with 37 additions and 48 deletions.
85 changes: 37 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from setuptools import Distribution
from setuptools.command.sdist import sdist
from setuptools.extension import Extension
import subprocess
import platform
import re
import sys
Expand All @@ -28,20 +29,12 @@
file=sys.stderr)
SOURCE_EXT = 'c'

get_output = None

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

def _get_output(*args, **kwargs):
res = subprocess.check_output(*args, shell=True, **kwargs)
decoded = res.decode('utf-8')
return decoded.strip()

get_output = _get_output

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


def make_extension(name_fmt, module, **kwargs):
"""Helper method to remove the repetition in extension declarations."""
source = name_fmt.replace('.', '/') % module + '.' + SOURCE_EXT
if not os.path.exists(source):
raise OSError(source)
return Extension(
name_fmt % module,
extra_link_args=link_args,
extra_compile_args=compile_args,
library_dirs=library_dirs,
libraries=libraries,
sources=[source],
**kwargs
)


# detect support
def main_file(module):
return Extension('gssapi.raw.%s' % module,
extra_link_args=link_args,
extra_compile_args=compile_args,
library_dirs=library_dirs,
libraries=libraries,
sources=['gssapi/raw/%s.%s' % (module, SOURCE_EXT)])
return make_extension('gssapi.raw.%s', module)


ENUM_EXTS = []
Expand All @@ -248,43 +252,28 @@ def extension_file(module, canary):
if ENABLE_SUPPORT_DETECTION and not hasattr(GSSAPI_LIB, canary):
print('Skipping the %s extension because it '
'is not supported by your GSSAPI implementation...' % module)
return None
else:
enum_ext_path = 'gssapi/raw/_enum_extensions/ext_%s.%s' % (module,
SOURCE_EXT)
if os.path.exists(enum_ext_path):
ENUM_EXTS.append(
Extension('gssapi.raw._enum_extensions.ext_%s' % module,
extra_link_args=link_args,
extra_compile_args=compile_args,
sources=[enum_ext_path],
library_dirs=library_dirs,
libraries=libraries,
include_dirs=['gssapi/raw/']))

return Extension('gssapi.raw.ext_%s' % module,
extra_link_args=link_args,
extra_compile_args=compile_args,
library_dirs=library_dirs,
libraries=libraries,
sources=['gssapi/raw/ext_%s.%s' % (module,
SOURCE_EXT)])
return

try:
ENUM_EXTS.append(
make_extension('gssapi.raw._enum_extensions.ext_%s', module,
include_dirs=['gssapi/raw/'])
)
except OSError:
pass

return make_extension('gssapi.raw.ext_%s', module)


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

# add in supported mech files
MECHS_SUPPORTED = os.environ.get('GSSAPI_MECHS', 'krb5').split(',')
for mech in MECHS_SUPPORTED:
res.append(Extension('gssapi.raw.mech_%s' % mech,
extra_link_args=link_args,
extra_compile_args=compile_args,
library_dirs=library_dirs,
libraries=libraries,
sources=['gssapi/raw/mech_%s.%s' % (mech,
SOURCE_EXT)]))
res.extend(
make_extension('gssapi.raw.mech_%s', mech)
for mech in os.environ.get('GSSAPI_MECHS', 'krb5').split(',')
)

# add in any present enum extension files
res.extend(ENUM_EXTS)
Expand Down

0 comments on commit 826c02d

Please sign in to comment.