Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f40199d

Browse files
committed
Deprecate the CLI (via import or running normally).
It is less featureful (and less maintained) than the new 'official' option, check-jsonschema. See https://github.com/python-jsonschema/check-jsonschema for details. Closes: #600
1 parent 669bd47 commit f40199d

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v4.17.0
2+
=======
3+
4+
* The ``jsonschema`` CLI (along with ``jsonschema.cli`` the module) are now
5+
deprecated. Use ``check-jsonschema`` instead, which can be installed via
6+
``pip install check-jsonschema`` and found
7+
`here <https://github.com/python-jsonschema/check-jsonschema>`_.
8+
19
v4.16.1
210
=======
311

jsonschema/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import sys
1010
import traceback
11+
import warnings
1112

1213
try:
1314
from importlib import metadata
@@ -24,6 +25,16 @@
2425
from jsonschema.exceptions import SchemaError
2526
from jsonschema.validators import RefResolver, validator_for
2627

28+
warnings.warn(
29+
(
30+
"The jsonschema CLI is deprecated and will be removed in a future "
31+
"version. Please use check-jsonschema instead, which can be installed "
32+
"from https://pypi.org/project/check-jsonschema/"
33+
),
34+
DeprecationWarning,
35+
stacklevel=2,
36+
)
37+
2738

2839
class _CannotLoadFile(Exception):
2940
pass

jsonschema/tests/test_cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import subprocess
1010
import sys
1111
import tempfile
12+
import warnings
1213

1314
try: # pragma: no cover
1415
from importlib import metadata
@@ -17,14 +18,18 @@
1718

1819
from pyrsistent import m
1920

20-
from jsonschema import Draft4Validator, Draft202012Validator, cli
21+
from jsonschema import Draft4Validator, Draft202012Validator
2122
from jsonschema.exceptions import (
2223
RefResolutionError,
2324
SchemaError,
2425
ValidationError,
2526
)
2627
from jsonschema.validators import _LATEST_VERSION, validate
2728

29+
with warnings.catch_warnings():
30+
warnings.simplefilter("ignore")
31+
from jsonschema import cli
32+
2833

2934
def fake_validator(*errors):
3035
errors = list(reversed(errors))
@@ -895,7 +900,7 @@ def test_license(self):
895900

896901
def test_version(self):
897902
version = subprocess.check_output(
898-
[sys.executable, "-m", "jsonschema", "--version"],
903+
[sys.executable, "-W", "ignore", "-m", "jsonschema", "--version"],
899904
stderr=subprocess.STDOUT,
900905
)
901906
version = version.decode("utf-8").strip()

jsonschema/tests/test_deprecations.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from unittest import TestCase
2+
import subprocess
3+
import sys
24

35
from jsonschema import FormatChecker, validators
46

@@ -261,3 +263,14 @@ def test_draftN_format_checker(self):
261263

262264
with self.assertRaises(ImportError):
263265
from jsonschema import draft1234_format_checker # noqa
266+
267+
def test_cli(self):
268+
"""
269+
As of v4.17.0, the jsonschema CLI is deprecated.
270+
"""
271+
272+
process = subprocess.run(
273+
[sys.executable, "-m", "jsonschema"],
274+
capture_output=True,
275+
)
276+
self.assertIn(b"The jsonschema CLI is deprecated ", process.stderr)

0 commit comments

Comments
 (0)