Created
February 18, 2016 18:22
-
-
Save denis-bz/c8b137812812f5e6ec74 to your computer and use it in GitHub Desktop.
Lightfm-setup.py with compile_args link_args for macosx 10.8, gcc-4.9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://github.com/lyst/lightfm/blob/master/setup.py 2016-02-17 feb | |
# compile_args link_args that worked for me on: | |
# macosx 10.8.3, gcc-4.9, python 2.7.6, no Anaconda; comments welcome | |
# denis-bz-py t-online.de | |
import glob | |
import os | |
import platform | |
import subprocess | |
import sys | |
from setuptools import Command, Extension, setup | |
from setuptools.command.test import test as TestCommand | |
# http://stackoverflow.com/questions/6301003/stopping-setup-py-from-installing-as-egg | |
# better way within setup.py ? | |
if sys.argv[-1] == "install": | |
sys.argv += "--single-version-externally-managed --root=/" .split() | |
def define_extensions(file_ext): | |
compile_args = "-fopenmp -ffast-math -Wa,-q -arch x86_64" .split() | |
# There are problems with illegal ASM instructions | |
# http://stackoverflow.com/questions/26574743/mac-osx-10-8-5-gcc4-9-compilation-issues-for-avx-support | |
# when using the Anaconda distribution (at least on OSX). | |
# This could be because Anaconda uses its own assembler? | |
# To work around this we do not add -march=native if we | |
# know we're dealing with Anaconda | |
# if 'anaconda' not in sys.version.lower(): | |
# compile_args.append('-march=native')" # ?? | |
return [Extension("lightfm.lightfm_fast", | |
['lightfm/lightfm_fast%s' % file_ext], | |
extra_link_args="-fopenmp -arch x86_64" .split(), # -v: all ld args | |
extra_compile_args=compile_args)] | |
def set_gcc(): | |
""" | |
Try to find and use GCC on OSX for OpenMP support. | |
""" | |
# For macports and homebrew | |
patterns = ['/opt/local/bin/gcc-mp-[0-9].[0-9]', | |
'/opt/local/bin/gcc-mp-[0-9]', | |
'/usr/local/bin/gcc-[0-9].[0-9]', | |
'/usr/local/bin/gcc-[0-9]'] | |
if 'darwin' in platform.platform().lower(): | |
gcc_binaries = [] | |
for pattern in patterns: | |
gcc_binaries += glob.glob(pattern) | |
gcc_binaries.sort() | |
if gcc_binaries: | |
_, gcc = os.path.split(gcc_binaries[-1]) | |
os.environ["CC"] = gcc | |
else: | |
raise Exception('No GCC available. Install gcc from Homebrew ' | |
'using brew install gcc.') | |
class Cythonize(Command): | |
""" | |
Compile the extension .pyx files. | |
""" | |
user_options = [] | |
def initialize_options(self): | |
pass | |
def finalize_options(self): | |
pass | |
def run(self): | |
import Cython | |
from Cython.Build import cythonize | |
cythonize(define_extensions('.pyx')) | |
class Clean(Command): | |
""" | |
Clean build files. | |
""" | |
user_options = [] | |
def initialize_options(self): | |
pass | |
def finalize_options(self): | |
pass | |
def run(self): | |
pth = os.path.dirname(os.path.abspath(__file__)) | |
subprocess.call(['rm', '-rf', os.path.join(pth, 'build')]) | |
subprocess.call(['rm', '-rf', os.path.join(pth, 'lightfm.egg-info')]) | |
subprocess.call(['find', pth, '-name', 'lightfm*.pyc', '-type', 'f', '-delete']) | |
subprocess.call(['rm', os.path.join(pth, 'lightfm', 'lightfm_fast.so')]) | |
class PyTest(TestCommand): | |
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")] | |
def initialize_options(self): | |
TestCommand.initialize_options(self) | |
self.pytest_args = ['tests/'] | |
def finalize_options(self): | |
TestCommand.finalize_options(self) | |
self.test_args = [] | |
self.test_suite = True | |
def run_tests(self): | |
# import here, cause outside the eggs aren't loaded | |
import pytest | |
errno = pytest.main(self.pytest_args) | |
sys.exit(errno) | |
set_gcc() | |
setup( | |
name='lightfm', | |
version='1.8', | |
description='LightFM recommendation model', | |
url='https://github.com/lyst/lightfm', | |
download_url='https://github.com/lyst/lightfm/tarball/1.8', | |
packages=['lightfm'], | |
install_requires=['numpy', 'scipy'], | |
# examples require p7zip lxml requests sklearn | |
tests_require=['pytest', 'requests', 'scikit-learn'], | |
cmdclass={'test': PyTest, 'cythonize': Cythonize, 'clean': Clean}, | |
author='Lyst Ltd (Maciej Kula)', | |
author_email='data@ly.st', | |
license='MIT', | |
classifiers=['Development Status :: 3 - Alpha', | |
'License :: OSI Approved :: MIT License', | |
'Topic :: Scientific/Engineering :: Artificial Intelligence'], | |
ext_modules=define_extensions('.c') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment