Skip to content

Commit

Permalink
Merge pull request #218 from cleder/develop
Browse files Browse the repository at this point in the history
release 1.4.0
  • Loading branch information
cleder authored Mar 25, 2024
2 parents 789d31f + 881b457 commit c063e04
Show file tree
Hide file tree
Showing 30 changed files with 1,255 additions and 107 deletions.
58 changes: 50 additions & 8 deletions .github/workflows/run-all-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13-dev']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13-dev']

steps:
- uses: actions/checkout@v4
Expand All @@ -21,11 +21,53 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[tests]"
- name: Test with pytest
- name: Test with pytest, excluding hypothesis tests
run: >-
pytest tests
--ignore=tests/hypothesis
hypothesis-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[tests]"
- name: Test with pytest including hypothesis tests
run: >-
pytest tests
test-coverage:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pytest tests --cov=tests --cov=pygeoif --cov-report=xml
python -m pip install --upgrade pip
python -m pip install -e ".[tests]"
- name: Test with pytest including hypothesis tests and coverage
run: >-
pytest tests
--cov=tests --cov=pygeoif --cov-report=xml
--hypothesis-profile=coverage
- name: "Upload coverage to Codecov"
if: ${{ matrix.python-version==3.11 }}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
Expand Down Expand Up @@ -67,7 +109,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
pypy-version: ['pypy-3.7', 'pypy-3.8', 'pypy-3.9', 'pypy-3.10']
pypy-version: ['pypy-3.8', 'pypy-3.9', 'pypy-3.10']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.pypy-version }}
Expand All @@ -78,13 +120,13 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[tests]"
- name: Test with pytest
- name: Test with pytest, excluding hypothesis tests
run: |
pytest tests
pytest tests --ignore=tests/hypothesis
publish:
if: "github.event_name == 'push' && github.repository == 'cleder/pygeoif'"
needs: [cpython, static-tests, pypy]
needs: [cpython, static-tests, pypy, hypothesis-tests]
name: Build and publish to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage.xml
.watchmanconfig
html/
.dccache
.pytest_cache
.pytest_cache/
.pyre/
.mypy_cache/
.pytype/
Expand All @@ -24,3 +24,4 @@ venv/
__pycache__/
*.stderr*
docs/_*
.hypothesis/
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.14'
rev: 'v0.3.4'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down Expand Up @@ -68,9 +68,11 @@ repos:
- flake8-typing-imports
- flake8-use-fstring
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies:
- hypothesis
# - repo: https://github.com/Lucas-C/pre-commit-hooks-markup
# rev: v1.0.1
# hooks:
Expand All @@ -84,7 +86,7 @@ repos:
hooks:
- id: pyprojectsort
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.27.3"
rev: "0.28.0"
hooks:
- id: check-github-workflows
- id: check-github-actions
Expand Down
2 changes: 1 addition & 1 deletion .sourcery.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
refactor:
python_version: '3.7'
python_version: '3.8'
19 changes: 13 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,32 @@ out of points, polygons from linear rings, multi polygons from
polygons, etc. It was inspired by shapely and implements the
geometries in a way that when you are familiar with pygeoif,
you will feel right at home with shapely or the other way round.
It provides Hypothesis strategies for all geometries for property based
testing with Hypothesis_.

It was written to provide clean and python only geometries for fastkml_

.. image:: https://readthedocs.org/projects/pygeoif/badge/?version=latest
:target: https://pygeoif.readthedocs.io/en/latest/?badge=latest
:alt: Documentation

.. image:: https://github.com/cleder/pygeoif/actions/workflows/run-all-tests.yml/badge.svg?branch=main
:target: https://github.com/cleder/pygeoif/actions/workflows/run-all-tests.yml
:alt: GitHub Actions

.. image:: https://readthedocs.org/projects/pygeoif/badge/?version=latest
:target: https://pygeoif.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://codecov.io/gh/cleder/pygeoif/branch/main/graph/badge.svg?token=2EfiwBXs9X
:target: https://codecov.io/gh/cleder/pygeoif
:alt: Codecov

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
.. image:: https://img.shields.io/badge/property_based_tests-hypothesis-green
:target: https://hypothesis.works
:alt: Hypothesis

.. image:: https://img.shields.io/badge/code_style-black-000000.svg
:target: https://github.com/psf/
:alt: Black

.. image:: https://img.shields.io/badge/type%20checker-mypy-blue
.. image:: https://img.shields.io/badge/type_checker-mypy-blue
:target: http://mypy-lang.org/
:alt: Mypy

Expand Down Expand Up @@ -411,3 +417,4 @@ The tests were improved with mutmut_ which discovered some nasty edge cases.
.. _mutmut: https://github.com/boxed/mutmut
.. _GeoJSON: https://geojson.org/
.. _fastkml: http://pypi.python.org/pypi/fastkml/
.. _Hypothesis: https://hypothesis.works
20 changes: 15 additions & 5 deletions docs/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
Changelog
=========

1.3.0 (unreleased)
1.4.0 (2024/03/25)
------------------

