Skip to content

Commit

Permalink
add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Nov 9, 2021
1 parent 418fd78 commit 5ba27a0
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
source = json5
source = json5
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include LICENSE
include README.md
include README.md
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

JSON5 for Python

[![Documentation Status](https://readthedocs.org/projects/json-five/badge/?version=latest)](https://json-five.readthedocs.io/en/latest/?badge=latest)
[![Build Status](https://travis-ci.com/spyoungtech/json-five.svg?branch=master)](https://travis-ci.com/spyoungtech/json-five)
[![version](https://img.shields.io/pypi/v/json-five.svg?colorB=blue)](https://pypi.org/project/json-five/)
[![pyversion](https://img.shields.io/pypi/pyversions/json-five.svg?)](https://pypi.org/project/json-five/)
[![Documentation Status](https://readthedocs.org/projects/json-five/badge/?version=latest)](https://json-five.readthedocs.io/en/latest/?badge=latest)
[![Build Status](https://travis-ci.com/spyoungtech/json-five.svg?branch=master)](https://travis-ci.com/spyoungtech/json-five)
[![version](https://img.shields.io/pypi/v/json-five.svg?colorB=blue)](https://pypi.org/project/json-five/)
[![pyversion](https://img.shields.io/pypi/pyversions/json-five.svg?)](https://pypi.org/project/json-five/)
[![Coverage](https://coveralls.io/repos/github/spyoungtech/json-five/badge.svg?branch=master)](https://coveralls.io/github/spyoungtech/json-five?branch=master)

## Installation
Expand Down Expand Up @@ -44,5 +44,5 @@ See also the [full documentation](https://json-five.readthedocs.io/en/latest/)

## Status

This project is still in early stages of development. Check the [issues](https://github.com/spyoungtech/json-five/issues)
This project is still in early stages of development. Check the [issues](https://github.com/spyoungtech/json-five/issues)
page to see known bugs and unimplemented features.
1 change: 0 additions & 1 deletion docs/QuickStart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ You can also work directly with strings
Want to do more? Check out :doc:`/extending` to dive deeper!

1 change: 0 additions & 1 deletion docs/comments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ any whitespace or comments that appear before or after the node.
This section will be expanded with time, the API for working with comments will likely change alot in future
versions.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
2 changes: 1 addition & 1 deletion docs/docrequirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx==3.0.3
sphinx_rtd_theme==0.4.3
sphinx_rtd_theme==0.4.3
1 change: 0 additions & 1 deletion docs/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,3 @@ The resulting model:
],
trailing_comma=None,
)
2 changes: 0 additions & 2 deletions docs/how.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,3 @@ The default dumper dumps python objects directly to JSON text.
.. _JSON5 grammar: https://spec.json5.org/#grammar


2 changes: 1 addition & 1 deletion json5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .loader import loads, load
from .dumper import dumps, dump
from .utils import JSON5DecodeError
from .utils import JSON5DecodeError
26 changes: 13 additions & 13 deletions json5/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def __init__(self, env=None):
@singledispatchmethod
def dump(self, obj):
raise NotImplementedError(f"Cannot dump node {repr(obj)}")

to_json = dump.register

@to_json(dict)
def dict_to_json(self, d):
self.env.write('{', indent=0)
Expand All @@ -69,15 +69,15 @@ def dict_to_json(self, d):
self.env.write('\n', indent=0)
else:
self.env.write(', ', indent=0)

if self.env.indent:
self.env.indent_level -= 1
self.env.write('\n')
self.env.write('}')
else:
self.env.write('}', indent=0)


@to_json(int)
def int_to_json(self, i):
self.env.write(str(i), indent=0)
Expand All @@ -90,7 +90,7 @@ def identifier_to_json(self, s):
def str_to_json(self, s):
self.env.write(json.dumps(s), indent=0)


@to_json(list)
def list_to_json(self, l):
self.env.write('[', indent=0)
Expand All @@ -112,8 +112,8 @@ def list_to_json(self, l):
if self.env.indent:
self.env.indent_level -= 1
self.env.write(']')


@to_json(float)
def float_to_json(self, f):
if f == math.inf:
Expand Down Expand Up @@ -297,31 +297,31 @@ class Modelizer:
@singledispatchmethod
def modelize(self, obj):
raise NotImplementedError(f"Cannot modelize object of type {type(obj)}")

to_model = modelize.register

@to_model(str)
def str_to_model(self, s):
if repr(s).startswith("'"):
return SingleQuotedString(s, raw_value=repr(s))
else:
return DoubleQuotedString(s, raw_value=repr(s))

@to_model(dict)
def dict_to_model(self, d):
kvps = []
for key, value in d.items():
kvp = KeyValuePair(key=self.modelize(key), value=self.modelize(value))
kvps.append(kvp)
return JSONObject(*kvps)

@to_model(list)
def list_to_model(self, lst):
list_values = []
for v in lst:
list_values.append(self.modelize(v))
return JSONArray(*list_values)

@to_model(int)
def int_to_model(self, i):
return Integer(str(i))
Expand Down
2 changes: 0 additions & 2 deletions json5/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ def __init__(self, msg, token):

def __reduce__(self):
return self.__class__, (self.msg, self.token)


2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
license_files = LICENSE
license_files = LICENSE
2 changes: 1 addition & 1 deletion tests/test_json_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def test_repr_does_not_contain_wsc():
assert 'wsc' not in repr(model)

def test_identifier_does_not_need_explicit_raw_value():
assert Identifier('foo').raw_value == 'foo'
assert Identifier('foo').raw_value == 'foo'
2 changes: 1 addition & 1 deletion tests/test_modelizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def test_modelize_nan():

def test_modelize_double_quote_string():
s = "'"
assert loads(dumps(modelize(s), dumper=ModelDumper())) == s
assert loads(dumps(modelize(s), dumper=ModelDumper())) == s
2 changes: 1 addition & 1 deletion tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_no_hang2():
def test_no_hang3():
json_string = '[true, {foo:]false}'
with pytest.raises(JSON5DecodeError) as exc_info:
loads(json_string)
loads(json_string)

0 comments on commit 5ba27a0

Please sign in to comment.