<commit_before>from __future__ import print_function
from distutils.command import build_ext as _build_ext
import os
from os.path import join, dirname
from setuptools import Extension, find_packages, setup
try:
    from Cython.Distutils import build_ext
except ImportError:
    build_ext = None
import numpy
import sys

# Make sure on OSX we bring in the framework
if sys.platform == "darwin":
    os.environ['LDFLAGS'] = '-framework Qt'

CYTHON_REQUIREMENT = 'Cython==0.19.1'

if build_ext:
    cbpy_module = Extension(
                            'cerebus.cbpy',
                            ['cerebus/cbpyw.pyx',
                             'cerebus/cbpy.cpp', 
                            ],
                            libraries=["cbsdk_static", "QtCore", "QtXml"],
                            include_dirs=[numpy.get_include()],
                            language="c++",             # generate C++ code
    )
else:
    cbpy_module = Extension(
                            'cerebus.cbpy',
                            ['cerebus/cbpyw.cpp',
                             'cerebus/cbpy.cpp', 
                            ],
                            libraries=["cbsdk_static", "QtCore", "QtXml"],
                            include_dirs=[numpy.get_include()],
    )
    
    class build_ext(_build_ext.build_ext):
        def initialize_options(self):
            self.cwd = None
            return _build_ext.build_ext.initialize_options(self)

        def finalize_options(self):
            self.cwd = os.getcwd()
            return _build_ext.build_ext.finalize_options(self)

        def run(self):
            assert os.getcwd() == self.cwd, \
                'Must be in package root: %s' % self.cwd
            print("""
            --> Cython is not installed. Can not compile .pyx files. <--
            Unfortunately, setuptools does not allow us to install
            Cython prior to this point, so you'll have to do it yourself
            and run this command again, if you want to recompile your
            .pyx files.

            `pip install {cython}` should suffice.

            ------------------------------------------------------------
            """.format(
                cython=CYTHON_REQUIREMENT,
            ))
            assert os.path.exists(
                os.path.join(self.cwd, 'cerebus', 'cbpyw.c')), \
                'Source file not found!'
            return _build_ext.build_ext.run(self)



setup(
    name='cerelink',
    version='0.0.1',
    description='Cerebus Link',
    long_description='Cerebus Link Python Package',
    author='dashesy',
    author_email='<EMAIL>',
    url='https://github.com/dashesy/CereLink',
    packages=find_packages(),
    cmdclass={
        'build_ext': build_ext,
    },
    ext_modules=[
        cbpy_module,
    ],
)
<commit_msg>setup.py to work also for OSX<commit_after>from __future__ import print_function
from distutils.command import build_ext as _build_ext
import os
from os.path import join, dirname
from setuptools import Extension, find_packages, setup
try:
    from Cython.Distutils import build_ext
except ImportError:
    build_ext = None
import numpy
import sys

# Make sure on OSX we bring in the framework
if sys.platform == "darwin":
    extra_link_args=['-F', '/usr/local/lib/', '-framework', 'QtCore', '-framework', 'QtXml']
    libraries = ["cbsdk_static"]
else:
    extra_link_args= []
    libraries = ["cbsdk_static", "QtCore", "QtXml"]

CYTHON_REQUIREMENT = 'Cython==0.19.1'

if build_ext:
    cbpy_module = Extension(
                            'cerebus.cbpy',
                            ['cerebus/cbpyw.pyx',
                             'cerebus/cbpy.cpp', 
                            ],
                            libraries=libraries,
                            extra_link_args=extra_link_args,
                            include_dirs=[numpy.get_include()],
                            language="c++",             # generate C++ code
    )
else:
    cbpy_module = Extension(
                            'cerebus.cbpy',
                            ['cerebus/cbpyw.cpp',
                             'cerebus/cbpy.cpp', 
                            ],
                            libraries=libraries,
                            extra_link_args=extra_link_args,
                            include_dirs=[numpy.get_include()],
    )
    
    class build_ext(_build_ext.build_ext):
        def initialize_options(self):
            self.cwd = None
            return _build_ext.build_ext.initialize_options(self)

        def finalize_options(self):
            self.cwd = os.getcwd()
            return _build_ext.build_ext.finalize_options(self)

        def run(self):
            assert os.getcwd() == self.cwd, \
                'Must be in package root: %s' % self.cwd
            print("""
            --> Cython is not installed. Can not compile .pyx files. <--
            Unfortunately, setuptools does not allow us to install
            Cython prior to this point, so you'll have to do it yourself
            and run this command again, if you want to recompile your
            .pyx files.

            `pip install {cython}` should suffice.

            ------------------------------------------------------------
            """.format(
                cython=CYTHON_REQUIREMENT,
            ))
            assert os.path.exists(
                os.path.join(self.cwd, 'cerebus', 'cbpyw.c')), \
                'Source file not found!'
            return _build_ext.build_ext.run(self)



setup(
    name='cerelink',
    version='0.0.1',
    description='Cerebus Link',
    long_description='Cerebus Link Python Package',
    author='dashesy',
    author_email='<EMAIL>',
    url='https://github.com/dashesy/CereLink',
    packages=find_packages(),
    cmdclass={
        'build_ext': build_ext,
    },
    ext_modules=[
        cbpy_module,
    ],
)

{'fraction_non_alphanumeric': 0.11977573904179409, 'fraction_numerical': 0.002378525314305131, 'mean_word_length': 1.547382085677196, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3881737', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1661, 'n_words': 380}