Skip to content

Commit

Permalink
Merge pull request #40 from fonttools/export-version-string
Browse files Browse the repository at this point in the history
export pyclipper.__version__ as conventional in python packaging
  • Loading branch information
anthrotype authored Jun 25, 2021
2 parents 3de54fa + 19fcc36 commit 5e10a2e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 84 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ build
dist
pyclipper.egg-info
*.so
pyclipper/pyclipper.cpp
src/pyclipper/_pyclipper.cpp
src/pyclipper/_version.py
*.pyc
MANIFEST
.eggs/
.eggs/
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Here we only need to include those which are not tracked by git but we do
# 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
exclude dev
Expand Down
15 changes: 9 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function
import sys
import os
from setuptools import setup
from setuptools import setup, find_packages
from setuptools.extension import Extension
from io import open

Expand All @@ -23,7 +23,7 @@
from Cython.Distutils import build_ext

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

Expand All @@ -40,21 +40,22 @@ def run(self):

else:
print('Distribution mode: Compiling Cython generated .cpp sources.')
sources = ["pyclipper/pyclipper.cpp", "pyclipper/clipper.cpp"]
sources = ["src/pyclipper/_pyclipper.cpp", "src/clipper.cpp"]
cmdclass = {}


needs_pytest = {'pytest', 'test'}.intersection(sys.argv)
pytest_runner = ['pytest_runner'] if needs_pytest else []


