Skip to content

Simplify setup.py #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 53 additions & 73 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,43 @@
headers = []
version_define = ''


def _maybe_clang(flags):
if platform.system() not in ('Darwin', 'FreeBSD'):
return

os.environ.setdefault('CC', 'clang')
os.environ.setdefault('CXX', 'clang++')
orig_customize_compiler = distutils.sysconfig.customize_compiler

def customize_compiler(compiler):
orig_customize_compiler(compiler)
compiler.compiler[0] = os.environ['CC']
compiler.compiler_so[0] = os.environ['CXX']
compiler.compiler_cxx[0] = os.environ['CXX']
compiler.linker_so[0] = os.environ['CXX']
return compiler
distutils.sysconfig.customize_compiler = customize_compiler
flags[:] = ['-c', '-O3'] + flags + ['stdlib=libc++']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, slight typo here -- fixing this



def _maybe_macos(flags):
if platform.system() != 'Darwin':
return
flags.append('-mmacosx-version-min=10.7',)
macver = tuple(map(int, platform.mac_ver()[0].split('.')))
if macver >= (10, 9):
flags.append(
'-Wno-error=unused-command-line-argument-hard-error-in-future',
)


if system_sass:
flags = [
'-fPIC', '-std=gnu++0x', '-Wall', '-Wno-parentheses', '-Werror=switch',
]
platform.mac_ver()
if platform.system() in ['Darwin', 'FreeBSD']:
os.environ.setdefault('CC', 'clang')
os.environ.setdefault('CXX', 'clang++')
orig_customize_compiler = distutils.sysconfig.customize_compiler

def customize_compiler(compiler):
orig_customize_compiler(compiler)
compiler.compiler[0] = os.environ['CC']
compiler.compiler_so[0] = os.environ['CXX']
compiler.compiler_cxx[0] = os.environ['CXX']
compiler.linker_so[0] = os.environ['CXX']
return compiler
distutils.sysconfig.customize_compiler = customize_compiler
flags.append('-stdlib=libc++')
if platform.system() == 'Darwin':
flags.append('-mmacosx-version-min=10.7',)
macver = tuple(map(int, platform.mac_ver()[0].split('.')))
if macver >= (10, 9):
flags.append(
'-Wno-error=unused-command-line-' +
'argument-hard-error-in-future', # noqa
)

flags = ['-c', '-O3'] + flags
_maybe_clang(flags)
_maybe_macos(flags)

if platform.system() == 'FreeBSD':
link_flags = ['-fPIC', '-lc++']
Expand Down Expand Up @@ -90,10 +98,10 @@ def customize_compiler(compiler):
libsass_version = libsass_version_file.read().decode('UTF-8').strip()
if sys.platform == 'win32':
# This looks wrong, but is required for some reason :(
version_define = r'/DLIBSASS_VERSION="\"{0}\""'.format(
version_define = r'/DLIBSASS_VERSION="\"{}\""'.format(
libsass_version)
else:
version_define = '-DLIBSASS_VERSION="{0}"'.format(libsass_version)
version_define = '-DLIBSASS_VERSION="{}"'.format(libsass_version)

for directory in (
os.path.join('libsass', 'src'),
Expand All @@ -109,7 +117,7 @@ def customize_compiler(compiler):

if sys.platform == 'win32':
from distutils.msvc9compiler import get_build_version
vscomntools_env = 'VS{0}{1}COMNTOOLS'.format(
vscomntools_env = 'VS{}{}COMNTOOLS'.format(
int(get_build_version()),
int(get_build_version() * 10) % 10
)
Expand All @@ -131,29 +139,10 @@ def customize_compiler(compiler):
'-fPIC', '-std=gnu++0x', '-Wall',
'-Wno-parentheses', '-Werror=switch',
]
platform.mac_ver()
if platform.system() in ['Darwin', 'FreeBSD']:
os.environ.setdefault('CC', 'clang')
os.environ.setdefault('CXX', 'clang++')
orig_customize_compiler = distutils.sysconfig.customize_compiler

def customize_compiler(compiler):
orig_customize_compiler(compiler)
compiler.compiler[0] = os.environ['CC']
compiler.compiler_so[0] = os.environ['CXX']
compiler.compiler_cxx[0] = os.environ['CXX']
compiler.linker_so[0] = os.environ['CXX']
return compiler
distutils.sysconfig.customize_compiler = customize_compiler
flags.append('-stdlib=libc++')
if platform.system() == 'Darwin':
flags.append('-mmacosx-version-min=10.7',)
macver = tuple(map(int, platform.mac_ver()[0].split('.')))
if macver >= (10, 9):
flags.append(
'-Wno-error=unused-command-line-' +
'argument-hard-error-in-future', # noqa
)
_maybe_clang(flags)
_maybe_macos(flags)

if platform.system() in ('Darwin', 'FreeBSD'):
# Dirty workaround to avoid link error...
# Python distutils doesn't provide any way
# to configure different flags for each cc and c++.
Expand All @@ -162,26 +151,24 @@ def customize_compiler(compiler):
with open(cencode_path) as f:
cencode_body = f.read()
with open(cencode_path, 'w') as f:
f.write('''
#ifdef __cplusplus
extern "C" {
#endif
''')
f.write(
'#ifdef __cplusplus\n'
'extern "C" {\n'
'#endif\n'
)
f.write(cencode_body)
f.write('''
#ifdef __cplusplus
}
#endif
''')
f.write(
'#ifdef __cplusplus\n'
'}\n'
'#endif\n'
)

@atexit.register
def restore_cencode():
if os.path.isfile(cencode_path):
with open(cencode_path, 'w') as f:
f.write(cencode_body)

flags = ['-c', '-O3'] + flags

if platform.system() == 'FreeBSD':
link_flags = ['-fPIC', '-lc++']
else:
Expand All @@ -192,19 +179,16 @@ def restore_cencode():
extra_compile_args = flags + [version_define]
extra_link_args = link_flags

sources.sort()
sass_extension = Extension(
'_sass',
sources,
sorted(sources),
include_dirs=include_dirs,
depends=headers,
extra_compile_args=extra_compile_args,
extra_link_args=link_flags,
libraries=libraries
)

install_requires = ['six']


def version(sass_filename='sass.py'):
with open(sass_filename) as f:
Expand Down Expand Up @@ -287,12 +271,8 @@ def run(self):
['sassc = sassc:main'],
]
},
install_requires=install_requires,
extras_require={
'upload_appveyor_builds': [
'twine == 1.5.0',
],
},
install_requires=['six'],
extras_require={'upload_appveyor_builds': ['twine == 1.5.0']},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
Expand Down