Skip to content

pre-4.0.0 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2560407
Change the author_email
dmtucker Aug 14, 2016
7b52622
Bump the Development Status to Stable
dmtucker Aug 14, 2016
f8b2d77
Use absolute imports everywhere
dmtucker Aug 16, 2016
a1b8706
Raise the limit for function name length
dmtucker Aug 20, 2016
d08612f
Convert gjtk.test.test_validate to pytest
dmtucker Aug 16, 2016
da8db1a
Remove redundant tests
dmtucker Aug 17, 2016
a1c0870
Rename test_validate_examples to test_examples
dmtucker Aug 17, 2016
741ee92
Convert test_examples to pytest
dmtucker Aug 17, 2016
a678ef3
Add gjtk.example
dmtucker Aug 18, 2016
46ab739
Convert gjtk.test.test_extract to pytest
dmtucker Aug 18, 2016
a537b77
Remove gjtk.test usage in __main__
dmtucker Aug 20, 2016
9fff8ac
Add tests for uncovered lines
dmtucker Aug 18, 2016
ea2d66d
Include coverage in tox
dmtucker Aug 18, 2016
770f3d9
Use random.choice in test fixtures
dmtucker Aug 20, 2016
0889780
Drop support for Python 3.3
dmtucker Aug 20, 2016
f03443a
Use a compatible version explicitly in setup.py
dmtucker Aug 20, 2016
0ffd1bf
Use print instead of sys.stdout.write
dmtucker Aug 20, 2016
ee76cd8
Update .pylintrc
dmtucker Aug 20, 2016
94ac4b5
Improve gjtk lint error-handling
dmtucker Aug 20, 2016
c471bc3
Improve gjtk lint output
dmtucker Aug 20, 2016
a6ba326
Use sys.exit to control exit status
dmtucker Aug 20, 2016
60a17c8
Redefine __main__ and add gjtk.cli
dmtucker Aug 20, 2016
6517cf4
Add tests for gjtk.__main__ and gjtk.cli
dmtucker Aug 21, 2016
68326f8
Refactor test_extract
dmtucker Aug 21, 2016
08700f1
Pack gjtk last
dmtucker Aug 21, 2016
288b18e
Switch to tox-travis
dmtucker Aug 21, 2016
fef70ea
Push console_script testing into tox
dmtucker Aug 21, 2016
7295fb7
Move style-checking to tox
dmtucker Aug 21, 2016
eb56ba8
Refactor test fixtures
dmtucker Aug 21, 2016
43a6ee9
Unify around UTF-8 encoding
dmtucker Aug 22, 2016
107b89c
Improve the error message of exit_with_status
dmtucker Aug 22, 2016
2662794
Add coveralls support
dmtucker Aug 23, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 64 additions & 36 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# paths.
ignore=CVS

# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=

# Pickle collected data for later comparisons.
persistent=yes

Expand All @@ -35,7 +39,8 @@ extension-pkg-whitelist=
# be used to obtain the result of joining multiple strings with the addition
# operator. Joining a lot of strings can lead to a maximum recursion error in
# Pylint and this flag can prevent that. It has one side effect, the resulting
# AST will be different than the one from reality.
# AST will be different than the one from reality. This option is deprecated
# and it will be removed in Pylint 2.0.
optimize-ast=no


Expand All @@ -60,7 +65,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating
disable=nonzero-method,input-builtin,file-builtin,old-division,unicode-builtin,standarderror-builtin,raw_input-builtin,xrange-builtin,suppressed-message,unichr-builtin,execfile-builtin,dict-view-method,coerce-method,round-builtin,long-builtin,delslice-method,getslice-method,dict-iter-method,old-ne-operator,cmp-method,basestring-builtin,old-octal-literal,useless-suppression,raising-string,range-builtin-not-iterating,next-method-called,intern-builtin,long-suffix,filter-builtin-not-iterating,import-star-module-level,print-statement,map-builtin-not-iterating,using-cmp-argument,zip-builtin-not-iterating,coerce-builtin,cmp-builtin,old-raise-syntax,unpacking-in-except,buffer-builtin,reduce-builtin,oct-method,hex-method,parameter-unpacking,metaclass-assignment,apply-builtin,reload-builtin,setslice-method,no-absolute-import,indexing-exception,backtick


