|
1 | 1 | import setuptools
|
2 | 2 |
|
3 | 3 | with open("README.md", "r") as fh:
|
4 |
| - long_description= fh.read() |
| 4 | + long_description = fh.read() |
| 5 | + |
| 6 | +# Adapted from https://github.com/pybind/python_example/blob/master/setup.py |
| 7 | +class get_pybind_include(object): |
| 8 | + """Helper class to determine the pybind11 include path |
| 9 | + The purpose of this class is to postpone importing pybind11 |
| 10 | + until it is actually installed, so that the ``get_include()`` |
| 11 | + method can be invoked. """ |
| 12 | + |
| 13 | + def __init__(self, user=False, pep517=False): |
| 14 | + self.user = user |
| 15 | + self.pep517 = pep517 |
| 16 | + |
| 17 | + def __str__(self): |
| 18 | + import os |
| 19 | + import pybind11 |
| 20 | + |
| 21 | + interpreter_include_path = pybind11.get_include(self.user) |
| 22 | + |
| 23 | + if self.pep517: |
| 24 | + # When pybind11 is installed permanently in site packages, the headers |
| 25 | + # will be in the interpreter include path above. PEP 517 provides an |
| 26 | + # experimental feature for build system dependencies. When installing |
| 27 | + # a package from a source distribvution, first its build dependencies |
| 28 | + # are installed in a temporary location. pybind11 does not return the |
| 29 | + # correct path for this condition, so we glom together a second path, |
| 30 | + # and ultimately specify them _both_ in the include search path. |
| 31 | + # https://github.com/pybind/pybind11/issues/1067 |
| 32 | + return os.path.abspath( |
| 33 | + os.path.join( |
| 34 | + os.path.dirname(pybind11.__file__), |
| 35 | + "..", |
| 36 | + "..", |
| 37 | + "..", |
| 38 | + "..", |
| 39 | + "include", |
| 40 | + os.path.basename(interpreter_include_path), |
| 41 | + ) |
| 42 | + ) |
| 43 | + else: |
| 44 | + return interpreter_include_path |
| 45 | + |
5 | 46 |
|
6 | 47 | # `tiny_obj_loader.cc` contains implementation of tiny_obj_loader.
|
7 |
| -m = setuptools.Extension('tinyobjloader', |
8 |
| - sources = ['bindings.cc', 'tiny_obj_loader.cc'], |
9 |
| - extra_compile_args=['-std=c++11'], |
10 |
| - include_dirs = ['../', '../pybind11/include'] |
11 |
| - ) |
12 |
| - |
13 |
| - |
14 |
| -setuptools.setup (name = 'tinyobjloader', |
15 |
| - version = '0.1', |
16 |
| - description = 'Python module for tinyobjloader', |
17 |
| - long_description = long_description, |
18 |
| - long_description_content_type = "text/markdown", |
19 |
| - author="Syoyo Fujita", |
20 |
| - |
21 |
| - url="https://github.com/syoyo/tinyobjloader", |
22 |
| - classifiers=[ |
23 |
| - "License :: OSI Approved :: MIT License", |
24 |
| - ], |
25 |
| - packages=setuptools.find_packages(), |
26 |
| - ext_modules = [m]) |
| 48 | +m = setuptools.Extension( |
| 49 | + "tinyobjloader", |
| 50 | + extra_compile_args=["-std=c++11"], |
| 51 | + sources=["bindings.cc", "tiny_obj_loader.cc"], |
| 52 | + include_dirs=[ |
| 53 | + # Support `build_ext` finding tinyobjloader (without first running |
| 54 | + # `sdist`). |
| 55 | + "..", |
| 56 | + # Support `build_ext` finding pybind 11 (provided it's permanently |
| 57 | + # installed). |
| 58 | + get_pybind_include(), |
| 59 | + get_pybind_include(user=True), |
| 60 | + # Support building from a source distribution finding pybind11 from |
| 61 | + # a PEP 517 temporary install. |
| 62 | + get_pybind_include(pep517=True), |
| 63 | + ], |
| 64 | + language="c++", |
| 65 | +) |
27 | 66 |
|
28 | 67 |
|
| 68 | +setuptools.setup( |
| 69 | + name="tinymetabobjloader", |
| 70 | + version="0.1.0", |
| 71 | + description="Experimental fork of tinyobjloader Python module", |
| 72 | + long_description=long_description, |
| 73 | + long_description_content_type="text/markdown", |
| 74 | + author="Syoyo Fujita, Paul Melnikow", |
| 75 | + |
| 76 | + url="https://github.com/metabolize/tinyobjloader", |
| 77 | + classifiers=["License :: OSI Approved :: MIT License"], |
| 78 | + packages=setuptools.find_packages(), |
| 79 | + ext_modules=[m], |
| 80 | +) |
0 commit comments