mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	Integrate patch from @mikepb re building OpenMP-supporting wheels for macOS / OSX. I'm running blind on this, so this commit might not be 100%. Rollback if there are any problems. See Issue #267.
This commit is contained in:
		
							parent
							
								
									efe7790439
								
							
						
					
					
						commit
						36bcd46244
					
				
							
								
								
									
										57
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								setup.py
									
									
									
									
									
								
							| 
						 | 
					@ -15,6 +15,9 @@ except ImportError:
 | 
				
			||||||
    from distutils.core import Extension, setup
 | 
					    from distutils.core import Extension, setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PACKAGE_DATA = {'': ['*.pyx', '*.pxd', '*.txt', '*.tokens']}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PACKAGES = [
 | 
					PACKAGES = [
 | 
				
			||||||
    'spacy',
 | 
					    'spacy',
 | 
				
			||||||
    'spacy.tokens',
 | 
					    'spacy.tokens',
 | 
				
			||||||
| 
						 | 
					@ -76,39 +79,56 @@ MOD_NAMES = [
 | 
				
			||||||
    'spacy.syntax.iterators']
 | 
					    'spacy.syntax.iterators']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
compile_options =  {
 | 
					COMPILE_OPTIONS =  {
 | 
				
			||||||
    'msvc': ['/Ox', '/EHsc'],
 | 
					    'msvc': ['/Ox', '/EHsc'],
 | 
				
			||||||
    'mingw32' : ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function'],
 | 
					    'mingw32' : ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function'],
 | 
				
			||||||
    'other' : ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function']
 | 
					    'other' : ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function']
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
link_options = {
 | 
					LINK_OPTIONS = {
 | 
				
			||||||
    'msvc' : [],
 | 
					    'msvc' : [],
 | 
				
			||||||
    'mingw32': [],
 | 
					    'mingw32': [],
 | 
				
			||||||
    'other' : []
 | 
					    'other' : []
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
if os.environ.get('USE_OPENMP') == '1':
 | 
					# I don't understand this very well yet. See Issue #267
 | 
				
			||||||
    compile_options['msvc'].append('/openmp')
 | 
					# Fingers crossed!
 | 
				
			||||||
 | 
					#if os.environ.get('USE_OPENMP') == '1':
 | 
				
			||||||
 | 
					#    compile_options['msvc'].append('/openmp')
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#if not sys.platform.startswith('darwin'):
 | 
				
			||||||
 | 
					#    compile_options['other'].append('-fopenmp')
 | 
				
			||||||
 | 
					#    link_options['other'].append('-fopenmp')
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					USE_OPENMP_DEFAULT = '1' if sys.platform != 'darwin' else None
 | 
				
			||||||
 | 
					if os.environ.get('USE_OPENMP', USE_OPENMP_DEFAULT) == '1':
 | 
				
			||||||
 | 
					    if sys.platform == 'darwin':
 | 
				
			||||||
 | 
					        COMPILE_OPTIONS['other'].append('-fopenmp')
 | 
				
			||||||
 | 
					        LINK_OPTIONS['other'].append('-fopenmp')
 | 
				
			||||||
 | 
					        PACKAGE_DATA['spacy.platform.darwin.lib'] = ['*.dylib']
 | 
				
			||||||
 | 
					        PACKAGES.append('spacy.platform.darwin.lib')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if not sys.platform.startswith('darwin'):
 | 
					    elif sys.platform == 'win32':
 | 
				
			||||||
    compile_options['other'].append('-fopenmp')
 | 
					        COMPILE_OPTIONS['msvc'].append('/openmp')
 | 
				
			||||||
    link_options['other'].append('-fopenmp')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        COMPILE_OPTIONS['other'].append('-fopenmp')
 | 
				
			||||||
 | 
					        LINK_OPTIONS['other'].append('-fopenmp')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# By subclassing build_extensions we have the actual compiler that will be used which is really known only after finalize_options
 | 
					# By subclassing build_extensions we have the actual compiler that will be used which is really known only after finalize_options
 | 
				
			||||||
# http://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
 | 
					# http://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
 | 
				
			||||||
class build_ext_options:
 | 
					class build_ext_options:
 | 
				
			||||||
    def build_options(self):
 | 
					    def build_options(self):
 | 
				
			||||||
        for e in self.extensions:
 | 
					        for e in self.extensions:
 | 
				
			||||||
            e.extra_compile_args = compile_options.get(
 | 
					            e.extra_compile_args += COMPILE_OPTIONS.get(
 | 
				
			||||||
                self.compiler.compiler_type, compile_options['other'])
 | 
					                self.compiler.compiler_type, COMPILE_OPTIONS['other'])
 | 
				
			||||||
        for e in self.extensions:
 | 
					        for e in self.extensions:
 | 
				
			||||||
            e.extra_link_args = link_options.get(
 | 
					            e.extra_link_args += LINK_OPTIONS.get(
 | 
				
			||||||
                self.compiler.compiler_type, link_options['other'])
 | 
					                self.compiler.compiler_type, LINK_OPTIONS['other'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class build_ext_subclass(build_ext, build_ext_options):
 | 
					class build_ext_subclass(build_ext, build_ext_options):
 | 
				
			||||||
| 
						 | 
					@ -176,9 +196,19 @@ def setup_package():
 | 
				
			||||||
        ext_modules = []
 | 
					        ext_modules = []
 | 
				
			||||||
        for mod_name in MOD_NAMES:
 | 
					        for mod_name in MOD_NAMES:
 | 
				
			||||||
            mod_path = mod_name.replace('.', '/') + '.cpp'
 | 
					            mod_path = mod_name.replace('.', '/') + '.cpp'
 | 
				
			||||||
 | 
					            extra_link_args = []
 | 
				
			||||||
 | 
					            # ???
 | 
				
			||||||
 | 
					            # Imported from patch from @mikepb
 | 
				
			||||||
 | 
					            # See Issue #267. Running blind here...
 | 
				
			||||||
 | 
					            if sys.platform == 'darwin':
 | 
				
			||||||
 | 
					                dylib_path = ['..' for _ in range(mod_name.count('.'))]
 | 
				
			||||||
 | 
					                dylib_path = '/'.join(dylib_path)
 | 
				
			||||||
 | 
					                dylib_path = '@loader_path/%s/spacy/platform/darwin/lib' % dylib_path
 | 
				
			||||||
 | 
					                extra_link_args.append('-Wl,-rpath,%s' % dylib_path)
 | 
				
			||||||
            ext_modules.append(
 | 
					            ext_modules.append(
 | 
				
			||||||
                Extension(mod_name, [mod_path],
 | 
					                Extension(mod_name, [mod_path],
 | 
				
			||||||
                    language='c++', include_dirs=include_dirs))
 | 
					                    language='c++', include_dirs=include_dirs,
 | 
				
			||||||
 | 
					                    extra_link_args=extra_link_args))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not is_source_release(root):
 | 
					        if not is_source_release(root):
 | 
				
			||||||
            generate_cython(root, 'spacy')
 | 
					            generate_cython(root, 'spacy')
 | 
				
			||||||
| 
						 | 
					@ -187,7 +217,7 @@ def setup_package():
 | 
				
			||||||
            name=about['__title__'],
 | 
					            name=about['__title__'],
 | 
				
			||||||
            zip_safe=False,
 | 
					            zip_safe=False,
 | 
				
			||||||
            packages=PACKAGES,
 | 
					            packages=PACKAGES,
 | 
				
			||||||
            package_data={'': ['*.pyx', '*.pxd', '*.txt', '*.tokens']},
 | 
					            package_data=PACKAGE_DATA,
 | 
				
			||||||
            description=about['__summary__'],
 | 
					            description=about['__summary__'],
 | 
				
			||||||
            long_description=readme,
 | 
					            long_description=readme,
 | 
				
			||||||
            author=about['__author__'],
 | 
					            author=about['__author__'],
 | 
				
			||||||
| 
						 | 
					@ -231,4 +261,3 @@ def setup_package():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    setup_package()
 | 
					    setup_package()
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user