mirror of
				https://github.com/msgpack/msgpack-python.git
				synced 2025-10-31 17:40:54 +00:00 
			
		
		
		
	setup: automatically fallback to pure Python module
Signed-off-by: Bas Westerbaan <bas@westerbaan.name>
This commit is contained in:
		
							parent
							
								
									6a28b28c63
								
							
						
					
					
						commit
						2627b6ae9f
					
				
					 1 changed files with 12 additions and 5 deletions
				
			
		
							
								
								
									
										15
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -8,6 +8,9 @@ from setuptools import setup, Extension | ||||||
| 
 | 
 | ||||||
| from distutils.command.build_ext import build_ext | from distutils.command.build_ext import build_ext | ||||||
| 
 | 
 | ||||||
|  | class NoCython(Exception): | ||||||
|  |     pass | ||||||
|  | 
 | ||||||
| try: | try: | ||||||
|     import Cython.Compiler.Main as cython_compiler |     import Cython.Compiler.Main as cython_compiler | ||||||
|     have_cython = True |     have_cython = True | ||||||
|  | @ -24,10 +27,7 @@ def ensure_source(src): | ||||||
| 
 | 
 | ||||||
|     if not os.path.exists(src): |     if not os.path.exists(src): | ||||||
|         if not have_cython: |         if not have_cython: | ||||||
|             raise Exception("""\ |             raise NoCython | ||||||
| Cython is required for building extension from checkout. |  | ||||||
| Install Cython >= 0.16 or install msgpack from PyPI. |  | ||||||
| """) |  | ||||||
|         cythonize(pyx) |         cythonize(pyx) | ||||||
|     elif (os.path.exists(pyx) and |     elif (os.path.exists(pyx) and | ||||||
|           os.stat(src).st_mtime < os.stat(pyx).st_mtime and |           os.stat(src).st_mtime < os.stat(pyx).st_mtime and | ||||||
|  | @ -38,7 +38,14 @@ Install Cython >= 0.16 or install msgpack from PyPI. | ||||||
| 
 | 
 | ||||||
| class BuildExt(build_ext): | class BuildExt(build_ext): | ||||||
|     def build_extension(self, ext): |     def build_extension(self, ext): | ||||||
|  |         try: | ||||||
|             ext.sources = list(map(ensure_source, ext.sources)) |             ext.sources = list(map(ensure_source, ext.sources)) | ||||||
|  |         except NoCython: | ||||||
|  |             print "WARNING" | ||||||
|  |             print "Cython is required for building extension from checkout." | ||||||
|  |             print "Install Cython >= 0.16 or install msgpack from PyPI." | ||||||
|  |             print "Falling back to pure Python implementation." | ||||||
|  |             return | ||||||
|         return build_ext.build_extension(self, ext) |         return build_ext.build_extension(self, ext) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Bas Westerbaan
						Bas Westerbaan