Skip to content

Commit f3643ad

Browse files
authored
Merge pull request #60 from cunla/master
Remove python 2.7
2 parents 4c47628 + cce7ed2 commit f3643ad

File tree

8 files changed

+80
-78
lines changed

8 files changed

+80
-78
lines changed

Diff for: .github/workflows/test.yaml

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,58 @@
11
name: Python package
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
6-
build:
12+
lint:
13+
name: "flake8 on code"
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.ref }}
21+
22+
- name: Set up Python 3.12
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.12
26+
allow-prereleases: true
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install flake8
31+
- name: Run flake8
32+
shell: bash
33+
run: |
34+
flake8
735
36+
test:
37+
needs: [ lint ]
838
runs-on: ubuntu-latest
939
strategy:
1040
fail-fast: false
1141
matrix:
12-
python-version: ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
42+
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
1343

1444
steps:
1545
- uses: actions/checkout@v4
1646
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v4
47+
uses: actions/setup-python@v5
1848
with:
1949
python-version: ${{ matrix.python-version }}
2050
allow-prereleases: true
2151
- name: Install dependencies
2252
run: |
2353
python -m pip install --upgrade pip
24-
pip install flake8 pytest
25-
pip install coveralls
26-
# - name: Lint with flake8
27-
# run: |
28-
# stop the build if there are Python syntax errors or undefined names
29-
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
30-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
31-
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
54+
pip install -r requirements-dev.txt
55+
3256
- name: Test
3357
run: |
3458
make coverage

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist
66
*.swp
77
doc/_build
88
*.egg-info
9+
.idea

Diff for: bin/jsonpointer

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from __future__ import print_function
54

6-
import sys
7-
import os.path
8-
import json
9-
import jsonpointer
105
import argparse
6+
import json
7+
import sys
118

9+
import jsonpointer
1210

1311
parser = argparse.ArgumentParser(
1412
description='Resolve a JSON pointer on JSON files')
@@ -20,7 +18,7 @@ ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r'),
2018
nargs='?',
2119
help='File containing a JSON pointer expression')
2220

