|
1 | | -import sys |
2 | | -import os |
3 | | -import subprocess |
4 | | -import re |
5 | | -import platform |
6 | | - |
7 | | -import setuptools |
8 | | -from setuptools import setup, Extension |
9 | | -from setuptools.command.build_ext import build_ext |
10 | | -from distutils.version import LooseVersion |
11 | | - |
12 | | -FILE_DIR = os.path.dirname(os.path.abspath(__file__)) |
13 | | - |
14 | | -class CMakeExtension(Extension): |
15 | | - def __init__(self, name, sourcedir=''): |
16 | | - Extension.__init__(self, name, sources=[]) |
17 | | - self.sourcedir = os.path.abspath(sourcedir) |
18 | | - |
19 | | - |
20 | | -class CMakeBuild(build_ext): |
21 | | - def run(self): |
22 | | - try: |
23 | | - out = subprocess.check_output(['cmake', '--version']) |
24 | | - except OSError: |
25 | | - raise RuntimeError( |
26 | | - "CMake must be installed to build the following extensions: " + |
27 | | - ", ".join(e.name for e in self.extensions)) |
28 | | - |
29 | | - if platform.system() == "Windows": |
30 | | - cmake_version = LooseVersion( |
31 | | - re.search(r'version\s*([\d.]+)', out.decode()).group(1)) |
32 | | - if cmake_version < '3.1.0': |
33 | | - raise RuntimeError("CMake >= 3.1.0 is required on Windows") |
34 | | - |
35 | | - for ext in self.extensions: |
36 | | - self.build_extension(ext) |
37 | | - |
38 | | - def build_extension(self, ext): |
39 | | - extdir = os.path.abspath( |
40 | | - os.path.dirname(self.get_ext_fullpath(ext.name))) |
41 | | - cmake_args = [ |
42 | | - '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
43 | | - '-DPYTHON_EXECUTABLE=' + sys.executable |
44 | | - ] |
45 | | - |
46 | | - cfg = 'Debug' if self.debug else 'Release' |
47 | | - build_args = ['--config', cfg] |
48 | | - |
49 | | - if platform.system() == "Windows": |
50 | | - cmake_args += [ |
51 | | - '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( |
52 | | - cfg.upper(), extdir) |
53 | | - ] |
54 | | - if sys.maxsize > 2**32: |
55 | | - cmake_args += ['-A', 'x64'] |
56 | | - build_args += ['--', '/m'] |
57 | | - else: |
58 | | - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
59 | | - build_args += ['--', '-j8'] |
60 | | - |
61 | | - env = os.environ.copy() |
62 | | - env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format( |
63 | | - env.get('CXXFLAGS', ''), self.distribution.get_version()) |
64 | | - if not os.path.exists(self.build_temp): |
65 | | - os.makedirs(self.build_temp) |
66 | | - subprocess.check_call( |
67 | | - ['cmake', ext.sourcedir] + cmake_args, |
68 | | - cwd=self.build_temp, |
69 | | - env=env) |
70 | | - subprocess.check_call( |
71 | | - ['cmake', '--build', '.'] + build_args, cwd=self.build_temp) |
72 | | - |
73 | | - |
74 | | -def get_readme_contents(): |
75 | | - with open(os.path.join(FILE_DIR, 'README.md'), 'r') as readme_file: |
76 | | - return readme_file.read() |
77 | | - |
78 | | - |
79 | | -setup( |
80 | | - name='mapbox_earcut', |
81 | | - use_scm_version=True, |
82 | | - url='https://github.com/skogler/mapbox_earcut_python', |
83 | | - author='Samuel Kogler', |
84 | | - author_email='samuel.kogler@gmail.com', |
85 | | - description= |
86 | | - 'Python bindings for the mapbox earcut C++ polygon triangulation library.', |
87 | | - long_description=get_readme_contents(), |
88 | | - long_description_content_type='text/markdown', |
89 | | - license='ISC', |
90 | | - ext_modules=[CMakeExtension('mapbox_earcut')], |
91 | | - setup_requires=['setuptools_scm'], |
92 | | - install_requires=['numpy'], |
93 | | - cmdclass=dict(build_ext=CMakeBuild), |
94 | | - zip_safe=False, |
95 | | - project_urls={ |
96 | | - 'Source': 'https://github.com/skogler/mapbox_earcut_python', |
97 | | - 'Original C++ Source': 'https://github.com/mapbox/earcut.hpp', |
98 | | - }) |
| 1 | +import sys |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +import re |
| 5 | +import platform |
| 6 | + |
| 7 | +import setuptools |
| 8 | +from setuptools import setup, Extension |
| 9 | +from setuptools.command.build_ext import build_ext |
| 10 | +from distutils.version import LooseVersion |
| 11 | + |
| 12 | +FILE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 13 | + |
| 14 | +class CMakeExtension(Extension): |
| 15 | + def __init__(self, name, sourcedir=''): |
| 16 | + Extension.__init__(self, name, sources=[]) |
| 17 | + self.sourcedir = os.path.abspath(sourcedir) |
| 18 | + |
| 19 | + |
| 20 | +class CMakeBuild(build_ext): |
| 21 | + def run(self): |
| 22 | + try: |
| 23 | + out = subprocess.check_output(['cmake', '--version']) |
| 24 | + except OSError: |
| 25 | + raise RuntimeError( |
| 26 | + "CMake must be installed to build the following extensions: " + |
| 27 | + ", ".join(e.name for e in self.extensions)) |
| 28 | + |
| 29 | + if platform.system() == "Windows": |
| 30 | + cmake_version = LooseVersion( |
| 31 | + re.search(r'version\s*([\d.]+)', out.decode()).group(1)) |
| 32 | + if cmake_version < '3.1.0': |
| 33 | + raise RuntimeError("CMake >= 3.1.0 is required on Windows") |
| 34 | + |
| 35 | + for ext in self.extensions: |
| 36 | + self.build_extension(ext) |
| 37 | + |
| 38 | + def build_extension(self, ext): |
| 39 | + extdir = os.path.abspath( |
| 40 | + os.path.dirname(self.get_ext_fullpath(ext.name))) |
| 41 | + cmake_args = [ |
| 42 | + '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
| 43 | + '-DPYTHON_EXECUTABLE=' + sys.executable |
| 44 | + ] |
| 45 | + |
| 46 | + cfg = 'Debug' if self.debug else 'Release' |
| 47 | + build_args = ['--config', cfg] |
| 48 | + |
| 49 | + if platform.system() == "Windows": |
| 50 | + cmake_args += [ |
| 51 | + '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( |
| 52 | + cfg.upper(), extdir) |
| 53 | + ] |
| 54 | + if sys.maxsize > 2**32: |
| 55 | + cmake_args += ['-A', 'x64'] |
| 56 | + build_args += ['--', '/m'] |
| 57 | + else: |
| 58 | + cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
| 59 | + build_args += ['--', '-j8'] |
| 60 | + |
| 61 | + env = os.environ.copy() |
| 62 | + env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format( |
| 63 | + env.get('CXXFLAGS', ''), self.distribution.get_version()) |
| 64 | + if not os.path.exists(self.build_temp): |
| 65 | + os.makedirs(self.build_temp) |
| 66 | + subprocess.check_call( |
| 67 | + ['cmake', ext.sourcedir] + cmake_args, |
| 68 | + cwd=self.build_temp, |
| 69 | + env=env) |
| 70 | + subprocess.check_call( |
| 71 | + ['cmake', '--build', '.'] + build_args, cwd=self.build_temp) |
| 72 | + |
| 73 | + |
| 74 | +def get_readme_contents(): |
| 75 | + with open(os.path.join(FILE_DIR, 'README.md'), 'r') as readme_file: |
| 76 | + return readme_file.read() |
| 77 | + |
| 78 | + |
| 79 | +setup( |
| 80 | + name='mapbox_earcut', |
| 81 | + use_scm_version=True, |
| 82 | + url='https://github.com/skogler/mapbox_earcut_python', |
| 83 | + author='Samuel Kogler', |
| 84 | + author_email='samuel.kogler@gmail.com', |
| 85 | + description= |
| 86 | + 'Python bindings for the mapbox earcut C++ polygon triangulation library.', |
| 87 | + long_description=get_readme_contents(), |
| 88 | + long_description_content_type='text/markdown', |
| 89 | + license='ISC', |
| 90 | + ext_modules=[CMakeExtension('mapbox_earcut')], |
| 91 | + setup_requires=['setuptools_scm'], |
| 92 | + install_requires=['numpy'], |
| 93 | + cmdclass=dict(build_ext=CMakeBuild), |
| 94 | + zip_safe=False, |
| 95 | + project_urls={ |
| 96 | + 'Source': 'https://github.com/skogler/mapbox_earcut_python', |
| 97 | + 'Original C++ Source': 'https://github.com/mapbox/earcut.hpp', |
| 98 | + }, |
| 99 | + include_package_data = True |
| 100 | +) |
0 commit comments