-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,23 @@ | |
from setuptools.command.build_ext import build_ext | ||
from distutils.version import LooseVersion | ||
|
||
from setuptools.command.develop import develop | ||
from setuptools.command.install import install | ||
from setuptools.command.sdist import sdist | ||
from setuptools.command.build_py import build_py | ||
from setuptools import setup, find_packages | ||
from subprocess import check_call, check_output | ||
|
||
with open('README.rst') as f: | ||
readme = f.read() | ||
|
||
""" Specific versions of submodules to use. """ | ||
|
||
submoduleVersions = { | ||
'clipper2': 'Clipper2_1.3.0', | ||
'pybind11': 'v2.11', | ||
'eigen': '3.4' | ||
} | ||
|
||
class CMakeExtension(Extension): | ||
def __init__(self, name, modName, sourcedir=''): | ||
|
@@ -22,8 +35,57 @@ def __init__(self, name, modName, sourcedir=''): | |
self.sourcedir = os.path.abspath(sourcedir) | ||
|
||
|
||
def gitcmd_update_submodules(): | ||
""" | ||
Check if the package is being deployed as a git repository. If so, recursively update all dependencies. | ||
""" | ||
|
||
if os.path.exists('.git'): | ||
|
||
check_call(['git', 'submodule', 'update', '--init', '--recursive']) | ||
|
||
# set all versions as required | ||
for k, v in submoduleVersions.items(): | ||
check_call(['git', '-C', 'external/{:s}'.format(k), 'checkout', v]) | ||
|
||
check_call(['git', 'submodule', 'status']) | ||
|
||
return True | ||
|
||
return False | ||
|
||
|
||
class gitcmd_develop(develop): | ||
""" | ||
Specialized packaging class that runs `git submodule update --init --recursive` | ||
as part of the update/install procedure. | ||
""" | ||
def run(self): | ||
gitcmd_update_submodules() | ||
develop.run(self) | ||
|
||
|
||
class gitcmd_install(install): | ||
""" | ||
Specialized packaging class that runs `git submodule update --init --recursive` | ||
as part of the update/install procedure. | ||
""" | ||
def run(self): | ||
gitcmd_update_submodules() | ||
install.run(self) | ||
|
||
class gitcmd_sdist(sdist): | ||
""" | ||
Specialized packaging class that runs git submodule update --init --recursive | ||
as part of the update/install procedure;. | ||
""" | ||
def run(self): | ||
gitcmd_update_submodules() | ||
sdist.run(self) | ||
|
||
class CMakeBuild(build_ext): | ||
def run(self): | ||
|
||
try: | ||
out = subprocess.check_output(['cmake', '--version']) | ||
except OSError: | ||
|
@@ -39,6 +101,11 @@ def run(self): | |
self.build_extension(ext) | ||
|
||
def build_extension(self, ext): | ||
""" | ||
Builds the following CMake extension within the project tree | ||
:param ext: CMake Extension to build | ||
""" | ||
print('ext_full_path', self.get_ext_fullpath(ext.name)) | ||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) | ||
# required for auto-detection of auxiliary "native" libs | ||
|
@@ -71,20 +138,23 @@ def build_extension(self, ext): | |
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) | ||
subprocess.check_call(['cmake', '--build', '.', '--target', ext.modName] + build_args, cwd=self.build_temp) | ||
|
||
# subprocess.check_call(['cmake', '--build', '.', '--target', 'install'], cwd=self.build_temp) | ||
|
||
|
||
setup( | ||
name='pyclipr', | ||
version='0.1.6', | ||
version='0.1.7', | ||
author='Luke Parry', | ||
author_email='[email protected]', | ||
url='https://github.com/drlukeparry/pyclipr', | ||
long_description=readme, | ||
long_description_content_type = 'text/x-rst', | ||
description='Python library for polygon clipping and offsetting based on Clipper2.', | ||
ext_modules=[CMakeExtension('pyclipr.pyclipr', 'pyclipr')], | ||
cmdclass=dict(build_ext=CMakeBuild), | ||
cmdclass= { | ||
'build_ext': CMakeBuild, | ||
'develop': gitcmd_develop, | ||
'install': gitcmd_install, | ||
'sdist': gitcmd_sdist, | ||
}, | ||
packages = ['pyclipr'], | ||
package_dir={'': 'python'}, | ||
keywords=['polygon clipping', 'polygon offsetting', 'libClipper', 'Clipper2', 'polygon boolean', 'polygon', 'line clipping', 'clipper'], | ||
|