Skip to content

Commit

Permalink
Merge pull request #62 from Kijewski/pr-issue-61
Browse files Browse the repository at this point in the history
 Fix typing for _SupportsWrite
  • Loading branch information
Kijewski authored Jun 23, 2023
2 parents fe70ed0 + fcd7a8d commit e117948
Show file tree
Hide file tree
Showing 25 changed files with 493 additions and 407 deletions.
48 changes: 38 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
python: [
'3.5',
# '3.6', '3.7', '3.8', '3.9', # it takes too much GitHub action time to run tests on all versions in between
'3.10',
]
include:
- os: ubuntu-latest
python: pypy-3.7

name: Python ${{ matrix.python }} on ${{ matrix.os }}
python:
- '3.8'
- '3.11'

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -56,3 +49,38 @@ jobs:

- name: Run "JSON is a Minefield" suite
run: python run-minefield-test.py

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Cache pip
uses: actions/cache@v3
with:
key: lint--${{ hashFiles('./requirements*.txt', './Makefile') }}
restore-keys: lint--
path: ~/.cache/pip

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Display Python version
run: python -c 'import sys; print(sys.version)'

- name: Update pip
run: python -m pip install -U pip wheel setuptools

- name: Install requirements
run: python -m pip install -Ur requirements-dev.txt

- name: Compile project
run: make install

- name: Run black
run: python -m black --check ./*.py ./src/
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Cache pip
uses: actions/cache@v3
with:
key: codeql-analysis--${{ github.event.inputs.os }}--${{ github.event.inputs.python }}--${{ hashFiles('./requirements.txt') }}
key: codeql-analysis--${{ github.event.inputs.os }}--${{ github.event.inputs.python }}--${{ hashFiles('./requirements-dev.txt') }}
path: ~/.cache/pip

- name: Setup python
Expand All @@ -48,7 +48,7 @@ jobs:
run: python -m pip install -U pip wheel setuptools

- name: Install requirements
run: python -m pip install -Ur requirements.txt
run: python -m pip install -Ur requirements-dev.txt

- name: Compile
run: make bdist_wheel
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

**1.6.3**

* Fix typing for `dump()` ([#61](https://github.com/Kijewski/pyjson5/issues/61))

**1.6.2**

* Update to Unicode 15.0.0
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
all: sdist bdist_wheel docs
all: sdist wheel docs

.DELETE_ON_ERROR:

.PHONY: all sdist bdist_wheel clean docs prepare test install
.PHONY: all sdist wheel clean docs prepare test install

export PYTHONUTF8 := 1
export PYTHONIOENCODING := UTF-8
Expand Down Expand Up @@ -34,14 +34,14 @@ pyjson5.cpp: pyjson5.pyx $(wildcard src/*.pyx) $(wildcard src/*.hpp)
prepare: pyjson5.cpp ${FILES}

sdist: prepare
rm -f -- dist/pyjson5-*.tar.gz
python setup.py sdist
-rm -- dist/pyjson5-*.tar.gz
python -m build --sdist

bdist_wheel: pyjson5.cpp ${FILES} | sdist
rm -f -- dist/pyjson5-*.whl
python setup.py bdist_wheel
wheel: prepare
-rm -- dist/pyjson5-*.whl
python -m build --wheel

install: bdist_wheel
install: wheel
pip install --force dist/pyjson5-*.whl

docs: install $(wildcard docs/* docs/*/*)
Expand All @@ -51,9 +51,9 @@ clean:
[ ! -d build/ ] || rm -r -- build/
[ ! -d dist/ ] || rm -r -- dist/
[ ! -d pyjson5.egg-info/ ] || rm -r -- pyjson5.egg-info/
rm -f -- pyjson5.*.so python5.cpp
-rm -- pyjson5.*.so python5.cpp

test: bdist_wheel
test: wheel
pip install --force dist/pyjson5-*.whl
python run-minefield-test.py
python run-tests.py
38 changes: 7 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
'myst_parser',
]

language = "en"

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'

project = u'PyJSON5'
copyright = u'2018-2022, René Kijewski'
author = u'René Kijewski'
project = 'PyJSON5'
copyright = '2018-2023, René Kijewski'
author = 'René Kijewski'

with open('../src/VERSION.inc', 'rt') as f:
version = eval(f.read().strip())
Expand All @@ -33,41 +35,15 @@
pygments_style = 'sphinx'
todo_include_todos = False

html_theme = 'sphinx_rtd_theme'
html_theme_options = {
'navigation_depth': -1,
}
html_sidebars = {
'**': [
'localtoc.html',
'searchbox.html',
]
}
html_theme = 'furo'
htmlhelp_basename = 'PyJSON5doc'

latex_elements = {}
latex_documents = [
(master_doc, 'PyJSON5.tex', u'PyJSON5 Documentation',
u'René Kijewski', 'manual'),
]

man_pages = [
(master_doc, 'pyjson5', u'PyJSON5 Documentation',
[author], 1)
]

texinfo_documents = [
(master_doc, 'PyJSON5', u'PyJSON5 Documentation',
author, 'PyJSON5', 'One line description of project.',
'Miscellaneous'),
]

display_toc = True
autodoc_default_flags = ['members']
autosummary_generate = True

intersphinx_mapping = {
'python': ('https://docs.python.org/3.10', None),
'python': ('https://docs.python.org/3.11', None),
}

