Skip to content

non GPL format option #619

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 4 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/spelling-wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ HD

Berman
Freenode
GPL
29 changes: 21 additions & 8 deletions docs/validate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,26 @@ to validate. Their names can be viewed by inspecting the
`FormatChecker.checkers` attribute. Certain checkers will only be
available if an appropriate package is available for use. The easiest way to
ensure you have what is needed is to install ``jsonschema`` using the
``format`` setuptools extra -- i.e.
``format`` or ``format_nongpl`` setuptools extra -- i.e.

.. code-block:: sh

$ pip install jsonschema[format]

which will install all of the below dependencies for all formats. The
more specific list of available checkers, along with their requirement
which will install all of the below dependencies for all formats.

Or if you want to install MIT-license compatible dependencies only:

.. code-block:: sh

$ pip install jsonschema[format_nongpl]

The non-GPL extra is intended to not install any direct dependencies
that are GPL (but that of course end-users should do their own verification).
At the moment, it supports all the available checkers except for ``iri`` and
``iri-reference``.

The more specific list of available checkers, along with their requirement
(if any,) are listed below.

.. note::
Expand All @@ -342,7 +354,7 @@ Checker Notes
========================= ====================
``color`` requires webcolors_
``date``
``date-time`` requires strict-rfc3339_
``date-time`` requires strict-rfc3339_ or rfc3339-validator_
``email``
``hostname``
``idn-hostname`` requires idna_
Expand All @@ -353,9 +365,9 @@ Checker Notes
``json-pointer`` requires jsonpointer_
``regex``
``relative-json-pointer`` requires jsonpointer_
``time`` requires strict-rfc3339_
``uri`` requires rfc3987_
``uri-reference`` requires rfc3987_
``time`` requires strict-rfc3339_ or rfc3339-validator_
``uri`` requires rfc3987_ or rfc3986-validator_
``uri-reference`` requires rfc3987_ or rfc3986-validator_
========================= ====================


Expand All @@ -365,7 +377,8 @@ Checker Notes
.. _rfc5322: https://tools.ietf.org/html/rfc5322#section-3.4.1
.. _strict-rfc3339: https://pypi.org/pypi/strict-rfc3339/
.. _webcolors: https://pypi.org/pypi/webcolors/

.. _rfc3339-validator: https://pypi.org/project/rfc3339-validator/
.. _rfc3986-validator: https://pypi.org/project/rfc3986-validator/

.. note::

Expand Down
34 changes: 29 additions & 5 deletions jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,27 @@ def is_idn_host_name(instance):
try:
import rfc3987
except ImportError:
pass
try:
from rfc3986_validator import validate_rfc3986
except ImportError:
pass
else:
@_checks_drafts(name="uri")
def is_uri(instance):
if not isinstance(instance, str_types):
return True
return validate_rfc3986(instance, rule="URI")

@_checks_drafts(
draft6="uri-reference",
draft7="uri-reference",
raises=ValueError,
)
def is_uri_reference(instance):
if not isinstance(instance, str_types):
return True
return validate_rfc3986(instance, rule="URI_reference")

else:
@_checks_drafts(draft7="iri", raises=ValueError)
def is_iri(instance):
Expand Down Expand Up @@ -280,15 +300,19 @@ def is_uri_reference(instance):


try:
import strict_rfc3339
from strict_rfc3339 import validate_rfc3339
except ImportError:
pass
else:
try:
from rfc3339_validator import validate_rfc3339
except ImportError:
validate_rfc3339 = None

if validate_rfc3339:
@_checks_drafts(name="date-time")
def is_datetime(instance):
if not isinstance(instance, str_types):
return True
return strict_rfc3339.validate_rfc3339(instance)
return validate_rfc3339(instance)

@_checks_drafts(draft7="time")
def is_time(instance):
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ format =
rfc3987
strict-rfc3339
webcolors
format_nongpl =
idna
jsonpointer>1.13
webcolors
rfc3986-validator>0.1.0
rfc3339-validator

[options.entry_points]
console_scripts =
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{35,36,37,38,py,py3}-{build,tests}
py{35,36,37,38,py,py3}-{build,tests,tests_nongpl},
demo
readme
safety
Expand All @@ -22,8 +22,9 @@ whitelist_externals =
virtualenv
commands =
perf,tests: {envbindir}/python -m pip install '{toxinidir}[format]'
tests_nongpl: {envbindir}/python -m pip install '{toxinidir}[format_nongpl]'

tests: {envbindir}/trial {posargs:jsonschema}
tests,tests_nongpl: {envbindir}/trial {posargs:jsonschema}
tests: {envpython} -m doctest {toxinidir}/README.rst

perf: mkdir {envtmpdir}/benchmarks/
Expand Down Expand Up @@ -53,7 +54,7 @@ deps =

perf: pyperf

tests,coverage,codecov: -r{toxinidir}/test-requirements.txt
tests,tests_nongpl,coverage,codecov: -r{toxinidir}/test-requirements.txt

coverage,codecov: coverage
codecov: codecov
Expand Down