[python-geojson] 01/05: Imported Upstream version 1.3.4
Johan Van de Wauw
johanvdw-guest at moszumanska.debian.org
Mon Feb 13 20:35:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
johanvdw-guest pushed a commit to branch master
in repository python-geojson.
commit a3e01183222034ba0f1b988310fa612eb5a03ef6
Author: Johan Van de Wauw <johan.vandewauw at gmail.com>
Date: Mon Feb 13 20:44:50 2017 +0100
Imported Upstream version 1.3.4
---
.gitignore | 6 ++++++
.travis.yml | 1 -
CHANGELOG.rst | 23 ++++++++++++++++++++++-
README.rst | 2 +-
geojson/__init__.py | 4 +++-
geojson/_version.py | 2 ++
geojson/examples.py | 7 ++-----
geojson/geometry.py | 8 +++++++-
geojson/utils.py | 21 +++++++++++++--------
geojson/validation.py | 22 ++++++++++------------
setup.py | 16 ++++++++++++++--
tests/test_features.py | 2 +-
tests/test_validation.py | 21 +++++++++++++++++++++
tox.ini | 10 ++++++++++
14 files changed, 112 insertions(+), 33 deletions(-)
diff --git a/.gitignore b/.gitignore
index edd9d60..969b14d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,8 @@
+__pycache__/
+*.py[cod]
build/
dist/
+sdist/
+*.egg-info/
+*.egg
+.tox/
diff --git a/.travis.yml b/.travis.yml
index ec47617..f3c75a1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,4 @@
language: "python"
-sudo: false
python:
- "2.7"
- "3.3"
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 73a1e67..9b9d4cd 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,27 @@
Changes
=======
+1.3.4 (2017-02-11)
+------------------
+
+- Remove runtime dependency on setuptools
+
+ - https://github.com/frewsxcv/python-geojson/pull/90
+
+1.3.3 (2016-07-21)
+------------------
+
+- Add validate parameter to GeoJSON constructors
+
+ - https://github.com/frewsxcv/python-geojson/pull/78
+
+1.3.2 (2016-01-28)
+------------------
+
+- Add __version__ and __version_info__ attributes
+
+ - https://github.com/frewsxcv/python-geojson/pull/74
+
1.3.1 (2015-10-12)
------------------
@@ -125,4 +146,4 @@ Changes
- Made all code work with Python 2.4.3, 2.5.1, will test with all variations.
(see tests/rundoctests.dist)
- Made tests use ELLIPSIS to avoid output transmogification due to floating
- point representation.
+ point representation.
diff --git a/README.rst b/README.rst
index 5f0a370..ebc7ffd 100644
--- a/README.rst
+++ b/README.rst
@@ -21,7 +21,7 @@ This library contains:
Installation
------------
-python-geojson is compatible with Python 2.6, 2.7, 3.2, 3.3, and 3.4. It is listed on `PyPi as 'geojson'`_. The recommended way to install is via pip_:
+python-geojson is compatible with Python 2.6, 2.7, 3.2, 3.3, 3.4 and 3.5. It is listed on `PyPi as 'geojson'`_. The recommended way to install is via pip_:
.. code::
diff --git a/geojson/__init__.py b/geojson/__init__.py
index f46f5cc..887f9db 100644
--- a/geojson/__init__.py
+++ b/geojson/__init__.py
@@ -6,6 +6,7 @@ from geojson.geometry import GeometryCollection
from geojson.feature import Feature, FeatureCollection
from geojson.base import GeoJSON
from geojson.validation import is_valid
+from geojson._version import __version__, __version_info__
__all__ = ([dump, dumps, load, loads, GeoJSONEncoder] +
[coords, map_coords] +
@@ -14,4 +15,5 @@ __all__ = ([dump, dumps, load, loads, GeoJSONEncoder] +
[GeometryCollection] +
[Feature, FeatureCollection] +
[GeoJSON] +
- [is_valid])
+ [is_valid] +
+ [__version__, __version_info__])
diff --git a/geojson/_version.py b/geojson/_version.py
new file mode 100644
index 0000000..35531d9
--- /dev/null
+++ b/geojson/_version.py
@@ -0,0 +1,2 @@
+__version__ = "1.3.4"
+__version_info__ = tuple(map(int, __version__.split(".")))
diff --git a/geojson/examples.py b/geojson/examples.py
index 2a75c72..4b8a857 100644
--- a/geojson/examples.py
+++ b/geojson/examples.py
@@ -25,10 +25,7 @@ class SimpleWebFeature(object):
"""
self.id = id
self.geometry = geometry
- self.properties = {}
- self.properties['title'] = title
- self.properties['summary'] = summary
- self.properties['link'] = link
+ self.properties = {'title': title, 'summary': summary, 'link': link}
def as_dict(self):
return {
@@ -47,7 +44,7 @@ class SimpleWebFeature(object):
"""
-def createSimpleWebFeature(o):
+def create_simple_web_feature(o):
"""
Create an instance of SimpleWebFeature from a dict, o. If o does not
match a Python feature object, simply return o. This function serves as a
diff --git a/geojson/geometry.py b/geojson/geometry.py
index 006cc80..931eccd 100644
--- a/geojson/geometry.py
+++ b/geojson/geometry.py
@@ -2,6 +2,7 @@ import sys
from decimal import Decimal
from geojson.base import GeoJSON
+from geojson.validation import is_valid
class Geometry(GeoJSON):
@@ -15,7 +16,7 @@ class Geometry(GeoJSON):
else:
__JSON_compliant_types = (float, int, Decimal, long) # noqa
- def __init__(self, coordinates=None, crs=None, **extra):
+ def __init__(self, coordinates=None, crs=None, validate=False, **extra):
"""
Initialises a Geometry object.
@@ -28,6 +29,11 @@ class Geometry(GeoJSON):
super(Geometry, self).__init__(**extra)
self["coordinates"] = coordinates or []
self.clean_coordinates(self["coordinates"])
+ if validate:
+ validation = is_valid(self)
+ if validation['valid'] == 'no':
+ raise ValueError('{}: {}'.format(
+ validation['message'], coordinates))
if crs:
self["crs"] = self.to_instance(crs, strict=True)
diff --git a/geojson/utils.py b/geojson/utils.py
index 718606f..15ff320 100644
--- a/geojson/utils.py
+++ b/geojson/utils.py
@@ -27,13 +27,16 @@ def coords(obj):
def map_coords(func, obj):
"""
- Returns the coordinates from a Geometry after applying the provided
- function to the tuples.
+ Returns the mapped coordinates from a Geometry after applying the provided
+ function to each dimension in tuples list (ie, linear scaling).
+ :param func: Function to apply to tuples
+ :type func: function
:param obj: A geometry or feature to extract the coordinates from.
:type obj: Point, LineString, MultiPoint, MultiLineString, Polygon,
MultiPolygon
- :return: The result of applying the function to each coordinate array.
+ :return: The result of applying the function to each dimension in the
+ array.
:rtype: list
:raises ValueError: if the provided object is not a Geometry.
"""
@@ -61,14 +64,16 @@ def generate_random(featureType, numberVertices=3,
"""
Generates random geojson features depending on the parameters
passed through.
+ The bounding box defaults to the world - [-180.0, -90.0, 180.0, 90.0].
+ The number of vertices defaults to 3.
:param featureType: A geometry type
- :type string: Point, LineString, Polygon
- :param numberVertices: The number vertices that
- a linestring or polygon will have
- :type int: defaults to 3
+ :type featureType: Point, LineString, Polygon
+ :param numberVertices: The number vertices that a linestring or polygon
+ will have
+ :type numberVertices: int
:param boundingBox: A bounding box in which features will be restricted to
- :type list: defaults to the world - [-180.0, -90.0, 180.0, 90.0]
+ :type boundingBox: list
:return: The resulting random geojson object or geometry collection.
:rtype: object
:raises ValueError: if there is no featureType provided.
diff --git a/geojson/validation.py b/geojson/validation.py
index 6e8b54f..e1afa37 100644
--- a/geojson/validation.py
+++ b/geojson/validation.py
@@ -3,14 +3,14 @@ import geojson
def is_valid(obj):
""" IsValid provides validation for GeoJSON objects
- All of error messages obtained from the offical site
+ All of error messages obtained from the official site
http://geojson.org/geojson-spec.html
Args:
obj(geoJSON object): check validation
Returns:
- dict of two paremeters 'valid' and 'message'.
+ dict of two parameters 'valid' and 'message'.
In the case if geoJSON object is valid, returns
{valid: 'yes', message: ''}
If json objects is not valid, returns
@@ -76,13 +76,12 @@ def checkListOfObjects(coord, pred):
MultiLineString that each element of the list is valid geojson object.
This is helpful method for IsValid.
- Args:
- coord(list): List of coordinates
- pred(function): Predicate to check validation of each
- member in the coord
-
- Returns:
- True if list contains valid objects, False otherwise
+ :param coord: List of coordinates
+ :type coord: list
+ :param pred: Predicate to check validation of each member in the coord
+ :type pred: function
+ :return: True if list contains valid objects, False otherwise
+ :rtype: bool
"""
return not isinstance(coord, list) or not all([pred(ls) for ls in coord])
@@ -90,9 +89,8 @@ def checkListOfObjects(coord, pred):
def output(message):
""" Output result for IsValid
- Args:
- message - If message is not empty,
- object is not valid
+ :param message: If message is not empty, object is not valid
+ :type message: str
"""
result = {'valid': 'no', 'message': ''}
if message != '':
diff --git a/setup.py b/setup.py
index 26a3082..3166430 100644
--- a/setup.py
+++ b/setup.py
@@ -1,11 +1,21 @@
import io
from setuptools import setup
import sys
+import re
with io.open("README.rst") as readme_file:
readme_text = readme_file.read()
+VERSIONFILE = "geojson/_version.py"
+verstrline = open(VERSIONFILE, "rt").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,))
+
def test_suite():
import doctest
@@ -18,6 +28,7 @@ def test_suite():
suite.addTest(doctest.DocFileSuite("README.rst"))
return suite
+
if sys.version_info[:2] not in [(2, 6), (2, 7)] and \
sys.version_info[:1] not in [(3, )]:
sys.stderr.write("Sorry, only Python 2.7, and 3.x are supported "
@@ -30,7 +41,7 @@ import multiprocessing # NOQA
setup(
name="geojson",
- version="1.3.1",
+ version=verstr,
description="Python bindings and utilities for GeoJSON",
license="BSD",
keywords="gis geography json",
@@ -43,7 +54,7 @@ setup(
packages=["geojson"],
package_dir={"geojson": "geojson"},
package_data={"geojson": ["*.rst"]},
- install_requires=["setuptools"],
+ install_requires=[],
test_suite="setup.test_suite",
classifiers=[
"Development Status :: 5 - Production/Stable",
@@ -58,6 +69,7 @@ setup(
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
+ "Programming Language :: Python :: 3.5",
"Topic :: Scientific/Engineering :: GIS",
]
)
diff --git a/tests/test_features.py b/tests/test_features.py
index 9f791fa..fe295d4 100644
--- a/tests/test_features.py
+++ b/tests/test_features.py
@@ -72,7 +72,7 @@ class FeaturesTest(unittest.TestCase):
self.assertEqual(geojson.dumps(feature, sort_keys=True), json)
# Decoding
- factory = geojson.examples.createSimpleWebFeature
+ factory = geojson.examples.create_simple_web_feature
json = ('{"geometry": {"type": "Point",'
' "coordinates": [53, -4]},'
' "id": "1",'
diff --git a/tests/test_validation.py b/tests/test_validation.py
index 3b80d7b..45d47d4 100644
--- a/tests/test_validation.py
+++ b/tests/test_validation.py
@@ -12,6 +12,27 @@ YES = 'yes'
NO = 'no'
+class TestValidationGeometry(unittest.TestCase):
+
+ def test_invalid_geometry_with_validate(self):
+ self.assertRaises(
+ ValueError, geojson.Point, (10, 20, 30), validate=True)
+
+ def test_invalid_geometry_without_validate(self):
+ try:
+ geojson.Point((10, 20, 30))
+ geojson.Point((10, 20, 30), validate=False)
+ except ValueError:
+ self.fail("Point raised ValueError unexpectedly")
+
+ def test_valid_geometry(self):
+ try:
+ geojson.Point((10, 20), validate=True)
+ geojson.Point((10, 20), validate=False)
+ except ValueError:
+ self.fail("Point raised ValueError unexpectedly")
+
+
class TestValidationGeoJSONObject(unittest.TestCase):
def test_invalid_jsonobject(self):
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..e4608b3
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,10 @@
+# Tox (http://tox.testrun.org/) is a tool for running tests
+# in multiple virtualenvs. This configuration file will run the
+# test suite on all supported python versions. To use it, "pip install tox"
+# and then run "tox" from this directory.
+
+[tox]
+envlist = py{27,33,34,35}, pypy, pypy3
+
+[testenv]
+commands = {envpython} setup.py test
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-geojson.git
More information about the Pkg-grass-devel
mailing list