Skip to content

Commit 4ec45e5

Browse files
authored
Merge pull request #114 from stefankoegl/claude/pensive-wright-ioey78
Clean up broken, outdated and redundant bits across the project
2 parents 26d99df + a4b3fb4 commit 4ec45e5

20 files changed

Lines changed: 160 additions & 310 deletions

‎.github/workflows/publish.yml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ jobs:
4040
permissions:
4141
contents: read
4242
steps:
43-
- uses: actions/checkout@v4
43+
- uses: actions/checkout@v7
4444

4545
- name: Set up Python
46-
uses: actions/setup-python@v5
46+
uses: actions/setup-python@v7
4747
with:
4848
python-version: "3.13"
4949

@@ -58,7 +58,7 @@ jobs:
5858
- name: Check distributions
5959
run: twine check --strict dist/*
6060

61-
- uses: actions/upload-artifact@v4
61+
- uses: actions/upload-artifact@v7
6262
with:
6363
name: dist
6464
path: dist/
@@ -74,13 +74,13 @@ jobs:
7474
permissions:
7575
id-token: write
7676
steps:
77-
- uses: actions/download-artifact@v4
77+
- uses: actions/download-artifact@v8
7878
with:
7979
name: dist
8080
path: dist/
8181

8282
- name: Publish to PyPI
83-
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1
83+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
8484

8585
publish-testpypi:
8686
name: Publish to TestPyPI
@@ -93,12 +93,12 @@ jobs:
9393
permissions:
9494
id-token: write
9595
steps:
96-
- uses: actions/download-artifact@v4
96+
- uses: actions/download-artifact@v8
9797
with:
9898
name: dist
9999
path: dist/
100100

101101
- name: Publish to TestPyPI
102-
uses: pypa/gh-action-pypi-publish@release/v1
102+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
103103
with:
104104
repository-url: https://test.pypi.org/legacy/

‎.github/workflows/test.yaml‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ jobs:
1515
permissions:
1616
contents: read
1717
steps:
18-
- uses: actions/checkout@v4
19-
with:
20-
ref: ${{ github.ref }}
18+
- uses: actions/checkout@v7
2119

2220
- name: Set up Python 3.13
23-
uses: actions/setup-python@v5
21+
uses: actions/setup-python@v7
2422
with:
25-
python-version: 3.13
26-
allow-prereleases: true
23+
python-version: "3.13"
2724
- name: Install dependencies
2825
run: |
2926
python -m pip install --upgrade pip
@@ -39,10 +36,10 @@ jobs:
3936
permissions:
4037
contents: read
4138
steps:
42-
- uses: actions/checkout@v4
39+
- uses: actions/checkout@v7
4340

4441
- name: Set up Python 3.13
45-
uses: actions/setup-python@v5
42+
uses: actions/setup-python@v7
4643
with:
4744
python-version: "3.13"
4845
- name: Install build tools
@@ -60,10 +57,10 @@ jobs:
6057
permissions:
6158
contents: read
6259
steps:
63-
- uses: actions/checkout@v4
60+
- uses: actions/checkout@v7
6461

6562
- name: Set up Python 3.13
66-
uses: actions/setup-python@v5
63+
uses: actions/setup-python@v7
6764
with:
6865
python-version: "3.13"
6966
- name: Install dependencies
@@ -81,10 +78,10 @@ jobs:
8178
permissions:
8279
contents: read
8380
steps:
84-
- uses: actions/checkout@v4
81+
- uses: actions/checkout@v7
8582

8683
- name: Set up Python 3.13
87-
uses: actions/setup-python@v5
84+
uses: actions/setup-python@v7
8885
with:
8986
python-version: "3.13"
9087
- name: Install dependencies
@@ -97,21 +94,26 @@ jobs:
9794
test:
9895
needs: [ lint ]
9996
runs-on: ${{ matrix.os }}
97+
# Pre-release Pythons may fail for reasons unrelated to this package
98+
continue-on-error: ${{ matrix.experimental || false }}
10099
strategy:
101100
fail-fast: false
102101
matrix:
103102
os: [ ubuntu-latest ]
104-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy3.10", "pypy3.11" ]
103+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15", "pypy3.11" ]
105104
include:
106105
- os: windows-latest
107-
python-version: "3.13"
106+
python-version: "3.15"
108107
- os: macos-latest
109-
python-version: "3.13"
108+
python-version: "3.15"
109+
- os: ubuntu-latest
110+
python-version: "3.16"
111+
experimental: true
110112

111113
steps:
112-
- uses: actions/checkout@v4
114+
- uses: actions/checkout@v7
113115
- name: Set up Python ${{ matrix.python-version }}
114-
uses: actions/setup-python@v5
116+
uses: actions/setup-python@v7
115117
with:
116118
python-version: ${{ matrix.python-version }}
117119
allow-prereleases: true

‎.readthedocs.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
tools:
1212
python: "3.13"
1313

14-
# Build documentation in the docs/ directory with Sphinx
14+
# Build documentation in the doc/ directory with Sphinx
1515
sphinx:
1616
configuration: doc/conf.py
1717

‎MANIFEST.in‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
include AUTHORS
22
include LICENSE.txt
3-
include README.md
3+
include makefile
4+
include requirements-dev.txt
5+
include .coveragerc
46
include tests.py
57
include doc/*.rst
8+
include doc/conf.py
9+
include doc/Makefile
10+
include doc/requirements.txt
611
recursive-include jsonpointer-stubs *.pyi

‎README.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
python-json-pointer
22
===================
33

4-
[![PyPI version](https://img.shields.io/pypi/v/jsonpointer.svg)](https://pypi.python.org/pypi/jsonpointer/)
5-
[![Supported Python versions](https://img.shields.io/pypi/pyversions/jsonpointer.svg)](https://pypi.python.org/pypi/jsonpointer/)
4+
[![PyPI version](https://img.shields.io/pypi/v/jsonpointer.svg)](https://pypi.org/project/jsonpointer/)
5+
[![Supported Python versions](https://img.shields.io/pypi/pyversions/jsonpointer.svg)](https://pypi.org/project/jsonpointer/)
66
[![Tests](https://github.com/stefankoegl/python-json-pointer/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/stefankoegl/python-json-pointer/actions/workflows/test.yaml)
77
[![Coverage Status](https://coveralls.io/repos/github/stefankoegl/python-json-pointer/badge.svg?branch=master)](https://coveralls.io/github/stefankoegl/python-json-pointer?branch=master)
88

@@ -11,12 +11,13 @@ Resolve JSON Pointers in Python
1111
-------------------------------
1212

1313
Library to resolve JSON Pointers according to
14-
[RFC 6901](http://tools.ietf.org/html/rfc6901)
14+
[RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901)
15+
16+
See the documentation for examples.
1517

16-
See source code for examples
1718
* Website: https://github.com/stefankoegl/python-json-pointer
1819
* Repository: https://github.com/stefankoegl/python-json-pointer.git
19-
* Documentation: https://python-json-pointer.readthedocs.org/
20-
* PyPI: https://pypi.python.org/pypi/jsonpointer
20+
* Documentation: https://python-json-pointer.readthedocs.io/
21+
* PyPI: https://pypi.org/project/jsonpointer/
2122
* GitHub Actions: https://github.com/stefankoegl/python-json-pointer/actions
2223
* Coveralls: https://coveralls.io/github/stefankoegl/python-json-pointer

‎bin/jsonpointer‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(
1313
# Accept pointer as option, as file or as first positional argument
1414
ptr_group = parser.add_mutually_exclusive_group()
1515

16-
ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r', encoding='utf-8'),
16+
ptr_group.add_argument('-f', '--pointer-file', type=str,
1717
help='File containing a JSON pointer expression')
1818

1919
ptr_group.add_argument('-p', '--pointer', type=str,
@@ -37,14 +37,28 @@ def main():
3737
try:
3838
ok = resolve_files()
3939
except KeyboardInterrupt:
40-
sys.exit(1)
40+
# Conventional status for termination by SIGINT (128 + 2)
41+
sys.exit(130)
4142

4243
if not ok:
4344
sys.exit(1)
4445

4546

47+
def open_input(name):
48+
""" Open a UTF-8 input file, or return stdin for "-"
49+
50+
Exits with a usage error if the file cannot be opened. """
51+
if name == '-':
52+
return sys.stdin
53+
54+
try:
55+
return open(name, encoding='utf-8')
56+
except OSError as e:
57+
parser.error("can't open '%s': %s" % (name, e))
58+
59+
4660
def parse_pointer(args):
47-
""" Return the pointer and the list of files to resolve it on
61+
""" Return the parsed pointer and the list of files to resolve it on
4862
4963
If the pointer is given via -f or -p, a POINTER positional argument is
5064
actually the first file. """
@@ -57,14 +71,16 @@ def parse_pointer(args):
5771
if args.pointer is not None:
5872
ptr = args.pointer
5973
else:
60-
# 2026-10-11: Trim file line endings without changing member names.
74+
# Strip only the trailing line ending; other whitespace may be
75+
# part of a member name.
76+
pointer_file = open_input(args.pointer_file)
6177
try:
62-
ptr = args.pointer_file.read().rstrip("\r\n")
78+
ptr = pointer_file.read().rstrip("\r\n")
6379
except UnicodeDecodeError as e:
6480
parser.error('could not decode pointer file: %s' % e)
6581
finally:
66-
if args.pointer_file is not sys.stdin:
67-
args.pointer_file.close()
82+
if pointer_file is not sys.stdin:
83+
pointer_file.close()
6884

6985
elif args.POINTER is not None:
7086
ptr = args.POINTER
@@ -75,11 +91,11 @@ def parse_pointer(args):
7591
# Catches e.g. `jsonpointer a.json b.json`, where the pointer was omitted
7692
# and the first file would otherwise be used as the pointer
7793
try:
78-
jsonpointer.JsonPointer(ptr)
94+
pointer = jsonpointer.JsonPointer(ptr)
7995
except jsonpointer.JsonPointerException as e:
8096
parser.error('invalid JSON pointer %r: %s' % (ptr, e))
8197

82-
return ptr, files
98+
return pointer, files
8399

84100

85101
def resolve_files():
@@ -89,14 +105,11 @@ def resolve_files():
89105
or if --continue-on-error skipped a JSON or text decoding error. """
90106
args = parser.parse_args()
91107

92-
ptr, files = parse_pointer(args)
108+
pointer, files = parse_pointer(args)
93109
ok = True
94110

95111
for name in files:
96-
try:
97-
f = argparse.FileType('r', encoding='utf-8')(name)
98-
except argparse.ArgumentTypeError as e:
99-
parser.error(str(e))
112+
f = open_input(name)
100113

101114
try:
102115
doc = json.load(f)
@@ -112,7 +125,7 @@ def resolve_files():
112125
f.close()
113126

114127
try:
115-
result = jsonpointer.resolve_pointer(doc, ptr)
128+
result = pointer.resolve(doc)
116129
if isinstance(result, jsonpointer.EndOfList):
117130
raise jsonpointer.JsonPointerException(
118131
"'-' does not reference an existing array element")

‎doc/_static/.empty‎

Whitespace-only changes.

‎doc/commandline.rst‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ The ``jsonpointer`` commandline utility
22
=======================================
33

44
The JSON pointer package also installs a ``jsonpointer`` commandline utility
5-
that can be used to resolve a JSON pointers on JSON files.
5+
that can be used to resolve a JSON pointer on JSON files.
66

77
The program has the following usage ::
88

@@ -19,9 +19,9 @@ The program has the following usage ::
1919

2020
options:
2121
-h, --help show this help message and exit
22-
-f POINTER_FILE, --pointer-file POINTER_FILE
22+
-f, --pointer-file POINTER_FILE
2323
File containing a JSON pointer expression
24-
-p POINTER, --pointer POINTER
24+
-p, --pointer POINTER
2525
A JSON pointer expression
2626
--indent INDENT Indent output by n spaces
2727
--continue-on-error Continue with remaining files after JSON or text
@@ -35,8 +35,8 @@ JSON input files and pointer files are read as UTF-8.
3535

3636
The exit status is 0 if the pointer could be resolved on all files, 1 if it
3737
could not be resolved on at least one file (the remaining files are still
38-
processed) and 2 on usage errors, such as an invalid pointer or a missing
39-
file.
38+
processed), 2 on usage errors, such as an invalid pointer or a missing
39+
file, and 130 if interrupted with Ctrl-C.
4040

4141
By default, invalid JSON or a text decoding error stops processing. With
4242
``--continue-on-error``, these errors are reported on standard error with

0 commit comments

Comments
 (0)