From 944ccf5e89b8c19a3b48dedb1d2bdac0b35390ae Mon Sep 17 00:00:00 2001 From: Andrew Port Date: Fri, 3 Feb 2023 18:45:50 -0500 Subject: [PATCH 1/2] create new yaml for legacy system tests --- .github/workflows/github-ci-legacy.yml | 34 ++++++++++++++++++++++++++ .github/workflows/github-ci.yml | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/github-ci-legacy.yml diff --git a/.github/workflows/github-ci-legacy.yml b/.github/workflows/github-ci-legacy.yml new file mode 100644 index 0000000..899d93e --- /dev/null +++ b/.github/workflows/github-ci-legacy.yml @@ -0,0 +1,34 @@ +name: Github CI Unit Testing for Legacy Environments + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + build: + runs-on: ${{ matrix.os }} + continue-on-error: true + strategy: + matrix: + os: [ubuntu-18.04, macos-10.15, windows-2019] + python-version: [2.7, 3.5, 3.6] + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # configure python + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + # install deps + - name: Install dependencies for ${{ matrix.os }} Python ${{ matrix.python-version }} + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install scipy + + # find and run all unit tests + - name: Run unit tests + run: python -m unittest discover test diff --git a/.github/workflows/github-ci.yml b/.github/workflows/github-ci.yml index 41ccecc..0c59194 100644 --- a/.github/workflows/github-ci.yml +++ b/.github/workflows/github-ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"] + python-version: [3.7, 3.8, 3.9, "3.10", "3.11"] steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 From d9515ea39962cd044eb624fd068a82cf37d12e8c Mon Sep 17 00:00:00 2001 From: Andrew Port Date: Fri, 3 Feb 2023 19:46:23 -0500 Subject: [PATCH 2/2] remove all wildcard imports --- ...-many-points-quickly-using-numpy-arrays.py | 2 +- ...path-is-contained-in-other-path-example.py | 11 ++++++----- .../distance-between-two-svg-paths-example.py | 9 ++++++--- svgpathtools/document.py | 5 +++-- svgpathtools/svg_io_sax.py | 19 ++++++++++--------- test/test_bezier.py | 2 +- test/test_document.py | 2 +- test/test_generation.py | 2 +- test/test_groups.py | 2 +- test/test_parsing.py | 3 ++- test/test_path.py | 8 ++++++-- test/test_polytools.py | 2 +- test/test_sax_groups.py | 2 +- test/test_svg2paths.py | 2 +- 14 files changed, 41 insertions(+), 30 deletions(-) diff --git a/examples/compute-many-points-quickly-using-numpy-arrays.py b/examples/compute-many-points-quickly-using-numpy-arrays.py index 1ad48c6..afbcfa2 100644 --- a/examples/compute-many-points-quickly-using-numpy-arrays.py +++ b/examples/compute-many-points-quickly-using-numpy-arrays.py @@ -8,7 +8,7 @@ Note: The relevant matrix transformation for quadratics can be found in the svgpathtools.bezier module.""" from __future__ import print_function import numpy as np -from svgpathtools import * +from svgpathtools import bezier_point, Path, bpoints2bezier, polynomial2bezier class HigherOrderBezier: diff --git a/examples/determine-if-svg-path-is-contained-in-other-path-example.py b/examples/determine-if-svg-path-is-contained-in-other-path-example.py index 2a01632..061d2ae 100755 --- a/examples/determine-if-svg-path-is-contained-in-other-path-example.py +++ b/examples/determine-if-svg-path-is-contained-in-other-path-example.py @@ -7,7 +7,8 @@ Path.continuous_subpaths() method to split a paths into a list of its continuous subpaths. """ -from svgpathtools import * +from svgpathtools import Path, Line + def path1_is_contained_in_path2(path1, path2): assert path2.isclosed() # This question isn't well-defined otherwise @@ -16,11 +17,11 @@ def path1_is_contained_in_path2(path1, path2): # find a point that's definitely outside path2 xmin, xmax, ymin, ymax = path2.bbox() - B = (xmin + 1) + 1j*(ymax + 1) + b = (xmin + 1) + 1j*(ymax + 1) - A = path1.start # pick an arbitrary point in path1 - AB_line = Path(Line(A, B)) - number_of_intersections = len(AB_line.intersect(path2)) + a = path1.start # pick an arbitrary point in path1 + ab_line = Path(Line(a, b)) + number_of_intersections = len(ab_line.intersect(path2)) if number_of_intersections % 2: # if number of intersections is odd return True else: diff --git a/examples/distance-between-two-svg-paths-example.py b/examples/distance-between-two-svg-paths-example.py index 57e2749..742cea4 100755 --- a/examples/distance-between-two-svg-paths-example.py +++ b/examples/distance-between-two-svg-paths-example.py @@ -1,13 +1,16 @@ -from svgpathtools import * +from svgpathtools import disvg, Line, CubicBezier +from scipy.optimize import fminbound # create some example paths path1 = CubicBezier(1,2+3j,3-5j,4+1j) path2 = path1.rotated(60).translated(3) -# find minimizer -from scipy.optimize import fminbound + def dist(t): return path1.radialrange(path2.point(t))[0][0] + + +# find minimizer T2 = fminbound(dist, 0, 1) # Let's do a visual check diff --git a/svgpathtools/document.py b/svgpathtools/document.py index c3fcdd1..d9f477a 100644 --- a/svgpathtools/document.py +++ b/svgpathtools/document.py @@ -13,7 +13,7 @@ An Historic Note: Example: Typical usage looks something like the following. - >> from svgpathtools import * + >> from svgpathtools import Document >> doc = Document('my_file.html') >> for path in doc.paths(): >> # Do something with the transformed Path object. @@ -44,6 +44,7 @@ import warnings from io import StringIO from tempfile import gettempdir from time import time +import numpy as np # Internal dependencies from .parser import parse_path @@ -51,7 +52,7 @@ from .parser import parse_transform from .svg_to_paths import (path2pathd, ellipse2pathd, line2pathd, polyline2pathd, polygon2pathd, rect2pathd) from .misctools import open_in_browser -from .path import * +from .path import transform, Path, is_path_segment # To maintain forward/backward compatibility try: diff --git a/svgpathtools/svg_io_sax.py b/svgpathtools/svg_io_sax.py index 413ce69..7faced1 100644 --- a/svgpathtools/svg_io_sax.py +++ b/svgpathtools/svg_io_sax.py @@ -6,6 +6,7 @@ from __future__ import division, absolute_import, print_function import os from xml.etree.ElementTree import iterparse, Element, ElementTree, SubElement +import numpy as np # Internal dependencies from .parser import parse_path @@ -13,13 +14,13 @@ from .parser import parse_transform from .svg_to_paths import (path2pathd, ellipse2pathd, line2pathd, polyline2pathd, polygon2pathd, rect2pathd) from .misctools import open_in_browser -from .path import * +from .path import transform # To maintain forward/backward compatibility try: - str = basestring + string = basestring except NameError: - pass + string = str NAME_SVG = "svg" ATTR_VERSION = "version" @@ -164,17 +165,17 @@ class SaxDocument: if matrix is not None and not np.all(np.equal(matrix, identity)): matrix_string = "matrix(" matrix_string += " " - matrix_string += str(matrix[0][0]) + matrix_string += string(matrix[0][0]) matrix_string += " " - matrix_string += str(matrix[1][0]) + matrix_string += string(matrix[1][0]) matrix_string += " " - matrix_string += str(matrix[0][1]) + matrix_string += string(matrix[0][1]) matrix_string += " " - matrix_string += str(matrix[1][1]) + matrix_string += string(matrix[1][1]) matrix_string += " " - matrix_string += str(matrix[0][2]) + matrix_string += string(matrix[0][2]) matrix_string += " " - matrix_string += str(matrix[1][2]) + matrix_string += string(matrix[1][2]) matrix_string += ")" path.set(ATTR_TRANSFORM, matrix_string) if ATTR_DATA in values: diff --git a/test/test_bezier.py b/test/test_bezier.py index 4c82e93..0e61370 100644 --- a/test/test_bezier.py +++ b/test/test_bezier.py @@ -1,7 +1,7 @@ from __future__ import division, absolute_import, print_function import numpy as np import unittest -from svgpathtools.bezier import * +from svgpathtools.bezier import bezier_point, bezier2polynomial, polynomial2bezier from svgpathtools.path import bpoints2bezier diff --git a/test/test_document.py b/test/test_document.py index 6642a49..a9cd74a 100644 --- a/test/test_document.py +++ b/test/test_document.py @@ -1,6 +1,6 @@ from __future__ import division, absolute_import, print_function import unittest -from svgpathtools import * +from svgpathtools import Document from io import StringIO from io import open # overrides build-in open for compatibility with python2 from os.path import join, dirname diff --git a/test/test_generation.py b/test/test_generation.py index f587c47..4d729d1 100644 --- a/test/test_generation.py +++ b/test/test_generation.py @@ -2,7 +2,7 @@ #------------------------------------------------------------------------------ from __future__ import division, absolute_import, print_function import unittest -from svgpathtools import * +from svgpathtools import parse_path class TestGeneration(unittest.TestCase): diff --git a/test/test_groups.py b/test/test_groups.py index aeb3393..7544433 100644 --- a/test/test_groups.py +++ b/test/test_groups.py @@ -5,7 +5,7 @@ $ python -m unittest test.test_groups.TestGroups.test_group_flatten """ from __future__ import division, absolute_import, print_function import unittest -from svgpathtools import * +from svgpathtools import Document, SVG_NAMESPACE, parse_path from os.path import join, dirname import numpy as np diff --git a/test/test_parsing.py b/test/test_parsing.py index 1c93064..cf33b1f 100644 --- a/test/test_parsing.py +++ b/test/test_parsing.py @@ -1,8 +1,9 @@ # Note: This file was taken mostly as is from the svg.path module (v 2.0) from __future__ import division, absolute_import, print_function import unittest -from svgpathtools import * +from svgpathtools import Path, Line, QuadraticBezier, CubicBezier, Arc, parse_path import svgpathtools + import numpy as np diff --git a/test/test_path.py b/test/test_path.py index db77dc9..6a19d10 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -10,8 +10,12 @@ import random import warnings # Internal dependencies -from svgpathtools import * -from svgpathtools.path import _NotImplemented4ArcException, bezier_radialrange +from svgpathtools import ( + Line, QuadraticBezier, CubicBezier, Arc, Path, poly2bez, path_encloses_pt, + bpoints2bezier, closest_point_in_path, farthest_point_in_path, + is_bezier_segment, is_bezier_path, parse_path +) +from svgpathtools.path import bezier_radialrange # An important note for those doing any debugging: # ------------------------------------------------ diff --git a/test/test_polytools.py b/test/test_polytools.py index 45f1685..45e8fd3 100644 --- a/test/test_polytools.py +++ b/test/test_polytools.py @@ -4,7 +4,7 @@ import unittest import numpy as np # Internal dependencies -from svgpathtools import * +from svgpathtools import rational_limit class Test_polytools(unittest.TestCase): diff --git a/test/test_sax_groups.py b/test/test_sax_groups.py index cbfb587..5e17aa3 100644 --- a/test/test_sax_groups.py +++ b/test/test_sax_groups.py @@ -1,6 +1,6 @@ from __future__ import division, absolute_import, print_function import unittest -from svgpathtools import * +from svgpathtools import SaxDocument from os.path import join, dirname diff --git a/test/test_svg2paths.py b/test/test_svg2paths.py index 31058ca..fe2507a 100644 --- a/test/test_svg2paths.py +++ b/test/test_svg2paths.py @@ -1,6 +1,6 @@ from __future__ import division, absolute_import, print_function import unittest -from svgpathtools import * +from svgpathtools import Path, Line, Arc, svg2paths, svgstr2paths from io import StringIO from io import open # overrides build-in open for compatibility with python2 from os.path import join, dirname