23-
ptr_group.add_argument('POINTER', type=str, nargs='?',
21+
ptr_group.add_argument('POINTER', type=str, nargs='?',
2422
help='A JSON pointer expression')
2523

2624
parser.add_argument('FILE', type=argparse.FileType('r'), nargs='+',

Diff for: jsonpointer.py

+14-32
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,22 @@
3232

3333
""" Identify specific nodes in a JSON document (RFC 6901) """
3434

35-
from __future__ import unicode_literals
36-
3735
# Will be parsed by setup.py to determine package metadata
3836
__author__ = 'Stefan Kögl <[email protected]>'
39-
__version__ = '2.4'
37+
__version__ = '3.0.0'
4038
__website__ = 'https://github.com/stefankoegl/python-json-pointer'
4139
__license__ = 'Modified BSD License'
4240

43-
44-
try:
45-
from itertools import izip
46-
str = unicode
47-
encode_str = lambda u: u.encode("raw_unicode_escape")
48-
except ImportError: # Python 3
49-
izip = zip
50-
encode_str = lambda u: u
51-
52-
try:
53-
from collections.abc import Mapping, Sequence
54-
except ImportError: # Python 3
55-
from collections import Mapping, Sequence
56-
57-
from itertools import tee, chain
58-
import re
5941
import copy
60-
42+
import re
43+
from collections.abc import Mapping, Sequence
44+
from itertools import tee, chain
6145

6246
_nothing = object()
6347

6448

6549
def set_pointer(doc, pointer, value, inplace=True):
66-
"""Resolves pointer against doc and sets the value of the target within doc.
50+
"""Resolves a pointer against doc and sets the value of the target within doc.
6751
6852
With inplace set to true, doc is modified as long as pointer is not the
6953
root.
@@ -145,7 +129,7 @@ def pairwise(iterable):
145129
a, b = tee(iterable)
146130
for _ in b:
147131
break
148-
return izip(a, b)
132+
return zip(a, b)
149133

150134

151135
class JsonPointerException(Exception):
@@ -259,12 +243,11 @@ def get_part(cls, doc, part):
259243
else:
260244
raise JsonPointerException("Document '%s' does not support indexing, "
261245
"must be mapping/sequence or support __getitem__" % type(doc))
262-
246+
263247
def get_parts(self):
264248
"""Returns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b']"""
265-
266-
return self.parts
267249

250+
return self.parts
268251

269252
def walk(self, doc, part):
270253
""" Walks one step in doc and returns the referenced part """
@@ -281,7 +264,7 @@ def walk(self, doc, part):
281264
return doc[part]
282265

283266
except IndexError:
284-
raise JsonPointerException("index '%s' is out of bounds" % (part, ))
267+
raise JsonPointerException("index '%s' is out of bounds" % (part,))
285268

286269
# Else the object is a mapping or supports __getitem__(so assume custom indexing)
287270
try:
@@ -290,7 +273,6 @@ def walk(self, doc, part):
290273
except KeyError:
291274
raise JsonPointerException("member '%s' not found in %s" % (part, doc))
292275

293-
294276
def contains(self, ptr):
295277
""" Returns True if self contains the given ptr """
296278
return self.parts[:len(ptr.parts)] == ptr.parts
@@ -309,12 +291,11 @@ def join(self, suffix):
309291
suffix_parts = suffix
310292
try:
311293
return JsonPointer.from_parts(chain(self.parts, suffix_parts))
312-
except:
294+
except: # noqa E722
313295
raise JsonPointerException("Invalid suffix")
314296

315-
def __truediv__(self, suffix): # Python 3
297+
def __truediv__(self, suffix): # Python 3
316298
return self.join(suffix)
317-
__div__ = __truediv__ # Python 2
318299

319300
@property
320301
def path(self):
@@ -342,10 +323,10 @@ def __hash__(self):
342323
return hash(tuple(self.parts))
343324

344325
def __str__(self):
345-
return encode_str(self.path)
326+
return self.path
346327

347328
def __repr__(self):
348-
return "JsonPointer(" + repr(self.path) + ")"
329+
return type(self).__name__ + "(" + repr(self.path) + ")"
349330

350331
@classmethod
351332
def from_parts(cls, parts):
@@ -362,5 +343,6 @@ def from_parts(cls, parts):
362343
def escape(s):
363344
return s.replace('~', '~0').replace('/', '~1')
364345

346+
365347
def unescape(s):
366348
return s.replace('~1', '/').replace('~0', '~')

Diff for: requirements-dev.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
wheel
2-
twine>=1.11.0
3-
setuptools>=38.6.0
2+
setuptools
3+
coverage
4+
flake8

Diff for: setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[bdist_wheel]
22
universal = 1
3+
4+
[flake8]
5+
max-line-length = 120
6+
exclude = .git,.tox,dist,doc,*egg,build,.venv

Diff for: setup.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22

3-
from setuptools import setup
4-
import re
53
import io
64
import os.path
5+
import re
6+
7+
from setuptools import setup
78

89
dirname = os.path.dirname(os.path.abspath(__file__))
910
filename = os.path.join(dirname, 'jsonpointer.py')
@@ -14,7 +15,7 @@
1415
PACKAGE = 'jsonpointer'
1516

1617
MODULES = (
17-
'jsonpointer',
18+
'jsonpointer',
1819
)
1920

2021
AUTHOR_EMAIL = metadata['author']
@@ -26,10 +27,8 @@
2627
# Extract name and e-mail ("Firstname Lastname <[email protected]>")
2728
AUTHOR, EMAIL = re.match(r'(.*) <(.*)>', AUTHOR_EMAIL).groups()
2829

29-
3030
with open('README.md') as readme:
31-
long_description = readme.read()
32-
31+
long_description = readme.read()
3332

3433
CLASSIFIERS = [
3534
'Development Status :: 5 - Production/Stable',
@@ -38,8 +37,6 @@
3837
'License :: OSI Approved :: BSD License',
3938
'Operating System :: OS Independent',
4039
'Programming Language :: Python',
41-
'Programming Language :: Python :: 2',
42-
'Programming Language :: Python :: 2.7',
4340
'Programming Language :: Python :: 3',
4441
'Programming Language :: Python :: 3.7',
4542
'Programming Language :: Python :: 3.8',
@@ -65,5 +62,5 @@
6562
py_modules=MODULES,
6663
scripts=['bin/jsonpointer'],
6764
classifiers=CLASSIFIERS,
68-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*',
69-
)
65+
python_requires='>=3.7',
66+
)

0 commit comments

Comments
 (0)