inheritance_graph_attrs = {
Expand Down
12 changes: 6 additions & 6 deletions docs/decoder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ Decoder Exceptions
pyjson5.Json5ExtraData
pyjson5.Json5IllegalType

.. autoclass:: pyjson5.Json5DecoderException
.. autoexception:: pyjson5.Json5DecoderException
:members:
:inherited-members:

.. autoclass:: pyjson5.Json5NestingTooDeep
.. autoexception:: pyjson5.Json5NestingTooDeep
:members:
:inherited-members:

.. autoclass:: pyjson5.Json5EOF
.. autoexception:: pyjson5.Json5EOF
:members:
:inherited-members:

.. autoclass:: pyjson5.Json5IllegalCharacter
.. autoexception:: pyjson5.Json5IllegalCharacter
:members:
:inherited-members:

.. autoclass:: pyjson5.Json5ExtraData
.. autoexception:: pyjson5.Json5ExtraData
:members:
:inherited-members:

.. autoclass:: pyjson5.Json5IllegalType
.. autoexception:: pyjson5.Json5IllegalType
:members:
:inherited-members:
4 changes: 2 additions & 2 deletions docs/encoder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ Encoder Exceptions
pyjson5.Json5EncoderException
pyjson5.Json5UnstringifiableType

.. autoclass:: pyjson5.Json5EncoderException
.. autoexception:: pyjson5.Json5EncoderException
:members:
:inherited-members:

.. autoclass:: pyjson5.Json5UnstringifiableType
.. autoexception:: pyjson5.Json5UnstringifiableType
:members:
:inherited-members:
2 changes: 1 addition & 1 deletion docs/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Exceptions
pyjson5.Json5ExtraData
pyjson5.Json5IllegalType

.. autoclass:: pyjson5.Json5Exception
.. autoexception:: pyjson5.Json5Exception
:members:
:inherited-members:
74 changes: 39 additions & 35 deletions make_decoder_recursive_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,58 @@


def generate(out):
lst = ['DRS_fail'] * 128
lst[ord('n')] = 'DRS_null'
lst[ord('t')] = 'DRS_true'
lst[ord('f')] = 'DRS_false'
lst[ord('I')] = 'DRS_inf'
lst[ord('N')] = 'DRS_nan'
lst[ord('"')] = 'DRS_string'
lst[ord("'")] = 'DRS_string'
lst[ord('{')] = 'DRS_recursive'
lst[ord('[')] = 'DRS_recursive'
for c in '+-.0123456789':
lst[ord(c)] = 'DRS_number'

print('#ifndef JSON5EncoderCpp_decoder_recursive_select', file=out)
print('#define JSON5EncoderCpp_decoder_recursive_select', file=out)
lst = ["DRS_fail"] * 128
lst[ord("n")] = "DRS_null"
lst[ord("t")] = "DRS_true"
lst[ord("f")] = "DRS_false"
lst[ord("I")] = "DRS_inf"
lst[ord("N")] = "DRS_nan"
lst[ord('"')] = "DRS_string"
lst[ord("'")] = "DRS_string"
lst[ord("{")] = "DRS_recursive"
lst[ord("[")] = "DRS_recursive"
for c in "+-.0123456789":
lst[ord(c)] = "DRS_number"

print("#ifndef JSON5EncoderCpp_decoder_recursive_select", file=out)
print("#define JSON5EncoderCpp_decoder_recursive_select", file=out)
print(file=out)
print('// GENERATED FILE', file=out)
print('// All changes will be lost.', file=out)
print("// GENERATED FILE", file=out)
print("// All changes will be lost.", file=out)
print(file=out)
print('#include <cstdint>', file=out)
print("#include <cstdint>", file=out)
print(file=out)
print('namespace JSON5EncoderCpp {', file=out)
print('inline namespace {', file=out)
print("namespace JSON5EncoderCpp {", file=out)
print("inline namespace {", file=out)
print(file=out)
print('enum DrsKind : std::uint8_t {', file=out)
print(' DRS_fail, DRS_null, DRS_true, DRS_false, DRS_inf, DRS_nan, DRS_string, DRS_number, DRS_recursive', file=out)
print('};', file=out)
print("enum DrsKind : std::uint8_t {", file=out)
print(
" DRS_fail, DRS_null, DRS_true, DRS_false, DRS_inf, DRS_nan, DRS_string, DRS_number, DRS_recursive",
file=out,
)
print("};", file=out)
print(file=out)
print('static const DrsKind drs_lookup[128] = {', file=out)
print("static const DrsKind drs_lookup[128] = {", file=out)
for chunk in chunked(lst, 8):
print(' ', end='', file=out)
print(" ", end="", file=out)
for t in chunk:
print(' ', t, ',', sep='', end='', file=out)
print(" ", t, ",", sep="", end="", file=out)
print(file=out)
print('};', file=out)
print("};", file=out)
print(file=out)
print('} // anonymous inline namespace', sep='', file=out)
print('} // namespace JSON5EncoderCpp', sep='', file=out)
print("} // anonymous inline namespace", sep="", file=out)
print("} // namespace JSON5EncoderCpp", sep="", file=out)
print(file=out)
print('#endif', sep='', file=out)
print("#endif", sep="", file=out)


argparser = ArgumentParser(description='Generate src/_decoder_recursive_select.hpp')
argparser.add_argument('input', nargs='?', type=Path, default=Path('src/_decoder_recursive_select.hpp'))
argparser = ArgumentParser(description="Generate src/_decoder_recursive_select.hpp")
argparser.add_argument(
"input", nargs="?", type=Path, default=Path("src/_decoder_recursive_select.hpp")
)

if __name__ == '__main__':
if __name__ == "__main__":
basicConfig(level=DEBUG)
args = argparser.parse_args()
with open(str(args.input.resolve()), 'wt') as out:
with open(str(args.input.resolve()), "wt") as out:
generate(out)

Loading

0 comments on commit e117948

Please sign in to comment.