[REPORTS]
Expand All @@ -72,7 +77,8 @@ output-format=text

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
# written in a file name "pylint_global.[txt|html]". This option is deprecated
# and it will be removed in Pylint 2.0.
files-output=no

# Tells whether to display a full report or only the messages
Expand All @@ -92,9 +98,6 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme

[BASIC]

# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_,f

Expand All @@ -108,17 +111,9 @@ name-group=
# Include a hint for the correct naming format with invalid-name
include-naming-hint=no

# Regular expression matching correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for function names
function-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for variable names
variable-name-hint=[a-z_][a-z0-9_]{2,30}$
# List of decorators that produce properties, such as abc.abstractproperty. Add
# to this list to register other decorators that produce valid properties.
property-classes=abc.abstractproperty

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
Expand All @@ -132,42 +127,54 @@ attr-rgx=[a-z_][a-z0-9_]{2,30}$
# Naming hint for attribute names
attr-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{2,30}$
# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Regular expression matching correct function names
function-rgx=[a-z_][a-z0-9_]{2,50}$

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
# Naming hint for function names
function-name-hint=[a-z_][a-z0-9_]{2,50}$

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,40}$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{2,40}$

# Regular expression matching correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for method names
method-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression matching correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for variable names
variable-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=^_
Expand Down Expand Up @@ -231,7 +238,7 @@ notes=FIXME,XXX,TODO
[SIMILARITIES]

# Minimum lines number of a similarity.
min-similarity-lines=8
min-similarity-lines=5

# Ignore comments when computing similarities.
ignore-comments=yes
Expand Down Expand Up @@ -272,16 +279,21 @@ ignore-mixin-members=yes
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). This supports can work
# with qualified names.
ignored-classes=
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=optparse.Values,thread._local,_thread._local

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=

# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
# produce valid context managers.
contextmanager-decorators=contextlib.contextmanager


[VARIABLES]

Expand All @@ -290,7 +302,7 @@ init-import=no

# A regular expression matching the name of dummy variables (i.e. expectedly
# not used).
dummy-variables-rgx=_$|dummy
dummy-variables-rgx=(_+[a-zA-Z0-9]*?$)|dummy

# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
Expand All @@ -300,6 +312,10 @@ additional-builtins=
# name must start or end with one of those strings.
callbacks=cb_,_cb

# List of qualified module names which can have objects that can redefine
# builtins.
redefining-builtins-modules=six.moves,future.builtins


[CLASSES]

Expand Down Expand Up @@ -357,7 +373,7 @@ max-bool-expr=5
[IMPORTS]

# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,TERMIOS,Bastion,rexec
deprecated-modules=optparse

# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled)
Expand All @@ -371,6 +387,18 @@ ext-import-graph=
# not be disabled)
int-import-graph=

# Force import order to recognize a module as part of the standard
# compatibility libraries.
known-standard-library=

# Force import order to recognize a module as part of a third party library.
known-third-party=enchant

# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
analyse-fallback-blocks=no


[EXCEPTIONS]