- add Hypothesis tests [Ben Shaver, Christian Ledermann]
- fix ``convex_hull`` edge-cases discovered by Hypothesis tests
- fix ``from_wkt`` to include multi geometries in GeometryCollections
- drop Python 3.7 support

1.3.0 (2024/02/05)
------------------

- add Python 3.13 to supported versions
- remove ``maybe_valid`` methods
- GeoType and GeoCollectionType protocols to use a property instead of an attribute

1.2.0 (2023/11/27)
------------------

- remove Python 3.7 support
- Geometries are now immutable (but not hashable)
- add ``force_2d`` and ``force_3d`` factories [Alex Svetkin]
- Geometries are now immutable (but not hashable)
- add ``force_2d`` and ``force_3d`` factories [Alex Svetkin]

1.1.1 (2023/10/27)
------------------

- Use ``pyproject.toml``, remove ``setup.py`` and ``MANIFEST.in``
- Use ``pyproject.toml``, remove ``setup.py`` and ``MANIFEST.in``

1.1 (2023/10/13)
-----------------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

from pygeoif import about # noqa: E402
from pygeoif import about

project = "pygeoif"
copyright = "2023, Christian Ledermann" # noqa: A001
Expand Down
8 changes: 8 additions & 0 deletions docs/pygeoif.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ pygeoif.about module
:members:
:undoc-members:
:special-members: __version__

pygeoif.hypothesis.strategies module
--------------------

.. automodule:: pygeoif.hypothesis.strategies
:members:
:undoc-members:
:special-members: __version__
2 changes: 1 addition & 1 deletion pygeoif/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
The only purpose of this module is to provide a version number for the package.
"""

__version__ = "1.3.0"
__version__ = "1.4.0"
42 changes: 27 additions & 15 deletions pygeoif/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
from pygeoif.geometry import MultiPolygon
from pygeoif.geometry import Point
from pygeoif.geometry import Polygon
from pygeoif.types import Exteriors
from pygeoif.types import GeoCollectionInterface
from pygeoif.types import GeoCollectionType
from pygeoif.types import GeoInterface
from pygeoif.types import GeoType
from pygeoif.types import Interiors
from pygeoif.types import LineType
from pygeoif.types import PointType
from pygeoif.types import PolygonType
Expand All @@ -55,7 +55,9 @@
),
flags=re.I,
)
gcre: Pattern[str] = re.compile(r"POINT|LINESTRING|LINEARRING|POLYGON")
gcre: Pattern[str] = re.compile(
r"POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON",
)
outer: Pattern[str] = re.compile(r"\((.+)\)")
inner: Pattern[str] = re.compile(r"\([^)]*\)")
mpre: Pattern[str] = re.compile(r"\(\((.+?)\)\)")
Expand Down Expand Up @@ -188,27 +190,34 @@ def _point_from_wkt_coordinates(coordinates: str) -> Point:
def _line_from_wkt_coordinates(coordinates: str) -> LineString:
coords = coordinates.split(",")
return LineString(
[cast(PointType, tuple(num(c) for c in coord.split())) for coord in coords],
cast(
LineType, #
[tuple(num(c) for c in coord.split()) for coord in coords],
),
)


def _ring_from_wkt_coordinates(coordinates: str) -> LinearRing:
coords = coordinates.split(",")
return LinearRing(
[cast(PointType, tuple(num(c) for c in coord.split())) for coord in coords],
cast(
LineType,
[tuple(num(c) for c in coord.split()) for coord in coords],
),
)


def _shell_holes_from_wkt_coords(
coords: List[str],
) -> Tuple[LineType, Exteriors]:
) -> Tuple[LineType, Interiors]:
"""Extract shell and holes from polygon wkt coordinates."""
interior: LineType = [
cast(PointType, tuple(num(c) for c in coord.split())) for coord in coords[0]
]
exterior: LineType = cast(
LineType,
[tuple(num(c) for c in coord.split()) for coord in coords[0]],
)
if len(coords) > 1:
# we have a polygon with holes
exteriors = [
interiors = [
cast(
LineType,
[
Expand All @@ -219,8 +228,8 @@ def _shell_holes_from_wkt_coords(
for ext in coords[1:]
]
else:
exteriors = None
return interior, exteriors
interiors = None
return exterior, interiors


def _polygon_from_wkt_coordinates(coordinates: str) -> Polygon:
Expand All @@ -243,10 +252,13 @@ def _multipoint_from_wkt_coordinates(coordinates: str) -> MultiPoint:

def _multiline_from_wkt_coordinates(coordinates: str) -> MultiLineString:
coords = [
[
cast(PointType, tuple(num(c) for c in coord.split()))
for coord in lines.strip("()").split(",")
]
cast(
LineType,
[
tuple(num(c) for c in coord.split())
for coord in lines.strip("()").split(",")
],
)
for lines in inner.findall(coordinates)
]
return MultiLineString(coords)
Expand Down
Loading

0 comments on commit c063e04

Please sign in to comment.