build: convert to package
This commit is contained in:
parent
5bc1090fa4
commit
a071311ca1
|
@ -50,32 +50,32 @@ requires = ["poetry-core>=1.0"]
|
|||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
remarshal = 'remarshal:main'
|
||||
cbor2cbor = 'remarshal:main'
|
||||
cbor2json = 'remarshal:main'
|
||||
cbor2msgpack = 'remarshal:main'
|
||||
cbor2toml = 'remarshal:main'
|
||||
cbor2yaml = 'remarshal:main'
|
||||
json2cbor = 'remarshal:main'
|
||||
json2json = 'remarshal:main'
|
||||
json2msgpack = 'remarshal:main'
|
||||
json2toml = 'remarshal:main'
|
||||
json2yaml = 'remarshal:main'
|
||||
msgpack2cbor = 'remarshal:main'
|
||||
msgpack2json = 'remarshal:main'
|
||||
msgpack2msgpack = 'remarshal:main'
|
||||
msgpack2toml = 'remarshal:main'
|
||||
msgpack2yaml = 'remarshal:main'
|
||||
toml2cbor = 'remarshal:main'
|
||||
toml2json = 'remarshal:main'
|
||||
toml2msgpack = 'remarshal:main'
|
||||
toml2toml = 'remarshal:main'
|
||||
toml2yaml = 'remarshal:main'
|
||||
yaml2cbor = 'remarshal:main'
|
||||
yaml2json = 'remarshal:main'
|
||||
yaml2msgpack = 'remarshal:main'
|
||||
yaml2toml = 'remarshal:main'
|
||||
yaml2yaml = 'remarshal:main'
|
||||
remarshal = 'remarshal.main:main'
|
||||
cbor2cbor = 'remarshal.main:main'
|
||||
cbor2json = 'remarshal.main:main'
|
||||
cbor2msgpack = 'remarshal.main:main'
|
||||
cbor2toml = 'remarshal.main:main'
|
||||
cbor2yaml = 'remarshal.main:main'
|
||||
json2cbor = 'remarshal.main:main'
|
||||
json2json = 'remarshal.main:main'
|
||||
json2msgpack = 'remarshal.main:main'
|
||||
json2toml = 'remarshal.main:main'
|
||||
json2yaml = 'remarshal.main:main'
|
||||
msgpack2cbor = 'remarshal.main:main'
|
||||
msgpack2json = 'remarshal.main:main'
|
||||
msgpack2msgpack = 'remarshal.main:main'
|
||||
msgpack2toml = 'remarshal.main:main'
|
||||
msgpack2yaml = 'remarshal.main:main'
|
||||
toml2cbor = 'remarshal.main:main'
|
||||
toml2json = 'remarshal.main:main'
|
||||
toml2msgpack = 'remarshal.main:main'
|
||||
toml2toml = 'remarshal.main:main'
|
||||
toml2yaml = 'remarshal.main:main'
|
||||
yaml2cbor = 'remarshal.main:main'
|
||||
yaml2json = 'remarshal.main:main'
|
||||
yaml2msgpack = 'remarshal.main:main'
|
||||
yaml2toml = 'remarshal.main:main'
|
||||
yaml2yaml = 'remarshal.main:main'
|
||||
|
||||
[tool.pyright]
|
||||
pythonVersion = "3.8"
|
||||
|
@ -152,6 +152,6 @@ max-branches = 20
|
|||
max-statements = 100
|
||||
|
||||
[tool.ruff.per-file-ignores]
|
||||
"remarshal.py" = ["ARG001", "B904", "EM103", "RET506", "S506", "SIM115"]
|
||||
"remarshal/main.py" = ["ARG001", "B904", "EM103", "RET506", "S506", "SIM115"]
|
||||
"tests/test_remarshal.py" = ["F841", "PT011", "SLF001"]
|
||||
"tests/*" = ["S101"]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
from remarshal.main import * # noqa: F403
|
|
@ -0,0 +1,4 @@
|
|||
from remarshal.main import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -100,7 +100,8 @@ def _parse_command_line(argv: List[str]) -> argparse.Namespace: # noqa: C901.
|
|||
format_from_argv0 = argv0_to != ""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Convert between CBOR, JSON, MessagePack, TOML, and YAML."
|
||||
description="Convert between CBOR, JSON, MessagePack, TOML, and YAML.",
|
||||
prog="remarshal",
|
||||
)
|
||||
parser.add_argument("-v", "--version", action="version", version=__version__)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path("..").resolve()))
|
||||
|
||||
import remarshal as remarshal # noqa: E402, PLC0414
|
|
@ -19,7 +19,8 @@ from typing import Any, Callable, Dict, List, Tuple, Union
|
|||
import cbor2 # type: ignore
|
||||
import pytest
|
||||
|
||||
from .context import remarshal
|
||||
import remarshal
|
||||
from remarshal.main import _argv0_to_format, _parse_command_line
|
||||
|
||||
TEST_PATH = Path(__file__).resolve().parent
|
||||
|
||||
|
@ -39,7 +40,7 @@ def read_file(filename: str) -> bytes:
|
|||
|
||||
def run(*argv: str) -> None:
|
||||
# The `list()` call is to satisfy the type checker.
|
||||
args_d = vars(remarshal._parse_command_line(list(argv)))
|
||||
args_d = vars(_parse_command_line(list(argv)))
|
||||
sig = inspect.signature(remarshal.remarshal)
|
||||
re_args = {param: args_d[param] for param in sig.parameters if param in args_d}
|
||||
|
||||
|
@ -407,7 +408,7 @@ class TestRemarshal(unittest.TestCase):
|
|||
def test_format_string(s: str) -> None:
|
||||
for from_str in "json", "toml", "yaml":
|
||||
for to_str in "json", "toml", "yaml":
|
||||
from_parsed, to_parsed = remarshal._argv0_to_format(
|
||||
from_parsed, to_parsed = _argv0_to_format(
|
||||
s.format(from_str, to_str)
|
||||
)
|
||||
assert (from_parsed, to_parsed) == (from_str, to_str)
|
||||
|
@ -426,7 +427,7 @@ class TestRemarshal(unittest.TestCase):
|
|||
|
||||
for from_ext in ext_to_fmt:
|
||||
for to_ext in ext_to_fmt:
|
||||
args = remarshal._parse_command_line(
|
||||
args = _parse_command_line(
|
||||
[sys.argv[0], "input." + from_ext, "output." + to_ext]
|
||||
)
|
||||
|
||||
|
@ -435,17 +436,17 @@ class TestRemarshal(unittest.TestCase):
|
|||
|
||||
def test_format_detection_failure_input_stdin(self) -> None:
|
||||
with pytest.raises(SystemExit) as cm:
|
||||
remarshal._parse_command_line([sys.argv[0], "-"])
|
||||
_parse_command_line([sys.argv[0], "-"])
|
||||
assert cm.value.code == 2
|
||||
|
||||
def test_format_detection_failure_input_txt(self) -> None:
|
||||
with pytest.raises(SystemExit) as cm:
|
||||
remarshal._parse_command_line([sys.argv[0], "input.txt"])
|
||||
_parse_command_line([sys.argv[0], "input.txt"])
|
||||
assert cm.value.code == 2
|
||||
|
||||
def test_format_detection_failure_output_txt(self) -> None:
|
||||
with pytest.raises(SystemExit) as cm:
|
||||
remarshal._parse_command_line([sys.argv[0], "input.json", "output.txt"])
|
||||
_parse_command_line([sys.argv[0], "input.json", "output.txt"])
|
||||
assert cm.value.code == 2
|
||||
|
||||
def test_run_no_args(self) -> None:
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -6,7 +6,7 @@ env_list =
|
|||
py{38,39,310,311}
|
||||
|
||||
[base]
|
||||
source_files = remarshal.py tests/__init__.py tests/context.py tests/test_remarshal.py
|
||||
source_files = remarshal/__init__.py remarshal/__main__.py remarshal/main.py tests/__init__.py tests/test_remarshal.py
|
||||
|
||||
[testenv]
|
||||
description = run tests
|
||||
|
|
Loading…
Reference in New Issue