mirror of https://github.com/Nonannet/copapy.git
ruff config added for replacing flake8, code style und naming changes
This commit is contained in:
parent
6445ac9724
commit
a971b98f2d
24
.flake8
24
.flake8
|
|
@ -1,24 +0,0 @@
|
||||||
[flake8]
|
|
||||||
# Specify the maximum allowed line length
|
|
||||||
max-line-length = 88
|
|
||||||
|
|
||||||
# Ignore specific rules
|
|
||||||
# For example, E501: Line too long, W503: Line break before binary operator
|
|
||||||
ignore = E501, W503, W504, E226, E265
|
|
||||||
|
|
||||||
# Exclude specific files or directories
|
|
||||||
exclude =
|
|
||||||
.git,
|
|
||||||
__pycache__,
|
|
||||||
build,
|
|
||||||
dist,
|
|
||||||
.conda,
|
|
||||||
.venv
|
|
||||||
|
|
||||||
# Enable specific plugins or options
|
|
||||||
# Example: Enabling flake8-docstrings
|
|
||||||
select = C,E,F,W,D
|
|
||||||
|
|
||||||
# Specify custom error codes to ignore or enable
|
|
||||||
per-file-ignores =
|
|
||||||
tests/*: D, E712
|
|
||||||
|
|
@ -32,7 +32,7 @@ copapy = ["obj/*.o", "py.typed"]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
"flake8",
|
"ruff",
|
||||||
"mypy",
|
"mypy",
|
||||||
"pytest"
|
"pytest"
|
||||||
]
|
]
|
||||||
|
|
@ -50,4 +50,23 @@ show_error_codes = true
|
||||||
minversion = "6.0"
|
minversion = "6.0"
|
||||||
addopts = "-ra -q"
|
addopts = "-ra -q"
|
||||||
testpaths = ["tests"]
|
testpaths = ["tests"]
|
||||||
pythonpath = ["src"]
|
pythonpath = ["src"]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
lint.ignore = ["E501", "E226", "E265"]
|
||||||
|
|
||||||
|
# Equivalent to Flake8's "exclude"
|
||||||
|
exclude = [
|
||||||
|
".git",
|
||||||
|
"__pycache__",
|
||||||
|
"build",
|
||||||
|
"dist",
|
||||||
|
".conda",
|
||||||
|
".venv",
|
||||||
|
]
|
||||||
|
|
||||||
|
# "D" for dockstrings
|
||||||
|
lint.select = ["C", "E", "F", "W"]
|
||||||
|
|
||||||
|
[tool.ruff.lint.per-file-ignores]
|
||||||
|
"tests/*" = ["D", "E712"]
|
||||||
|
|
|
||||||
|
|
@ -161,11 +161,11 @@ class variable(Generic[TNum], Net):
|
||||||
def __lt__(self, other: NumLike) -> 'variable[bool]':
|
def __lt__(self, other: NumLike) -> 'variable[bool]':
|
||||||
ret = add_op('gt', [other, self])
|
ret = add_op('gt', [other, self])
|
||||||
return variable(ret.source, dtype='bool')
|
return variable(ret.source, dtype='bool')
|
||||||
|
|
||||||
def __ge__(self, other: NumLike) -> 'variable[bool]':
|
def __ge__(self, other: NumLike) -> 'variable[bool]':
|
||||||
ret = add_op('ge', [self, other])
|
ret = add_op('ge', [self, other])
|
||||||
return variable(ret.source, dtype='bool')
|
return variable(ret.source, dtype='bool')
|
||||||
|
|
||||||
def __le__(self, other: NumLike) -> 'variable[bool]':
|
def __le__(self, other: NumLike) -> 'variable[bool]':
|
||||||
ret = add_op('ge', [other, self])
|
ret = add_op('ge', [other, self])
|
||||||
return variable(ret.source, dtype='bool')
|
return variable(ret.source, dtype='bool')
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ COMMAND_SIZE = 4
|
||||||
|
|
||||||
class data_writer():
|
class data_writer():
|
||||||
def __init__(self, byteorder: ByteOrder):
|
def __init__(self, byteorder: ByteOrder):
|
||||||
self._data: list[tuple[str, bytes, int]] = list()
|
self._data: list[tuple[str, bytes, int]] = []
|
||||||
self.byteorder: ByteOrder = byteorder
|
self.byteorder: ByteOrder = byteorder
|
||||||
|
|
||||||
def write_int(self, value: int, num_bytes: int = 4, signed: bool = False) -> None:
|
def write_int(self, value: int, num_bytes: int = 4, signed: bool = False) -> None:
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,3 @@ def abs(x: T) -> T:
|
||||||
ret = (x < 0) * -x + (x >= 0) * x
|
ret = (x < 0) * -x + (x >= 0) * x
|
||||||
return ret # pyright: ignore[reportReturnType]
|
return ret # pyright: ignore[reportReturnType]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from coparun_module import coparun, read_data_mem
|
||||||
import struct
|
import struct
|
||||||
from ._basic_types import stencil_db_from_package
|
from ._basic_types import stencil_db_from_package
|
||||||
from ._basic_types import variable, Net, Node, Write, NumLike
|
from ._basic_types import variable, Net, Node, Write, NumLike
|
||||||
from ._compiler import compile_to_instruction_list
|
from ._compiler import compile_to_dag
|
||||||
|
|
||||||
|
|
||||||
def add_read_command(dw: binw.data_writer, variables: dict[Net, tuple[int, int, str]], net: Net) -> None:
|
def add_read_command(dw: binw.data_writer, variables: dict[Net, tuple[int, int, str]], net: Net) -> None:
|
||||||
|
|
@ -18,7 +18,7 @@ def add_read_command(dw: binw.data_writer, variables: dict[Net, tuple[int, int,
|
||||||
class Target():
|
class Target():
|
||||||
def __init__(self, arch: str = 'native', optimization: str = 'O3') -> None:
|
def __init__(self, arch: str = 'native', optimization: str = 'O3') -> None:
|
||||||
self.sdb = stencil_db_from_package(arch, optimization)
|
self.sdb = stencil_db_from_package(arch, optimization)
|
||||||
self._variables: dict[Net, tuple[int, int, str]] = dict()
|
self._variables: dict[Net, tuple[int, int, str]] = {}
|
||||||
|
|
||||||
def compile(self, *variables: int | float | variable[int] | variable[float] | variable[bool] | Iterable[int | float | variable[int] | variable[float] | variable[bool]]) -> None:
|
def compile(self, *variables: int | float | variable[int] | variable[float] | variable[bool] | Iterable[int | float | variable[int] | variable[float] | variable[bool]]) -> None:
|
||||||
nodes: list[Node] = []
|
nodes: list[Node] = []
|
||||||
|
|
@ -30,7 +30,7 @@ class Target():
|
||||||
else:
|
else:
|
||||||
nodes.append(Write(s))
|
nodes.append(Write(s))
|
||||||
|
|
||||||
dw, self._variables = compile_to_instruction_list(nodes, self.sdb)
|
dw, self._variables = compile_to_dag(nodes, self.sdb)
|
||||||
dw.write_com(binw.Command.END_COM)
|
dw.write_com(binw.Command.END_COM)
|
||||||
assert coparun(dw.get_data()) > 0
|
assert coparun(dw.get_data()) > 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from ._target import add_read_command
|
from ._target import add_read_command
|
||||||
from ._basic_types import Net, Op, Node, CPConstant, Write
|
from ._basic_types import Net, Op, Node, CPConstant, Write
|
||||||
from ._compiler import compile_to_instruction_list, \
|
from ._compiler import compile_to_dag, \
|
||||||
stable_toposort, get_const_nets, get_all_dag_edges, add_read_ops, \
|
stable_toposort, get_const_nets, get_all_dag_edges, add_read_ops, \
|
||||||
add_write_ops
|
add_write_ops
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ __all__ = [
|
||||||
"Node",
|
"Node",
|
||||||
"CPConstant",
|
"CPConstant",
|
||||||
"Write",
|
"Write",
|
||||||
"compile_to_instruction_list",
|
"compile_to_dag",
|
||||||
"stable_toposort",
|
"stable_toposort",
|
||||||
"get_const_nets",
|
"get_const_nets",
|
||||||
"get_all_dag_edges",
|
"get_all_dag_edges",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from copapy import variable, NumLike
|
from copapy import variable, NumLike
|
||||||
from copapy.backend import Write, compile_to_instruction_list, add_read_command
|
from copapy.backend import Write, compile_to_dag, add_read_command
|
||||||
import copapy
|
import copapy
|
||||||
import subprocess
|
import subprocess
|
||||||
import struct
|
import struct
|
||||||
|
|
@ -49,7 +49,7 @@ def test_compile():
|
||||||
|
|
||||||
out = [Write(r) for r in ret]
|
out = [Write(r) for r in ret]
|
||||||
|
|
||||||
il, variables = compile_to_instruction_list(out, copapy.generic_sdb)
|
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||||
|
|
||||||
# run program command
|
# run program command
|
||||||
il.write_com(_binwrite.Command.RUN_PROG)
|
il.write_com(_binwrite.Command.RUN_PROG)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from copapy import variable, NumLike
|
from copapy import variable, NumLike
|
||||||
from copapy.backend import Write, compile_to_instruction_list
|
from copapy.backend import Write, compile_to_dag
|
||||||
import copapy
|
import copapy
|
||||||
import subprocess
|
import subprocess
|
||||||
from copapy import _binwrite
|
from copapy import _binwrite
|
||||||
|
|
@ -26,7 +26,7 @@ def test_compile():
|
||||||
|
|
||||||
out = [Write(r) for r in ret]
|
out = [Write(r) for r in ret]
|
||||||
|
|
||||||
il, _ = compile_to_instruction_list(out, copapy.generic_sdb)
|
il, _ = compile_to_dag(out, copapy.generic_sdb)
|
||||||
|
|
||||||
# run program command
|
# run program command
|
||||||
il.write_com(_binwrite.Command.RUN_PROG)
|
il.write_com(_binwrite.Command.RUN_PROG)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from coparun_module import coparun
|
from coparun_module import coparun
|
||||||
from copapy import variable
|
from copapy import variable
|
||||||
from copapy.backend import Write, compile_to_instruction_list, add_read_command
|
from copapy.backend import Write, compile_to_dag, add_read_command
|
||||||
import copapy
|
import copapy
|
||||||
from copapy import _binwrite
|
from copapy import _binwrite
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@ def test_compile():
|
||||||
r2 = i1 + 9
|
r2 = i1 + 9
|
||||||
out = [Write(r1), Write(r2), Write(c2)]
|
out = [Write(r1), Write(r2), Write(c2)]
|
||||||
|
|
||||||
il, variables = compile_to_instruction_list(out, copapy.generic_sdb)
|
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||||
|
|
||||||
# run program command
|
# run program command
|
||||||
il.write_com(_binwrite.Command.RUN_PROG)
|
il.write_com(_binwrite.Command.RUN_PROG)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from copapy import NumLike, variable
|
from copapy import NumLike, variable
|
||||||
from copapy.backend import Write, Net, compile_to_instruction_list, add_read_command
|
from copapy.backend import Write, Net, compile_to_dag, add_read_command
|
||||||
import copapy
|
import copapy
|
||||||
import subprocess
|
import subprocess
|
||||||
from copapy import _binwrite
|
from copapy import _binwrite
|
||||||
|
|
@ -29,7 +29,7 @@ def test_compile():
|
||||||
|
|
||||||
ret = function(c1, c2)
|
ret = function(c1, c2)
|
||||||
|
|
||||||
dw, variable_list = compile_to_instruction_list([Write(net) for net in ret], copapy.generic_sdb)
|
dw, variable_list = compile_to_dag([Write(net) for net in ret], copapy.generic_sdb)
|
||||||
|
|
||||||
# run program command
|
# run program command
|
||||||
dw.write_com(_binwrite.Command.RUN_PROG)
|
dw.write_com(_binwrite.Command.RUN_PROG)
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,43 @@
|
||||||
from copapy import _binwrite, variable
|
from copapy import variable
|
||||||
from copapy.backend import Write, compile_to_instruction_list
|
from copapy.backend import Write, compile_to_dag
|
||||||
import copapy as cp
|
import copapy as cp
|
||||||
|
from copapy._binwrite import Command
|
||||||
|
|
||||||
|
|
||||||
def test_compile() -> None:
|
def test_compile() -> None:
|
||||||
|
"""Test compilation of a simple program."""
|
||||||
c1 = variable(9.0)
|
c1 = variable(9.0)
|
||||||
|
|
||||||
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
|
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
|
||||||
#ret = [c1 // 3.3 + 5]
|
ret = [c1 // 3.3 + 5]
|
||||||
ret = [cp.sqrt(c1)]
|
#ret = [cp.sqrt(c1)]
|
||||||
|
#c2 = cp._math.get_42()
|
||||||
|
#ret = [c2]
|
||||||
|
|
||||||
out = [Write(r) for r in ret]
|
out = [Write(r) for r in ret]
|
||||||
|
|
||||||
il, _ = compile_to_instruction_list(out, cp.generic_sdb)
|
dw, vars = compile_to_dag(out, cp.generic_sdb)
|
||||||
|
|
||||||
# run program command
|
# run program command
|
||||||
il.write_com(_binwrite.Command.RUN_PROG)
|
dw.write_com(Command.RUN_PROG)
|
||||||
|
|
||||||
il.write_com(_binwrite.Command.READ_DATA)
|
# read first 32 byte
|
||||||
il.write_int(0)
|
dw.write_com(Command.READ_DATA)
|
||||||
il.write_int(36)
|
dw.write_int(0)
|
||||||
|
dw.write_int(32)
|
||||||
|
|
||||||
il.write_com(_binwrite.Command.END_COM)
|
# read variables
|
||||||
|
for addr, lengths, _ in vars.values():
|
||||||
|
dw.write_com(Command.READ_DATA)
|
||||||
|
dw.write_int(addr)
|
||||||
|
dw.write_int(lengths)
|
||||||
|
|
||||||
|
dw.write_com(Command.END_COM)
|
||||||
|
|
||||||
print('* Data to runner:')
|
print('* Data to runner:')
|
||||||
il.print()
|
dw.print()
|
||||||
|
|
||||||
il.to_file('bin/test.copapy')
|
dw.to_file('bin/test.copapy')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue