turn pyclipper into a package, export dynamic '__version__'
the _version.py file is autogenerated at build time from git tag using setuptools_scm; the pyclipper.__version__ variable exports that, as it's common in python packaging. This allows clients to import pyclipper and check its __version__ without needing to query the package metadata (which may be missing when pyclipper is embedded in native applications).
This commit is contained in:
parent
fc2772aba0
commit
8aefba84b5
8 changed files with 19 additions and 9 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -3,7 +3,8 @@ build
|
||||||
dist
|
dist
|
||||||
pyclipper.egg-info
|
pyclipper.egg-info
|
||||||
*.so
|
*.so
|
||||||
pyclipper/pyclipper.cpp
|
src/pyclipper/_pyclipper.cpp
|
||||||
|
src/pyclipper/_version.py
|
||||||
*.pyc
|
*.pyc
|
||||||
MANIFEST
|
MANIFEST
|
||||||
.eggs/
|
.eggs/
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
# Here we only need to include those which are not tracked by git but we do
|
# Here we only need to include those which are not tracked by git but we do
|
||||||
# want to be included
|
# want to be included
|
||||||
include pyclipper/pyclipper.cpp
|
include src/pyclipper/_pyclipper.cpp
|
||||||
|
|
||||||
# and exclude those that are tracked by git but don't want to be in the sdist
|
# and exclude those that are tracked by git but don't want to be in the sdist
|
||||||
exclude dev
|
exclude dev
|
||||||
|
|
|
||||||
15
setup.py
15
setup.py
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from setuptools import setup
|
from setuptools import setup, find_packages
|
||||||
from setuptools.extension import Extension
|
from setuptools.extension import Extension
|
||||||
from io import open
|
from io import open
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ if dev_mode:
|
||||||
from Cython.Distutils import build_ext
|
from Cython.Distutils import build_ext
|
||||||
|
|
||||||
print('Development mode: Compiling Cython modules from .pyx sources.')
|
print('Development mode: Compiling Cython modules from .pyx sources.')
|
||||||
sources = ["pyclipper/pyclipper.pyx", "pyclipper/clipper.cpp"]
|
sources = ["src/pyclipper/_pyclipper.pyx", "src/clipper.cpp"]
|
||||||
|
|
||||||
from setuptools.command.sdist import sdist as _sdist
|
from setuptools.command.sdist import sdist as _sdist
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ if dev_mode:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('Distribution mode: Compiling Cython generated .cpp sources.')
|
print('Distribution mode: Compiling Cython generated .cpp sources.')
|
||||||
sources = ["pyclipper/pyclipper.cpp", "pyclipper/clipper.cpp"]
|
sources = ["src/pyclipper/_pyclipper.cpp", "src/clipper.cpp"]
|
||||||
cmdclass = {}
|
cmdclass = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,13 +48,14 @@ needs_pytest = {'pytest', 'test'}.intersection(sys.argv)
|
||||||
pytest_runner = ['pytest_runner'] if needs_pytest else []
|
pytest_runner = ['pytest_runner'] if needs_pytest else []
|
||||||
|
|
||||||
|
|
||||||
ext = Extension("pyclipper",
|
ext = Extension("pyclipper._pyclipper",
|
||||||
sources=sources,
|
sources=sources,
|
||||||
language="c++",
|
language="c++",
|
||||||
|
include_dirs=["src"],
|
||||||
# define extra macro definitions that are used by clipper
|
# define extra macro definitions that are used by clipper
|
||||||
# Available definitions that can be used with pyclipper:
|
# Available definitions that can be used with pyclipper:
|
||||||
# use_lines, use_int32
|
# use_lines, use_int32
|
||||||
# See pyclipper/clipper.hpp
|
# See src/clipper.hpp
|
||||||
# define_macros=[('use_lines', 1)]
|
# define_macros=[('use_lines', 1)]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -63,7 +64,7 @@ with open("README.rst", "r", encoding='utf-8') as readme:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pyclipper',
|
name='pyclipper',
|
||||||
use_scm_version=True,
|
use_scm_version={"write_to": "src/pyclipper/_version.py"},
|
||||||
description='Cython wrapper for the C++ translation of the Angus Johnson\'s Clipper library (ver. 6.4.2)',
|
description='Cython wrapper for the C++ translation of the Angus Johnson\'s Clipper library (ver. 6.4.2)',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
author='Angus Johnson, Maxime Chalton, Lukas Treyer, Gregor Ratajc',
|
author='Angus Johnson, Maxime Chalton, Lukas Treyer, Gregor Ratajc',
|
||||||
|
|
@ -89,6 +90,8 @@ setup(
|
||||||
"Topic :: Scientific/Engineering :: Mathematics",
|
"Topic :: Scientific/Engineering :: Mathematics",
|
||||||
"Topic :: Software Development :: Libraries :: Python Modules"
|
"Topic :: Software Development :: Libraries :: Python Modules"
|
||||||
],
|
],
|
||||||
|
package_dir={"": "src"},
|
||||||
|
packages=find_packages(where="src"),
|
||||||
ext_modules=[ext],
|
ext_modules=[ext],
|
||||||
setup_requires=[
|
setup_requires=[
|
||||||
'cython>=0.28',
|
'cython>=0.28',
|
||||||
|
|
|
||||||
6
src/pyclipper/__init__.py
Normal file
6
src/pyclipper/__init__.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from ._pyclipper import *
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ._version import version as __version__
|
||||||
|
except ImportError:
|
||||||
|
__version__ = "0.0.0+unknown"
|
||||||
Loading…
Reference in a new issue