Expand Down
17 changes: 4 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
branches:
only:
- master
before_install:
- pip install --upgrade pip
- pip install pep8 pylint tox
install:
- python setup.py sdist
- pip install ./dist/*
script:
- gjtk --help
- tox
- pep8 gjtk setup.py
- pylint gjtk setup.py
- master
install: pip install tox-travis coveralls
script: tox
after_success: coveralls
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
graft gjtk
global-exclude *.py[cod] __pycache__
include LICENSE
graft gjtk
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GeoJSON ToolKit

``gjtk`` is a library for working with `GeoJSON`_. It aims to be as compliant with the specification (soon `standard`_, hopefully) as possible.

|Build Status| |PyPI Version|
|Build Status| |Test Coverage| |PyPI Version|

Installation
------------
Expand Down Expand Up @@ -213,5 +213,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

.. |Build Status| image:: https://img.shields.io/travis/dmtucker/gjtk-py.svg
:target: https://travis-ci.org/dmtucker/gjtk-py
.. |Test Coverage| image:: https://img.shields.io/coveralls/dmtucker/gjtk-py.svg
:target: https://coveralls.io/github/dmtucker/gjtk-py
.. |PyPI Version| image:: https://img.shields.io/pypi/v/gjtk.svg
:target: https://pypi.python.org/pypi/gjtk
14 changes: 10 additions & 4 deletions gjtk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# coding: utf-8

"""GeoJSON ToolKit"""

from . import extract
from . import generate
from . import random
from . import validate
from __future__ import absolute_import

from gjtk import cli
from gjtk import example
from gjtk import extract
from gjtk import generate
from gjtk import random
from gjtk import validate
109 changes: 5 additions & 104 deletions gjtk/__main__.py
Original file line number Diff line number Diff line change
@@ -1,108 +1,9 @@
"""GJTK CLI Interface"""

from __future__ import absolute_import
from __future__ import print_function

import argparse
import json
import sys

import gjtk


def lint(args):
"""Validate GeoJSON files."""
valid = 0
for path in args.paths:
with open(path, 'r') as f:
anything = json.load(f)
sys.stdout.write(path+'... ')
if gjtk.validate.is_geojson(anything):
valid += 1
print('valid')
else:
print('invalid')
print(str(valid) + '/' + str(len(args.paths)) + ' valid GeoJSON files')


def stat(args):
"""Count the number of GeoJSON objects present of each type."""
valid = 0
geometries = 0
features = 0
feature_collections = 0
for path in args.paths:
with open(path, 'r') as f:
geojson = json.load(f)
if not gjtk.validate.is_geojson(geojson):
continue
valid += 1
if gjtk.validate.is_feature_collection(geojson):
feature_collections += 1
for feature in geojson['features']:
features += 1
geometries += stat_feature(feature)
elif gjtk.validate.is_feature(geojson):
features += 1
geometries += stat_feature(geojson)
else:
assert gjtk.validate.is_geometry(geojson), \
'A valid GeoJSON object is not a' \
' FeatureCollection, Feature, or Geometry!\n{0}'.format(
gjtk.test.error_message(test_data=geojson),
)
geometries += stat_geometry(geojson)
print(str(valid) + '/' + str(len(args.paths)) + ' valid GeoJSON files')
print(str(feature_collections) + ' FeatureCollections')
print(str(features) + ' Features')
print(str(geometries) + ' Geometries')
# coding: utf-8

"""This module defines the behavior of python -m."""

def stat_feature(feature):
"""Count the number of Geometries in a Feature."""
geometries = 0
if gjtk.validate.is_geometry(feature['geometry']):
geometries += stat_geometry(feature['geometry'])
return geometries


def stat_geometry(geometry):
"""Count the number of Geometries in a Geometry."""
geometries = 1
if gjtk.validate.is_geometry_collection(geometry):
for each in geometry['geometries']:
geometries += stat_geometry(each)
return geometries


def main():
"""Parse an execute the CLI."""
parser = argparse.ArgumentParser(prog="gjtk")
subparsers = parser.add_subparsers()

lint_parser = subparsers.add_parser(
"lint",
help="Validate a GeoJSON file.",
)
lint_parser.add_argument(
"paths", nargs='+', metavar="path",
help="Specify GeoJSON file(s).",
)
lint_parser.set_defaults(func=lint)

stat_parser = subparsers.add_parser(
"stat",
help="Show information about a GeoJSON file.",
)
stat_parser.add_argument(
"paths", nargs='+', metavar="path",
help="Specify GeoJSON file(s).",
)
stat_parser.set_defaults(func=stat)

args = parser.parse_args()
args.func(args)
from __future__ import absolute_import

import gjtk.cli

if __name__ == '__main__':
main()
gjtk.cli.main()
Loading