ext = Extension("pyclipper",
ext = Extension("pyclipper._pyclipper",
sources=sources,
language="c++",
include_dirs=["src"],
# define extra macro definitions that are used by clipper
# Available definitions that can be used with pyclipper:
# use_lines, use_int32
# See pyclipper/clipper.hpp
# See src/clipper.hpp
# define_macros=[('use_lines', 1)]
)

Expand All @@ -63,7 +64,7 @@ def run(self):

setup(
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)',
long_description=long_description,
author='Angus Johnson, Maxime Chalton, Lukas Treyer, Gregor Ratajc',
Expand All @@ -89,6 +90,8 @@ def run(self):
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Software Development :: Libraries :: Python Modules"
],
package_dir={"": "src"},
packages=find_packages(where="src"),
ext_modules=[ext],
setup_requires=[
'cython>=0.28',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/pyclipper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from ._pyclipper import *

try:
from ._version import version as __version__
except ImportError:
__version__ = "0.0.0+unknown"
26 changes: 0 additions & 26 deletions pyclipper/pyclipper.pyx → src/pyclipper/_pyclipper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ This wrapper was written by Maxime Chalton, Lukas Treyer and Gregor Ratajc.

SILENT = True

"""
SCALING_FACTOR has been deprecated. See https://github.com/greginvm/pyclipper/wiki/Deprecating-SCALING_FACTOR
for an explanation.
"""
SCALING_FACTOR = 1


def log_action(description):
if not SILENT:
Expand Down Expand Up @@ -670,8 +664,6 @@ cdef class Pyclipper:
Returns:
PyIntRect with left, right, bottom, top vertices that define the axis-aligned bounding rectangle.
"""
_check_scaling_factor()

cdef IntRect rr
with nogil:
rr = <IntRect> self.thisptr.GetBounds()
Expand Down Expand Up @@ -860,13 +852,9 @@ cdef class PyclipperOffset:
More info: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/ClipperOffset/Properties/ArcTolerance.htm
"""
def __get__(self):
_check_scaling_factor()

return self.thisptr.ArcTolerance

def __set__(self, value):
_check_scaling_factor()

self.thisptr.ArcTolerance = value


Expand Down Expand Up @@ -926,8 +914,6 @@ cdef Paths _to_clipper_paths(object polygons):


cdef Path _to_clipper_path(object polygon):
_check_scaling_factor()

cdef Path path = Path()
cdef IntPoint p
for v in polygon:
Expand All @@ -952,21 +938,9 @@ cdef object _from_clipper_paths(Paths paths):


cdef object _from_clipper_path(Path path):
_check_scaling_factor()

poly = []
cdef IntPoint point
for i in xrange(path.size()):
point = path[i]
poly.append([point.X, point.Y])
return poly


def _check_scaling_factor():
"""
Check whether SCALING_FACTOR has been set by the code using this library and warn the user that it has been
deprecated and it's value is ignored.
"""

if SCALING_FACTOR != 1:
_warnings.warn('SCALING_FACTOR is deprecated and it\'s value is ignored. See https://github.com/greginvm/pyclipper/wiki/Deprecating-SCALING_FACTOR for more information.', DeprecationWarning)
58 changes: 9 additions & 49 deletions tests/test_pyclipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def test_has_namespace_methods(self):


class TestNamespaceMethods(TestCase):
def setUp(self):
pyclipper.SCALING_FACTOR = 1

def test_orientation(self):
self.assertFalse(pyclipper.Orientation(PATH_SUBJ_1))
Expand Down Expand Up @@ -166,7 +164,6 @@ def check_paths(self, paths, expected_nr):

class TestPyclipperAddPaths(TestCase):
def setUp(self):
pyclipper.SCALING_FACTOR = 1
self.pc = pyclipper.Pyclipper()

def test_add_path(self):
Expand Down Expand Up @@ -202,16 +199,13 @@ def test_pyclipper_properties(self):
self.check_property_assignment(pc, prop_name, [True, False])

def test_pyclipperoffset_properties(self):
for factor in range(6):
pyclipper.SCALING_FACTOR = 10 ** factor
pc = pyclipper.PyclipperOffset()
for prop_name in ('MiterLimit', 'ArcTolerance'):
self.check_property_assignment(pc, prop_name, [2.912, 132.12, 12, -123])
pc = pyclipper.PyclipperOffset()
for prop_name in ('MiterLimit', 'ArcTolerance'):
self.check_property_assignment(pc, prop_name, [2.912, 132.12, 12, -123])


class TestPyclipperExecute(TestCase):
def setUp(self):
pyclipper.SCALING_FACTOR = 1
self.pc = pyclipper.Pyclipper()
self.add_default_paths(self.pc)
self.default_args = [pyclipper.CT_INTERSECTION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD]
Expand Down Expand Up @@ -285,8 +279,6 @@ def check_pypolynode(self, node):


class TestPyclipperOffset(TestCase):
def setUp(self):
pyclipper.SCALING_FACTOR = 1

@staticmethod
def add_path(pc, path):
Expand Down Expand Up @@ -316,44 +308,6 @@ def test_clear(self):
self.assertEqual(len(solution), 0)


class TestScalingFactorWarning(TestCase):
def setUp(self):
pyclipper.SCALING_FACTOR = 2.
self.pc = pyclipper.Pyclipper()

def test_orientation(self):
with self.assertWarns(DeprecationWarning):
pyclipper.Orientation(PATH_SUBJ_1)

def test_area(self):
with self.assertWarns(DeprecationWarning):
pyclipper.Area(PATH_SUBJ_1)

def test_point_in_polygon(self):
with self.assertWarns(DeprecationWarning):
self.assertEqual(pyclipper.PointInPolygon((180, 200), PATH_SUBJ_1), -1)

def test_minkowski_sum(self):
with self.assertWarns(DeprecationWarning):
pyclipper.MinkowskiSum(PATTERN, PATH_SIGMA, False)

def test_minkowski_sum2(self):
with self.assertWarns(DeprecationWarning):
pyclipper.MinkowskiSum2(PATTERN, [PATH_SIGMA], False)

def test_minkowski_diff(self):
with self.assertWarns(DeprecationWarning):
pyclipper.MinkowskiDiff(PATH_SUBJ_1, PATH_SUBJ_2)

def test_add_path(self):
with self.assertWarns(DeprecationWarning):
self.pc.AddPath(PATH_CLIP_1, poly_type=pyclipper.PT_CLIP)

def test_add_paths(self):
with self.assertWarns(DeprecationWarning):
self.pc.AddPaths([PATH_SUBJ_1, PATH_SUBJ_2], poly_type=pyclipper.PT_SUBJECT)


class TestScalingFunctions(TestCase):
scale = 2 ** 31
path = [(0, 0), (1, 1)]
Expand Down Expand Up @@ -421,6 +375,12 @@ def test_sympyzero(self):
assert path == [[0, 0], [0, 2147483648]]


class TestPackageVersion(TestCase):
def test__version__(self):
assert hasattr(pyclipper, "__version__")
assert isinstance(pyclipper.__version__, str)


def _do_solutions_match(paths_1, paths_2, factor=None):
if len(paths_1) != len(paths_2):
return False
Expand Down

0 comments on commit 5e10a2e

Please sign in to comment.