Skip to content

Commit fc4d81b

Browse files
committed
modify the CI files
1 parent a2d1090 commit fc4d81b

5 files changed

Lines changed: 17 additions & 19 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
18+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
1919
os: [ubuntu-latest, macos-latest, windows-latest]
2020

2121
steps:
@@ -34,8 +34,8 @@ jobs:
3434
3535
- name: Lint with flake8
3636
run: |
37-
flake8 jsonfmt.py --count --select=E9,F63,F7,F82 --show-source --statistics
38-
flake8 jsonfmt.py --count --exit-zero --max-complexity=10 --max-line-length=90 --statistics
37+
flake8 jsonfmt/*.py --count --select=E9,F63,F7,F82 --show-source --statistics
38+
flake8 jsonfmt/*.py --count --exit-zero --max-complexity=15 --max-line-length=120 --statistics
3939
4040
- name: Test with pytest
41-
run: pytest test/test.py
41+
run: pytest test/

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
pip install -r requirements.txt
3434
3535
- name: Test with pytest
36-
run: pytest test/test.py
36+
run: pytest test/
3737

3838
- name: Build package
3939
run: python -m build

jsonfmt/jsonfmt.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ def get_output_fp(input_file: IO, cp2clip: bool, diff: bool,
196196
return TEMP_CLIPBOARD
197197
elif diff:
198198
name = f"_{os.path.basename(input_file.name)}"
199-
return NamedTemporaryFile(mode='w+', prefix='jf-', suffix=name,
200-
delete=False, delete_on_close=False)
199+
return NamedTemporaryFile(mode='w+', prefix='jf-', suffix=name, delete=False)
201200
elif input_file is sys.stdin or overview:
202201
return sys.stdout
203202
elif overwrite:
@@ -361,11 +360,9 @@ def main():
361360
pyperclip.copy(TEMP_CLIPBOARD.read())
362361
utils.print_inf('result copied to clipboard')
363362
elif diff_mode:
364-
if len(diff_files) < 2:
365-
utils.exit_with_error('not enougth files to compare')
366363
try:
367364
compare(diff_files[0], diff_files[1], args.difftool)
368-
except (OSError, ValueError) as err:
365+
except (OSError, ValueError, IndexError) as err:
369366
utils.exit_with_error(err)
370367

371368

jsonfmt/xml2py.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
import sys
12
import xml.etree.ElementTree as ET
23
from collections.abc import Mapping
34
from copy import deepcopy
4-
from typing import Any, Optional, Self
55
from xml.dom.minidom import parseString
66

77
from .utils import safe_eval, sort_dict
88

9+
if sys.version_info < (3, 11):
10+
from typing import Any, Dict, Optional, TypeVar, Union
11+
Self = TypeVar('Self', bound='XmlElement')
12+
else:
13+
from typing import Any, Dict, Optional, Self, Union
14+
915

1016
class _list(list):
1117
pass
@@ -29,7 +35,7 @@ def makeelement(cls, tag, attrib, text=None, tail=None) -> Self:
2935
return cls(tag, attrib, text, tail)
3036

3137
@classmethod
32-
def clone(cls, src: Self | ET.Element, dst: Optional[Self] = None) -> Self:
38+
def clone(cls, src: Union[Self, ET.Element], dst: Optional[Self] = None) -> Self:
3339
if dst is None:
3440
dst = cls(src.tag, src.attrib, src.text, src.tail)
3541

@@ -46,7 +52,7 @@ def from_xml(cls, xml: str) -> Self:
4652

4753
def to_xml(self,
4854
minimal: Optional[bool] = None,
49-
indent: Optional[int | str] = 2
55+
indent: Optional[Union[int, str]] = 2
5056
) -> str:
5157
ele = deepcopy(self)
5258
for e in ele.iter():
@@ -73,7 +79,7 @@ def spawn(self, tag: str, attrib={}, text=None, tail=None, **extra) -> Self:
7379
self.append(child)
7480
return child
7581

76-
def _get_attrs(self) -> Optional[dict[str, Any]]:
82+
def _get_attrs(self) -> Optional[Dict[str, Any]]:
7783
attrs = {f'@{k}': safe_eval(v) for k, v in self.attrib.items()}
7884

7985
if len(self) == 0:

test/test_jsonfmt.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,6 @@ def test_main_diff_mode(self):
509509
jsonfmt.main()
510510
self.assertIn('less than two files', sys.stderr.read())
511511

512-
with patch.multiple(sys, argv=['jf', '-D', 'diff', XML_FILE, 'null']), \
513-
self.assertRaises(SystemExit):
514-
jsonfmt.main()
515-
self.assertIn('not enougth files to compare', sys.stderr.read())
516-
517512
with patch.multiple(sys, argv=['jf', '-D', 'nothing', XML_FILE, TOML_FILE]), \
518513
self.assertRaises(SystemExit):
519514
jsonfmt.main()

0 commit comments

Comments
 (0)