Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
drlukeparry committed Jan 10, 2024
2 parents 7a78f39 + c1684ee commit fb2201e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 23 deletions.
32 changes: 31 additions & 1 deletion .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

jobs:
deploy:

runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -70,3 +69,34 @@ jobs:
run: |
python3 -m twine upload dist/*
deploySource:
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Display Python version
run: python3 -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install setuptools wheel twine
- name: Install APT On Linux
run: |
sudo apt-get update -qq -y
sudo apt-get install -qq -y libglu1-mesa build-essential libeigen3-dev
- name: Build
run: |
python3 setup.py sdist
- name: Publish (Source)
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ All notable changes to this project will be documented in this file.

### Changed

## [0.1.7] - 2024-01-11

## [0.1.6] - 2023-16-12
### Added
- Updated build script to prepare source distribution (Linux)
- Script automatically pulls the specified submodule versions in setup.py

### Fixed
- Fixed old references to original build-scripts
- Fixed the external submodules (clipper2, pybind, eigen) to fixed version for reference
- Fixed a build issue with latest ClipperLib (PreserveCollinear property has become a protected member)

## [0.1.6] - 2023-12-16

### Added

Expand Down
19 changes: 7 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ link_directories(
)

if(BUILD_PYTHON)
message(STATUS "Building PyCork Python Module")
message(STATUS "Building PyClipr Python Module")

add_subdirectory(external/pybind11)

Expand Down Expand Up @@ -202,40 +202,35 @@ else(BUILD_PYTHON)
endif(BUILD_PYTHON)

set(App_SRCS
cork/main.cpp
main.cpp
)

SOURCE_GROUP("App" FILES ${App_SRCS})

if(BUILD_PYTHON)

set(PYCORK_SRCS
set(PYCLIPR_SRCS
python/pyclipr/module.cpp
)

SOURCE_GROUP("Python" FILES ${PYCORK_SRCS})
SOURCE_GROUP("Python" FILES ${PYCLIPR_SRCS})

pybind11_add_module(pyclipr ${PYCORK_SRCS})
pybind11_add_module(pyclipr ${PYCLIPR_SRCS})

#add_library(example MODULE main.cpp)

target_link_libraries(pyclipr PRIVATE pybind11::module clipr_static ${PYCORK_LIBS})
target_link_libraries(pyclipr PRIVATE pybind11::module clipr_static ${PYCLIPR_LIBS})

set_target_properties(pyclipr PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")


#add_executable(main ${App_SRCS})

#target_link_libraries(main clipr_static ${PYCLIPR_LIBS})

install(TARGETS pyclipr DESTINATION lib/pyclipr)


else(BUILD_PYTHON)

add_executable(main ${App_SRCS})
target_link_libraries(main clipr ${PYCORK_LIBS})
target_link_libraries(main clipr ${PYCLIPR_LIBS})

#install(TARGETS mpir DESTINATION )

Expand Down
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include LICENSE
include README.rst
include CHANGELOG.md
include CMakeLists.txt
graft external/*
graft CMake/*

include python/pyclipr
recursive-include external *
include python/pyclipr/*

4 changes: 2 additions & 2 deletions python/pyclipr/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,12 @@ PYBIND11_MODULE(pyclipr, m) {
.def_readwrite("scaleFactor", &pyclipr::Clipper::scaleFactor, R"(
Scale factor to be for transforming the input and output vectors. The default is 1000 )"
)
.def_readwrite("preserveCollinear", &pyclipr::Clipper::PreserveCollinear, R"(
.def_property("preserveCollinear", [](const pyclipr::Clipper &s ) { return s.PreserveCollinear();}
, [](pyclipr::Clipper &s, bool val ) { return s.PreserveCollinear(val);}, R"(
By default, when three or more vertices are collinear in input polygons (subject or clip),
the Clipper object removes the 'inner' vertices before clipping. When enabled the PreserveCollinear property
prevents this default behavior to allow these inner vertices to appear in the solution.
)" )
//.def("addPath", &pyclipr::Clipper::addPath)
.def("addPath", &pyclipr::Clipper::addPath, py::arg("path"), py::arg("pathType"), py::arg("isOpen") = false, R"(
The addPath method adds one or more closed subject paths (polygons) to the Clipper object.
Expand Down
78 changes: 74 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=''):
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit fb2201e

Please sign in to comment.