[Git][debian-gis-team/python-geojson][upstream] New upstream version 3.0.0

Bas Couwenberg (@sebastic) gitlab at salsa.debian.org
Thu Jan 26 06:37:19 GMT 2023



Bas Couwenberg pushed to branch upstream at Debian GIS Project / python-geojson


Commits:
ca487759 by Bas Couwenberg at 2023-01-26T07:17:54+01:00
New upstream version 3.0.0
- - - - -


27 changed files:

- + .github/workflows/release.yml
- + .github/workflows/test.yml
- + .pre-commit-config.yaml
- − .travis.yml
- CHANGELOG.rst
- + CODE_OF_CONDUCT.md
- + CONTRIBUTING.rst
- LICENSE.rst
- README.rst
- + docs/index.rst
- geojson/_version.py
- geojson/base.py
- geojson/codec.py
- geojson/examples.py
- geojson/feature.py
- geojson/geometry.py
- geojson/mapping.py
- geojson/utils.py
- setup.py
- tests/test_base.py
- tests/test_constructor.py
- tests/test_coords.py
- tests/test_features.py
- tests/test_geo_interface.py
- + tests/test_utils.py
- tests/test_validation.py
- tox.ini


Changes:

=====================================
.github/workflows/release.yml
=====================================
@@ -0,0 +1,53 @@
+name: Release
+
+on:
+  push:
+    tags:
+    - '*'
+
+jobs:
+  build:
+    if: github.repository == 'jazzband/geojson'
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout at v2
+        with:
+          fetch-depth: 0
+
+      - name: Set up Python
+        uses: actions/setup-python at v2
+        with:
+          python-version: '3.8'
+
+      - name: Get pip cache dir
+        id: pip-cache
+        run: |
+          echo "::set-output name=dir::$(pip cache dir)"
+
+      - name: Cache
+        uses: actions/cache at v2
+        with:
+          path: ${{ steps.pip-cache.outputs.dir }}
+          key: release-${{ hashFiles('**/setup.py') }}
+          restore-keys: |
+            release-
+
+      - name: Install dependencies
+        run: |
+          python -m pip install -U pip
+          python -m pip install -U setuptools twine wheel
+
+      - name: Build package
+        run: |
+          python setup.py --version
+          python setup.py sdist --format=gztar bdist_wheel
+          twine check dist/*
+
+      - name: Upload packages to Jazzband
+        if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
+        uses: pypa/gh-action-pypi-publish at master
+        with:
+          user: jazzband
+          password: ${{ secrets.JAZZBAND_RELEASE_KEY }}
+          repository_url: https://jazzband.co/projects/geojson/upload


=====================================
.github/workflows/test.yml
=====================================
@@ -0,0 +1,48 @@
+name: Test
+
+on: [push, pull_request]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      max-parallel: 6
+      matrix:
+        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.8']
+
+    steps:
+    - uses: actions/checkout at v2
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python at v2
+      with:
+        python-version: ${{ matrix.python-version }}
+
+    - name: Get pip cache dir
+      id: pip-cache
+      run: |
+        echo "::set-output name=dir::$(pip cache dir)"
+
+    - name: Cache
+      uses: actions/cache at v2
+      with:
+        path: ${{ steps.pip-cache.outputs.dir }}
+        key:
+          ${{ matrix.os }}-${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}
+        restore-keys: |
+          ${{ matrix.os }}-${{ matrix.python-version }}-v1-
+
+    - name: Install dependencies
+      run: |
+        python -m pip install --upgrade pip
+        python -m pip install --upgrade codecov
+
+    - name: Tests
+      run: |
+        coverage run --branch --source=geojson setup.py test
+        coverage xml
+
+    - name: Upload coverage
+      uses: codecov/codecov-action at v1
+      with:
+        name: Python ${{ matrix.python-version }}


=====================================
.pre-commit-config.yaml
=====================================
@@ -0,0 +1,9 @@
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v4.4.0
+    hooks:
+      - id: check-merge-conflict
+      - id: check-yaml
+
+ci:
+  autoupdate_schedule: quarterly


=====================================
.travis.yml deleted
=====================================
@@ -1,42 +0,0 @@
-language: python
-dist: xenial
-python:
-- 2.7
-- 3.5
-- 3.6
-- 3.7
-- pypy2.7-6.0
-- pypy3.5-6.0
-install:
-- pip install codecov
-script:
-- coverage run --branch --source=geojson setup.py test
-- coverage xml
-after_success:
-- codecov
-stages:
-- lint
-- test
-- deploy
-jobs:
-  include:
-  - stage: lint
-    env: TOXENV=flake8
-    python: 3.7
-    install: pip install flake8
-    script: flake8 .
-  - stage: deploy
-    env:
-    python: 3.7
-    install: skip
-    script: skip
-    deploy:
-      provider: pypi
-      server: https://jazzband.co/projects/python-geojson/upload
-      distributions: sdist bdist_wheel
-      user: jazzband
-      password:
-         secure: V2dsQfSMdChZ+G9w4cBcoa/Gmo/kJf2BMaN3sb7pDcAkTHuPYHppfSfj3vWDfpZFNobg8kTed4xjeYdKJ/oxFMpSGBWhGGpzQauzXO8n6LFXM44r/b5uXzyOyzdwwnjWXBn3NkubNU/n3dSjnRr9ZTeXGjiOGTPW1wAWjARJvgg=
-      on:
-        tags: true
-        repo: jazzband/python-geojson


=====================================
CHANGELOG.rst
=====================================
@@ -1,25 +1,61 @@
 Changes
 =======
 
+3.0.0 (2022-01-26)
+------------------
+
+- Support for Python versions 3.7-3.11 (Python 2 no longer supported)
+
+- Primary development branch renamed from `master` to `main`
+
+- Handle all real numbers as coordinates
+
+  - https://github.com/jazzband/geojson/pull/188
+
+- Default precision improvements
+
+  - https://github.com/jazzband/geojson/pull/177
+
+- CI improvements
+
+  - https://github.com/jazzband/geojson/pull/172
+  - https://github.com/jazzband/geojson/pull/155
+
+- utf-8 support added to `geojson.dumps()`
+
+  - https://github.com/jazzband/geojson/pull/165
+
+- Polygons now constrained to bounding box
+
+  - https://github.com/jazzband/geojson/pull/147
+
+- Better GeometryCollection handling in `util.coords()`
+
+  - https://github.com/jazzband/geojson/pull/146
+
+- Improved point validation
+
+  - https://github.com/jazzband/geojson/pull/144
+
 2.5.0 (2019-07-18)
 ------------------
 
 - Add "precision" parameter to GeoJSON Object classes with default precision of 6 (0.1m)
 
-  - https://github.com/jazzband/python-geojson/pull/131
+  - https://github.com/jazzband/geojson/pull/131
 
 - Fix bug where `map_geometries()` util was not preserving Feature IDs
 
-  - https://github.com/jazzband/python-geojson/pull/128
-  - https://github.com/jazzband/python-geojson/pull/130
+  - https://github.com/jazzband/geojson/pull/128
+  - https://github.com/jazzband/geojson/pull/130
 
 - Remove `crs` module and features to conform to official WGS84-only GeoJSON spec
 
-  - https://github.com/jazzband/python-geojson/pull/124
+  - https://github.com/jazzband/geojson/pull/124
 
 - Set up semi-automatic PyPi releases via Travis/Jazzband
 
-  - https://github.com/jazzband/python-geojson/pull/123
+  - https://github.com/jazzband/geojson/pull/123
 
 2.4.2 (2019-03-12)
 ------------------
@@ -27,28 +63,28 @@ Changes
 - Tie Travis CI to jazzband instance
 - Remove EOL 3.3 and 3.4 version support
 
-  - https://github.com/jazzband/python-geojson/pull/120
+  - https://github.com/jazzband/geojson/pull/120
 
 2.4.1 (2018-10-17)
 ------------------
 
 - Allow ``FeatureCollections`` to be passed to ``coords``
 
-  - https://github.com/frewsxcv/python-geojson/pull/117
+  - https://github.com/jazzband/geojson/pull/117
 
 2.4.0 (2018-05-21)
 ------------------
 
 - Additional functional maps for GeoJSON entities
 
-  - https://github.com/frewsxcv/python-geojson/pull/112
+  - https://github.com/jazzband/geojson/pull/112
 
 2.3.0 (2017-09-18)
 ------------------
 
 - Add ``__getitem__`` methods to sequence-like objects
 
-  - https://github.com/frewsxcv/python-geojson/pull/103
+  - https://github.com/jazzband/geojson/pull/103
 
 
 2.2.0 (2017-09-17)
@@ -56,70 +92,70 @@ Changes
 
 - Allow constructing geojson objects from geojson objects
 
-  - https://github.com/frewsxcv/python-geojson/pull/104
+  - https://github.com/jazzband/geojson/pull/104
 
 2.1.0 (2017-08-29)
 ------------------
 
 - Implement validation for GeometryCollection
 
-  - https://github.com/frewsxcv/python-geojson/pull/102
+  - https://github.com/jazzband/geojson/pull/102
 
 2.0.0 (2017-07-28)
 ------------------
 
 - Rewrite of validation mechanism (breaking change).
 
-  - https://github.com/frewsxcv/python-geojson/pull/98
+  - https://github.com/jazzband/geojson/pull/98
 
 1.3.5 (2017-04-24)
 ------------------
 
 - Changed the validator to allow elevation
 
-  - https://github.com/frewsxcv/python-geojson/pull/92
+  - https://github.com/jazzband/geojson/pull/92
 
 1.3.4 (2017-02-11)
 ------------------
 
 - Remove runtime dependency on setuptools
 
-  - https://github.com/frewsxcv/python-geojson/pull/90
+  - https://github.com/jazzband/geojson/pull/90
 
 1.3.3 (2016-07-21)
 ------------------
 
 - Add validate parameter to GeoJSON constructors
 
-  - https://github.com/frewsxcv/python-geojson/pull/78
+  - https://github.com/jazzband/geojson/pull/78
 
 1.3.2 (2016-01-28)
 ------------------
 
 - Add __version__ and __version_info__ attributes
 
-  - https://github.com/frewsxcv/python-geojson/pull/74
+  - https://github.com/jazzband/geojson/pull/74
 
 1.3.1 (2015-10-12)
 ------------------
 
 - Fix validation bug for MultiPolygons
 
-  - https://github.com/frewsxcv/python-geojson/pull/63
+  - https://github.com/jazzband/geojson/pull/63
 
 1.3.0 (2015-08-11)
 ------------------
 
 - Add utility to generate geometries with random data
 
-  - https://github.com/frewsxcv/python-geojson/pull/60
+  - https://github.com/jazzband/geojson/pull/60
 
 1.2.2 (2015-07-13)
 ------------------
 
 - Fix tests by including test file into build
 
-  - https://github.com/frewsxcv/python-geojson/issues/61
+  - https://github.com/jazzband/geojson/issues/61
 
 - Build universal wheels
 
@@ -130,21 +166,21 @@ Changes
 
 - Encode long types correctly with Python 2.x
 
-  - https://github.com/frewsxcv/python-geojson/pull/57
+  - https://github.com/jazzband/geojson/pull/57
 
 1.2.0 (2015-06-19)
 ------------------
 
 - Utility function to validate GeoJSON objects
 
-  - https://github.com/frewsxcv/python-geojson/pull/56
+  - https://github.com/jazzband/geojson/pull/56
 
 1.1.0 (2015-06-08)
 ------------------
 
 - Stop outputting invalid GeoJSON value id=null on Features
 
-  - https://github.com/frewsxcv/python-geojson/pull/53
+  - https://github.com/jazzband/geojson/pull/53
 
 1.0.9 (2014-10-05)
 ------------------


=====================================
CODE_OF_CONDUCT.md
=====================================
@@ -0,0 +1,46 @@
+# Code of Conduct
+
+As contributors and maintainers of the Jazzband projects, and in the interest of
+fostering an open and welcoming community, we pledge to respect all people who
+contribute through reporting issues, posting feature requests, updating documentation,
+submitting pull requests or patches, and other activities.
+
+We are committed to making participation in the Jazzband a harassment-free experience
+for everyone, regardless of the level of experience, gender, gender identity and
+expression, sexual orientation, disability, personal appearance, body size, race,
+ethnicity, age, religion, or nationality.
+
+Examples of unacceptable behavior by participants include:
+
+- The use of sexualized language or imagery
+- Personal attacks
+- Trolling or insulting/derogatory comments
+- Public or private harassment
+- Publishing other's private information, such as physical or electronic addresses,
+  without explicit permission
+- Other unethical or unprofessional conduct
+
+The Jazzband roadies have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are not
+aligned to this Code of Conduct, or to ban temporarily or permanently any contributor
+for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+By adopting this Code of Conduct, the roadies commit themselves to fairly and
+consistently applying these principles to every aspect of managing the jazzband
+projects. Roadies who do not follow or enforce the Code of Conduct may be permanently
+removed from the Jazzband roadies.
+
+This code of conduct applies both within project spaces and in public spaces when an
+individual is representing the project or its community.
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
+contacting the roadies at `roadies at jazzband.co`. All complaints will be reviewed and
+investigated and will result in a response that is deemed necessary and appropriate to
+the circumstances. Roadies are obligated to maintain confidentiality with regard to the
+reporter of an incident.
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version
+1.3.0, available at [https://contributor-covenant.org/version/1/3/0/][version]
+
+[homepage]: https://contributor-covenant.org
+[version]: https://contributor-covenant.org/version/1/3/0/


=====================================
CONTRIBUTING.rst
=====================================
@@ -0,0 +1,5 @@
+.. image:: https://jazzband.co/static/img/jazzband.svg
+   :target: https://jazzband.co/
+   :alt: Jazzband
+
+This is a `Jazzband <https://jazzband.co>`_ project. By contributing you agree to abide by the `Contributor Code of Conduct <https://jazzband.co/about/conduct>`_ and follow the `guidelines <https://jazzband.co/about/guidelines>`_.


=====================================
LICENSE.rst
=====================================
@@ -1,4 +1,4 @@
-Copyright © 2014, contributors of python-geojson
+Copyright © 2007-2019, contributors of geojson
 
 All rights reserved.
 
@@ -6,6 +6,6 @@ Redistribution and use in source and binary forms, with or without modification,
 
 -  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 -  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
--  Neither the name of the python-geojson nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+-  Neither the name of the geojson nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS OF PYTHON-GEOJSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS OF GEOJSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


=====================================
README.rst
=====================================
@@ -1,12 +1,17 @@
-python-geojson
+geojson
 ==============
 
-.. image:: https://img.shields.io/travis/jazzband/python-geojson.svg
-   :target: https://travis-ci.org/jazzband/python-geojson
-.. image:: https://img.shields.io/codecov/c/github/jazzband/python-geojson.svg
-   :target: https://codecov.io/github/jazzband/python-geojson?branch=master
+.. image:: https://github.com/jazzband/geojson/actions/workflows/test.yml/badge.svg
+   :target: https://github.com/jazzband/geojson/actions/workflows/test.yml
+   :alt: GitHub Actions
+.. image:: https://img.shields.io/codecov/c/github/jazzband/geojson.svg
+   :target: https://codecov.io/github/jazzband/geojson?branch=main
+   :alt: Codecov
+.. image:: https://jazzband.co/static/img/badge.svg
+   :target: https://jazzband.co/
+   :alt: Jazzband
 
-This library contains:
+This Python library contains:
 
 - Functions for encoding and decoding GeoJSON_ formatted data
 - Classes for all GeoJSON Objects
@@ -21,14 +26,14 @@ This library contains:
 Installation
 ------------
 
-python-geojson is compatible with Python 2.7, 3.5, 3.6 and 3.7. It is listed on `PyPi as 'geojson'`_. The recommended way to install is via pip_:
+geojson is compatible with Python 3.7 - 3.11. The recommended way to install is via pip_:
 
 .. code::
 
   pip install geojson
 
 .. _PyPi as 'geojson': https://pypi.python.org/pypi/geojson/
-.. _pip: http://www.pip-installer.org
+.. _pip: https://www.pip-installer.org
 
 GeoJSON Objects
 ---------------
@@ -113,15 +118,15 @@ Polygon
   >>> from geojson import Polygon
 
   >>> # no hole within polygon
-  >>> Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]])  # doctest: +ELLIPSIS
-  {"coordinates": [[[2.3..., 57.32...], [23.19..., -20.2...], [-120.4..., 19.1...]]], "type": "Polygon"}
+  >>> Polygon([[(2.38, 57.322), (-120.43, 19.15), (23.194, -20.28), (2.38, 57.322)]])  # doctest: +ELLIPSIS
+  {"coordinates": [[[2.3..., 57.32...], [-120.4..., 19.1...], [23.19..., -20.2...]]], "type": "Polygon"}
 
   >>> # hole within polygon
   >>> Polygon([
-  ...     [(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)],
+  ...     [(2.38, 57.322), (-120.43, 19.15), (23.194, -20.28), (2.38, 57.322)],
   ...     [(-5.21, 23.51), (15.21, -10.81), (-20.51, 1.51), (-5.21, 23.51)]
   ... ])  # doctest: +ELLIPSIS
-  {"coordinates": [[[2.3..., 57.32...], [23.19..., -20.2...], [-120.4..., 19.1...]], [[-5.2..., 23.5...], [15.2..., -10.8...], [-20.5..., 1.5...], [-5.2..., 23.5...]]], "type": "Polygon"}
+  {"coordinates": [[[2.3..., 57.32...], [-120.4..., 19.1...], [23.19..., -20.2...]], [[-5.2..., 23.5...], [15.2..., -10.8...], [-20.5..., 1.5...], [-5.2..., 23.5...]]], "type": "Polygon"}
 
 Visualize the results of the example above `here <https://gist.github.com/frewsxcv/b2f5c31c10e399a63679>`__. General information about Polygon can be found in `Section 3.1.6`_ and `Appendix A: Polygons`_ within `The GeoJSON Format Specification`_.
 
@@ -267,7 +272,7 @@ This encoding/decoding functionality shown in the previous can be extended to cu
   '{"coordinates": [52.23..., -19.23...], "type": "Point"}'
 
 Default and custom precision
-~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 GeoJSON Object-based classes in this package have an additional `precision` attribute which rounds off
 coordinates to 6 decimal places (roughly 0.1 meters) by default and can be customized per object instance.
@@ -282,6 +287,25 @@ coordinates to 6 decimal places (roughly 0.1 meters) by default and can be custo
   >>> Point((-115.12341234, 37.12341234), precision=8)  # rounded to 8 decimal places
   {"coordinates": [-115.12341234, 37.12341234], "type": "Point"}
 
+
+Precision can be set at the package level by setting `geojson.geometry.DEFAULT_PRECISION` 
+
+
+.. code:: python
+
+  >>> import geojson
+
+  >>> geojson.geometry.DEFAULT_PRECISION = 5
+
+  >>> from geojson import Point
+
+  >>> Point((-115.12341234, 37.12341234))  # rounded to 8 decimal places
+  {"coordinates": [-115.12341, 37.12341], "type": "Point"}
+
+
+After setting the DEFAULT_PRECISION, coordinates will be rounded off to that precision with `geojson.load` or `geojson.loads`. Following one of those with `geojson.dump` is a quick and easy way to scale down the precision of excessively precise, arbitrarily-sized GeoJSON data.
+
+
 Helpful utilities
 -----------------
 
@@ -330,7 +354,7 @@ map_tuples
   '{"coordinates": [37.24..., -115.81], "type": "Point"}'
 
 map_geometries
-~~~~~~~~~~
+~~~~~~~~~~~~~~
 
 :code:`geojson.utils.map_geometries` maps a function over each geometry in the input.
 
@@ -401,6 +425,6 @@ Credits
 * Ray Riga <ray at strongoutput.com>
 
 
-.. _GeoJSON: http://geojson.org/
+.. _GeoJSON: https://geojson.org/
 .. _The GeoJSON Format Specification: https://tools.ietf.org/html/rfc7946
 .. _\_\_geo\_interface\_\_ Specification: https://gist.github.com/sgillies/2217756


=====================================
docs/index.rst
=====================================
@@ -0,0 +1 @@
+.. include:: ../README.rst


=====================================
geojson/_version.py
=====================================
@@ -1,2 +1,2 @@
-__version__ = "2.5.0"
+__version__ = "3.0.0"
 __version_info__ = tuple(map(int, __version__.split(".")))


=====================================
geojson/base.py
=====================================
@@ -1,5 +1,3 @@
-from __future__ import unicode_literals
-
 import geojson
 from geojson.mapping import to_mapping
 
@@ -19,7 +17,7 @@ class GeoJSON(dict):
         :return: a GeoJSON object
         :rtype: GeoJSON
         """
-        super(GeoJSON, self).__init__(iterable)
+        super().__init__(iterable)
         self["type"] = getattr(self, "type", type(self).__name__)
         self.update(extra)
 


=====================================
geojson/codec.py
=====================================
@@ -27,9 +27,9 @@ def dump(obj, fp, cls=GeoJSONEncoder, allow_nan=False, **kwargs):
                      fp, cls=cls, allow_nan=allow_nan, **kwargs)
 
 
-def dumps(obj, cls=GeoJSONEncoder, allow_nan=False, **kwargs):
+def dumps(obj, cls=GeoJSONEncoder, allow_nan=False, ensure_ascii=False, **kwargs):
     return json.dumps(to_mapping(obj),
-                      cls=cls, allow_nan=allow_nan, **kwargs)
+                      cls=cls, allow_nan=allow_nan, ensure_ascii=ensure_ascii, **kwargs)
 
 
 def load(fp,


=====================================
geojson/examples.py
=====================================
@@ -1,5 +1,4 @@
-
-class SimpleWebFeature(object):
+class SimpleWebFeature:
 
     """
     A simple, Atom-ish, single geometry (WGS84) GIS feature.


=====================================
geojson/feature.py
=====================================
@@ -23,7 +23,7 @@ class Feature(GeoJSON):
         :return: Feature object
         :rtype: Feature
         """
-        super(Feature, self).__init__(**extra)
+        super().__init__(**extra)
         if id is not None:
             self["id"] = id
         self["geometry"] = (self.to_instance(geometry, strict=True)
@@ -48,7 +48,7 @@ class FeatureCollection(GeoJSON):
         :return: FeatureCollection object
         :rtype: FeatureCollection
         """
-        super(FeatureCollection, self).__init__(**extra)
+        super().__init__(**extra)
         self["features"] = features
 
     def errors(self):


=====================================
geojson/geometry.py
=====================================
@@ -1,14 +1,10 @@
-import sys
 from decimal import Decimal
+from numbers import Number, Real
 
 from geojson.base import GeoJSON
 
 
-if sys.version_info[0] == 3:
-    # Python 3.x has no long type
-    _JSON_compliant_types = (float, int, Decimal)
-else:
-    _JSON_compliant_types = (float, int, Decimal, long)  # noqa
+DEFAULT_PRECISION = 6
 
 
 class Geometry(GeoJSON):
@@ -16,7 +12,7 @@ class Geometry(GeoJSON):
     Represents an abstract base class for a WGS84 geometry.
     """
 
-    def __init__(self, coordinates=None, validate=False, precision=6, **extra):
+    def __init__(self, coordinates=None, validate=False, precision=None, **extra):
         """
         Initialises a Geometry object.
 
@@ -27,14 +23,16 @@ class Geometry(GeoJSON):
         :param precision: Number of decimal places for lat/lon coords.
         :type precision: integer
         """
-        super(Geometry, self).__init__(**extra)
+        super().__init__(**extra)
+        if precision is None:
+            precision = DEFAULT_PRECISION
         self["coordinates"] = self.clean_coordinates(
             coordinates or [], precision)
 
         if validate:
             errors = self.errors()
             if errors:
-                raise ValueError('{}: {}'.format(errors, coordinates))
+                raise ValueError(f'{errors}: {coordinates}')
 
     @classmethod
     def clean_coordinates(cls, coords, precision):
@@ -49,7 +47,7 @@ class Geometry(GeoJSON):
                 new_coords.append(cls.clean_coordinates(coord, precision))
             elif isinstance(coord, Geometry):
                 new_coords.append(coord['coordinates'])
-            elif isinstance(coord, _JSON_compliant_types):
+            elif isinstance(coord, (Real, Decimal)):
                 new_coords.append(round(coord, precision))
             else:
                 raise ValueError("%r is not a JSON compliant number" % coord)
@@ -62,7 +60,7 @@ class GeometryCollection(GeoJSON):
     """
 
     def __init__(self, geometries=None, **extra):
-        super(GeometryCollection, self).__init__(**extra)
+        super().__init__(**extra)
         self["geometries"] = geometries or []
 
     def errors(self):
@@ -83,6 +81,9 @@ def check_point(coord):
         return 'each position must be a list'
     if len(coord) not in (2, 3):
         return 'a position must have exactly 2 or 3 values'
+    for number in coord:
+        if not isinstance(number, Number):
+            return 'a position cannot have inner positions'
 
 
 class Point(Geometry):
@@ -143,7 +144,7 @@ class MultiPolygon(Geometry):
         return self.check_list_errors(check_polygon, self['coordinates'])
 
 
-class Default(object):
+class Default:
     """
     GeoJSON default object.
     """


=====================================
geojson/mapping.py
=====================================
@@ -1,7 +1,4 @@
-try:
-    from collections.abc import MutableMapping
-except ImportError:
-    from collections import MutableMapping
+from collections.abc import MutableMapping
 
 try:
     import simplejson as json


=====================================
geojson/utils.py
=====================================
@@ -11,17 +11,17 @@ def coords(obj):
     :rtype: generator
     """
     # Handle recursive case first
-    if 'features' in obj:
+    if 'features' in obj:  # FeatureCollection
         for f in obj['features']:
-            # For Python 2 compatibility
-            # See https://www.reddit.com/r/learnpython/comments/4rc15s/yield_from_and_python_27/ # noqa: E501
-            for c in coords(f):
-                yield c
+            yield from coords(f)
+    elif 'geometry' in obj:  # Feature
+        yield from coords(obj['geometry'])
+    elif 'geometries' in obj:  # GeometryCollection
+        for g in obj['geometries']:
+            yield from coords(g)
     else:
         if isinstance(obj, (tuple, list)):
             coordinates = obj
-        elif 'geometry' in obj:
-            coordinates = obj['geometry']['coordinates']
         else:
             coordinates = obj.get('coordinates', obj)
         for e in coordinates:
@@ -197,7 +197,11 @@ def generate_random(featureType, numberVertices=3,
             r_i = clip(random.gauss(aveRadius, spikeyness), 0, 2 * aveRadius)
             x = ctrX + r_i * math.cos(angle)
             y = ctrY + r_i * math.sin(angle)
-            points.append((int(x), int(y)))
+            x = (x + 180.0) * (abs(lonMin-lonMax) / 360.0) + lonMin
+            y = (y + 90.0) * (abs(latMin-latMax) / 180.0) + latMin
+            x = clip(x, lonMin, lonMax)
+            y = clip(y, latMin, latMax)
+            points.append((x, y))
             angle = angle + angleSteps[i]
 
         firstVal = points[0]


=====================================
setup.py
=====================================
@@ -1,28 +1,24 @@
-import io
 from setuptools import setup
 import sys
 import re
 
 
-with io.open("README.rst") as readme_file:
+with open("README.rst") as readme_file:
     readme_text = readme_file.read()
 
 VERSIONFILE = "geojson/_version.py"
-verstrline = open(VERSIONFILE, "rt").read()
+verstrline = open(VERSIONFILE).read()
 VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
 mo = re.search(VSRE, verstrline, re.M)
 if mo:
     verstr = mo.group(1)
 else:
-    raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
+    raise RuntimeError(f"Unable to find version string in {VERSIONFILE}.")
 
 
 def test_suite():
     import doctest
-    try:
-        import unittest2 as unittest
-    except ImportError:
-        import unittest
+    import unittest
 
     suite = unittest.TestLoader().discover("tests")
     suite.addTest(doctest.DocFileSuite("README.rst"))
@@ -30,16 +26,11 @@ def test_suite():
 
 
 major_version, minor_version = sys.version_info[:2]
-if not ((major_version == 2 and minor_version == 7)
-        or (major_version == 3 and minor_version >= 5)):
-    sys.stderr.write("Sorry, only Python 2.7, 3.5, 3.6 and 3.7 are supported "
-                     "at this time.\n")
+if not (major_version == 3 and 7 <= minor_version <= 11):
+    sys.stderr.write("Sorry, only Python 3.7 - 3.11 are "
+                     "supported at this time.\n")
     exit(1)
 
-# Get around this issue: http://bugs.python.org/issue15881
-# Appears to be a problem in older versions of Python 2.7
-import multiprocessing  # NOQA
-
 setup(
     name="geojson",
     version=verstr,
@@ -50,13 +41,14 @@ setup(
     author_email="sgillies at frii.com",
     maintainer="Ray Riga",
     maintainer_email="ray at strongoutput.com",
-    url="https://github.com/jazzband/python-geojson",
+    url="https://github.com/jazzband/geojson",
     long_description=readme_text,
     packages=["geojson"],
     package_dir={"geojson": "geojson"},
     package_data={"geojson": ["*.rst"]},
     install_requires=[],
     test_suite="setup.test_suite",
+    python_requires=">=3.7, <=3.11",
     classifiers=[
         "Development Status :: 5 - Production/Stable",
         "Intended Audience :: Developers",
@@ -64,12 +56,12 @@ setup(
         "License :: OSI Approved :: BSD License",
         "Operating System :: OS Independent",
         "Programming Language :: Python",
-        "Programming Language :: Python :: 2",
-        "Programming Language :: Python :: 2.7",
         "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.5",
-        "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: 3.7",
+        "Programming Language :: Python :: 3.8",
+        "Programming Language :: Python :: 3.9",
+        "Programming Language :: Python :: 3.10",
+        "Programming Language :: Python :: 3.11",
         "Topic :: Scientific/Engineering :: GIS",
     ]
 )


=====================================
tests/test_base.py
=====================================
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 """
 Tests for geojson/base.py
 """


=====================================
tests/test_constructor.py
=====================================
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 """
 Tests for geojson object constructor
 """


=====================================
tests/test_coords.py
=====================================
@@ -41,6 +41,24 @@ class CoordsTestCase(unittest.TestCase):
         self.assertEqual(pairs[0], (-115.11, 37.11))
         self.assertEqual(pairs[1], (-115.22, 37.22))
 
+    def test_geometrycollection(self):
+        p1 = geojson.Point((-115.11, 37.11))
+        p2 = geojson.Point((-115.22, 37.22))
+        ln = geojson.LineString(
+            [(-115.3, 37.3), (-115.4, 37.4), (-115.5, 37.5)])
+        g = geojson.MultiPolygon([
+            ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
+            ([(23.18, -34.29), (-1.31, -4.61),
+              (3.41, 77.91), (23.18, -34.29)],)])
+        itr = coords(geojson.GeometryCollection([p1, p2, ln, g]))
+        pairs = set(itr)
+        self.assertEqual(pairs, {
+            (-115.11, 37.11), (-115.22, 37.22),
+            (-115.3, 37.3), (-115.4, 37.4), (-115.5, 37.5),
+            (3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28),
+            (23.18, -34.29), (-1.31, -4.61), (3.41, 77.91), (23.18, -34.29)
+        })
+
     def test_map_point(self):
         result = map_coords(lambda x: x, geojson.Point((-115.81, 37.24)))
         self.assertEqual(result['type'], 'Point')


=====================================
tests/test_features.py
=====================================
@@ -1,7 +1,4 @@
-try:
-    from StringIO import StringIO
-except ImportError:
-    from io import StringIO
+from io import StringIO
 import unittest
 
 import geojson
@@ -82,7 +79,7 @@ class FeaturesTest(unittest.TestCase):
                 ' "properties": {"summary": "The first feature",'
                 ' "link": "http://example.org/features/1",'
                 ' "title": "Feature 1"}}')
-        feature = geojson.loads(json, object_hook=factory, encoding="utf-8")
+        feature = geojson.loads(json, object_hook=factory)
         self.assertEqual(repr(type(feature)),
                          "<class 'geojson.examples.SimpleWebFeature'>")
         self.assertEqual(feature.id, '1')
@@ -94,7 +91,7 @@ class FeaturesTest(unittest.TestCase):
                          '{"coordinates": [53.0, -4.0], "type": "Point"}')
 
     def test_geo_interface(self):
-        class Thingy(object):
+        class Thingy:
             def __init__(self, id, title, x, y):
                 self.id = id
                 self.title = title


=====================================
tests/test_geo_interface.py
=====================================
@@ -10,12 +10,12 @@ from geojson.mapping import to_mapping
 class EncodingDecodingTest(unittest.TestCase):
 
     def setUp(self):
-        class Restaurant(object):
+        class Restaurant:
             """
             Basic Restaurant class
             """
             def __init__(self, name, latlng):
-                super(Restaurant, self).__init__()
+                super().__init__()
                 self.name = name
                 self.latlng = latlng
 


=====================================
tests/test_utils.py
=====================================
@@ -0,0 +1,50 @@
+"""
+Tests for geojson generation
+"""
+
+import random
+import unittest
+
+import geojson
+from geojson.utils import generate_random
+
+
+def generate_bbox():
+    min_lat = random.random() * 180.0 - 90.0
+    max_lat = random.random() * 180.0 - 90.0
+    if min_lat > max_lat:
+        min_lat, max_lat = max_lat, min_lat
+    min_lon = random.random() * 360.0 - 180.0
+    max_lon = random.random() * 360.0 - 180.0
+    if min_lon > max_lon:
+        min_lon, max_lon = max_lon, min_lon
+    return [min_lon, min_lat, max_lon, max_lat]
+
+
+def check_polygon_bbox(polygon, bbox):
+    min_lon, min_lat, max_lon, max_lat = bbox
+    eps = 1e-3
+    for linear_ring in polygon['coordinates']:
+        for coordinate in linear_ring:
+            if not (min_lon-eps <= coordinate[0] <= max_lon+eps
+                    and min_lat-eps <= coordinate[1] <= max_lat+eps):
+                return False
+    return True
+
+
+class TestGenerateRandom(unittest.TestCase):
+    def test_simple_polygon(self):
+        for _ in range(5000):
+            bbox = [-180.0, -90.0, 180.0, 90.0]
+            result = generate_random('Polygon')
+            self.assertIsInstance(result, geojson.geometry.Polygon)
+            self.assertTrue(geojson.geometry.check_polygon(result))
+            self.assertTrue(check_polygon_bbox(result, bbox))
+
+    def test_bbox_polygon(self):
+        for _ in range(5000):
+            bbox = generate_bbox()
+            result = generate_random('Polygon', boundingBox=bbox)
+            self.assertIsInstance(result, geojson.geometry.Polygon)
+            self.assertTrue(geojson.geometry.check_polygon(result))
+            self.assertTrue(check_polygon_bbox(result, bbox))


=====================================
tests/test_validation.py
=====================================
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 """
 Tests for geojson/validation
 """
@@ -54,6 +53,9 @@ class TestValidationPoint(unittest.TestCase):
         point = geojson.Point((10, 20, 30, 40))
         self.assertEqual(point.is_valid, False)
 
+        point = geojson.Point([(10, 20), (30, 40)])
+        self.assertEqual(point.is_valid, False)
+
     def test_valid_point(self):
         point = geojson.Point((-3.68, 40.41))
         self.assertEqual(point.is_valid, True)


=====================================
tox.ini
=====================================
@@ -4,7 +4,7 @@
 # and then run "tox" from this directory.
 
 [tox]
-envlist = py{27,35,36,37}, pypy, pypy3
+envlist = py{36,37,38,39,310}, pypy3
 
 [testenv]
 commands = {envpython} setup.py test



View it on GitLab: https://salsa.debian.org/debian-gis-team/python-geojson/-/commit/ca487759d5fc7e54ba93deb5118957431f2254d1

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/python-geojson/-/commit/ca487759d5fc7e54ba93deb5118957431f2254d1
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20230126/f5b04f54/attachment-0001.htm>


More information about the Pkg-grass-devel mailing list