From bd3fe9bb00ef9a9ffc693396f8cc3afbede629eb Mon Sep 17 00:00:00 2001 From: "Reid D. 'arrdem' McKenzie" Date: Tue, 31 May 2022 09:41:10 -0600 Subject: [PATCH] Fmt. --- projects/archiver/org_photos.py | 2 +- .../src/python/shogoth/analyzer/__init__.py | 1 - .../src/python/shogoth/analyzer/impl.py | 7 +++++- .../src/python/shogoth/reader/__init__.py | 1 - .../shogoth/src/python/shogoth/reader/impl.py | 9 +++++++- .../src/python/shogoth/repl/__main__.py | 22 +++++++++---------- .../src/python/shogoth/types/__init__.py | 4 ---- .../shogoth/src/python/shogoth/vm/__init__.py | 2 +- .../src/python/shogoth/vm/bootstrap.py | 2 ++ .../shogoth/src/python/shogoth/vm/impl.py | 2 ++ projects/shogoth/src/python/shogoth/vm/isa.py | 2 +- .../test/python/shogoth/vm/fixtures.py | 1 - .../python/shogoth/vm/parser/test_parser.py | 7 +++--- .../test/python/shogoth/vm/test_bootstrap.py | 16 +++++++------- .../python/shogoth/vm/test_interpreter.py | 4 ++-- 15 files changed, 44 insertions(+), 38 deletions(-) diff --git a/projects/archiver/org_photos.py b/projects/archiver/org_photos.py index ad1f2ef..fd96cd5 100644 --- a/projects/archiver/org_photos.py +++ b/projects/archiver/org_photos.py @@ -22,9 +22,9 @@ from hashlib import sha256, sha512 from pathlib import Path import re from shutil import copy2 as copyfile +import stat import sys import typing as t -import stat from .util import * diff --git a/projects/shogoth/src/python/shogoth/analyzer/__init__.py b/projects/shogoth/src/python/shogoth/analyzer/__init__.py index c5b87bd..c7113b2 100644 --- a/projects/shogoth/src/python/shogoth/analyzer/__init__.py +++ b/projects/shogoth/src/python/shogoth/analyzer/__init__.py @@ -2,4 +2,3 @@ """A syntax analyzer for Shogoth.""" -from .impl import * diff --git a/projects/shogoth/src/python/shogoth/analyzer/impl.py b/projects/shogoth/src/python/shogoth/analyzer/impl.py index 3da0b51..bad5294 100644 --- a/projects/shogoth/src/python/shogoth/analyzer/impl.py +++ b/projects/shogoth/src/python/shogoth/analyzer/impl.py @@ -6,7 +6,12 @@ from abc import ABC from dataclasses import dataclass import typing as t -from shogoth.types import List, Vec, Keyword, Symbol +from shogoth.types import ( + Keyword, + List, + Symbol, + Vec, +) @dataclass diff --git a/projects/shogoth/src/python/shogoth/reader/__init__.py b/projects/shogoth/src/python/shogoth/reader/__init__.py index 05ebd3d..63f77b6 100644 --- a/projects/shogoth/src/python/shogoth/reader/__init__.py +++ b/projects/shogoth/src/python/shogoth/reader/__init__.py @@ -1,3 +1,2 @@ #!/usr/bin/env python3 -from .impl import * diff --git a/projects/shogoth/src/python/shogoth/reader/impl.py b/projects/shogoth/src/python/shogoth/reader/impl.py index c686e76..9c428f4 100644 --- a/projects/shogoth/src/python/shogoth/reader/impl.py +++ b/projects/shogoth/src/python/shogoth/reader/impl.py @@ -3,6 +3,8 @@ """The shogoth reader.""" import sys + + assert sys.version_info > (3, 10, 0), "`match` support is required" import re @@ -10,7 +12,12 @@ from typing import Any from lark import Token, Tree from shogoth.parser import parse -from shogoth.types import Keyword, Symbol, List, Vec +from shogoth.types import ( + Keyword, + List, + Symbol, + Vec, +) # Monkeypatching for py3.10 matching diff --git a/projects/shogoth/src/python/shogoth/repl/__main__.py b/projects/shogoth/src/python/shogoth/repl/__main__.py index adbd570..8813229 100644 --- a/projects/shogoth/src/python/shogoth/repl/__main__.py +++ b/projects/shogoth/src/python/shogoth/repl/__main__.py @@ -1,18 +1,16 @@ """A testing REPL.""" -from shogoth.reader import Reader -from shogoth.types import Symbol -from shogoth.analyzer import Analyzer, SPECIALS, GLOBALS, Namespace - -from prompt_toolkit import ( - print_formatted_text, - PromptSession, -) -from prompt_toolkit.formatted_text import ( - FormattedText, -) +from prompt_toolkit import PromptSession from prompt_toolkit.history import FileHistory from prompt_toolkit.styles import Style +from shogoth.analyzer import ( + Analyzer, + GLOBALS, + Namespace, + SPECIALS, +) +from shogoth.reader import Reader +from shogoth.types import Symbol from yaspin import Spinner, yaspin @@ -49,7 +47,7 @@ def main(): with yaspin(SPINNER): expr = analyzer.analyze(ns, read) - print('analyze ]', expr, type(expr)) + print("analyze ]", expr, type(expr)) if __name__ == "__main__": diff --git a/projects/shogoth/src/python/shogoth/types/__init__.py b/projects/shogoth/src/python/shogoth/types/__init__.py index 3490332..5536f44 100644 --- a/projects/shogoth/src/python/shogoth/types/__init__.py +++ b/projects/shogoth/src/python/shogoth/types/__init__.py @@ -1,11 +1,7 @@ """The public interface for shogoth's baked-in types.""" -from .keyword import Keyword -from .symbol import Symbol -from abc import ABC import typing as t - from uuid import UUID, uuid4 diff --git a/projects/shogoth/src/python/shogoth/vm/__init__.py b/projects/shogoth/src/python/shogoth/vm/__init__.py index 88637e3..ab10030 100644 --- a/projects/shogoth/src/python/shogoth/vm/__init__.py +++ b/projects/shogoth/src/python/shogoth/vm/__init__.py @@ -1,5 +1,5 @@ # noqa -from .isa import * # noqa from .bootstrap import * # noqa from .impl import * # noqa +from .isa import * # noqa diff --git a/projects/shogoth/src/python/shogoth/vm/bootstrap.py b/projects/shogoth/src/python/shogoth/vm/bootstrap.py index 2121af8..be535c3 100644 --- a/projects/shogoth/src/python/shogoth/vm/bootstrap.py +++ b/projects/shogoth/src/python/shogoth/vm/bootstrap.py @@ -5,8 +5,10 @@ Hopefully no "real" interpreter ever uses this code, since it's obviously replac """ from .isa import Module, Opcode + from shogoth.types import * + BOOTSTRAP = Module() NOT = BOOTSTRAP.define_function( diff --git a/projects/shogoth/src/python/shogoth/vm/impl.py b/projects/shogoth/src/python/shogoth/vm/impl.py index af5a895..b36ee74 100644 --- a/projects/shogoth/src/python/shogoth/vm/impl.py +++ b/projects/shogoth/src/python/shogoth/vm/impl.py @@ -18,6 +18,8 @@ context (a virtual machine) which DOES have an easily introspected and serialize import sys + + assert sys.version_info > (3, 10, 0), "`match` support is required" from copy import deepcopy diff --git a/projects/shogoth/src/python/shogoth/vm/isa.py b/projects/shogoth/src/python/shogoth/vm/isa.py index 6ca8657..c601625 100644 --- a/projects/shogoth/src/python/shogoth/vm/isa.py +++ b/projects/shogoth/src/python/shogoth/vm/isa.py @@ -3,7 +3,7 @@ from typing import NamedTuple -from shogoth.types import Function, FunctionRef +from shogoth.types import FunctionRef class Opcode: diff --git a/projects/shogoth/test/python/shogoth/vm/fixtures.py b/projects/shogoth/test/python/shogoth/vm/fixtures.py index cd9bd89..e092db2 100644 --- a/projects/shogoth/test/python/shogoth/vm/fixtures.py +++ b/projects/shogoth/test/python/shogoth/vm/fixtures.py @@ -3,7 +3,6 @@ import pytest from shogoth.vm import * -import pytest @pytest.fixture def vm(): diff --git a/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py b/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py index 5f1ed2d..15c8802 100644 --- a/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py +++ b/projects/shogoth/test/python/shogoth/vm/parser/test_parser.py @@ -1,17 +1,16 @@ #!/usr/bin/env python3 +import pytest from shogoth.parser import parse -import pytest - -@pytest.mark.parametrize('example', [ +@pytest.mark.parametrize("example", [ "true", "false", "nil", "foo", '"this is a trivial string"', - r'/this is a trivial pattern/', + r"/this is a trivial pattern/", "[]", "[[]]", "[[[]]]", diff --git a/projects/shogoth/test/python/shogoth/vm/test_bootstrap.py b/projects/shogoth/test/python/shogoth/vm/test_bootstrap.py index 262196c..40ba9b1 100644 --- a/projects/shogoth/test/python/shogoth/vm/test_bootstrap.py +++ b/projects/shogoth/test/python/shogoth/vm/test_bootstrap.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 +from .fixtures import * # noqa + import pytest from shogoth.vm import * -from .fixtures import * # noqa - -@pytest.mark.parametrize('stack,ret', [ +@pytest.mark.parametrize("stack,ret", [ [[True], [False]], [[True], [False]], ]) @@ -14,7 +14,7 @@ def test_not(vm, stack, ret): assert vm.run([Opcode.CALLS(NOT)], stack = stack) == ret -@pytest.mark.parametrize('stack,ret', [ +@pytest.mark.parametrize("stack,ret", [ [[False, False], [False]], [[True, False], [True]], [[False, True], [True]], @@ -24,7 +24,7 @@ def test_or(vm, stack, ret): assert vm.run([Opcode.CALLS(OR)], stack = stack) == ret -@pytest.mark.parametrize('stack,ret', [ +@pytest.mark.parametrize("stack,ret", [ [[False, False], [False]], [[True, False], [False]], [[False, True], [False]], @@ -34,7 +34,7 @@ def test_and(vm, stack, ret): assert vm.run([Opcode.CALLS(AND)], stack = stack) == ret -@pytest.mark.parametrize('stack,ret', [ +@pytest.mark.parametrize("stack,ret", [ [[False, False], [False]], [[True, False], [True]], [[False, True], [True]], @@ -44,14 +44,14 @@ def test_xor(vm, stack, ret): assert vm.run([Opcode.CALLS(XOR)], stack = stack) == ret -@pytest.mark.parametrize('stack,ret', [ +@pytest.mark.parametrize("stack,ret", [ [[], [FunctionRef.parse(NOT)]] ]) def test_funref(vm, stack, ret): assert vm.run([Opcode.FUNREF(NOT), Opcode.RETURN(1)], stack = stack) == ret -@pytest.mark.parametrize('stack,ret', [ +@pytest.mark.parametrize("stack,ret", [ [[], [True]] ]) def test_callf(vm, stack, ret): diff --git a/projects/shogoth/test/python/shogoth/vm/test_interpreter.py b/projects/shogoth/test/python/shogoth/vm/test_interpreter.py index 11697ed..d9157f6 100644 --- a/projects/shogoth/test/python/shogoth/vm/test_interpreter.py +++ b/projects/shogoth/test/python/shogoth/vm/test_interpreter.py @@ -2,11 +2,11 @@ Tests coverign the VM interpreter """ +from .fixtures import * # noqa + import pytest from shogoth.vm import * -from .fixtures import * # noqa - def test_true(vm): assert vm.run([Opcode.TRUE(), Opcode.RETURN(1)]) == [True]