PEP8, Pylint

This commit is contained in:
DarkCat09 2022-12-25 18:19:28 +04:00
parent c02d3fed3e
commit c788976ab2
3 changed files with 21 additions and 14 deletions

View file

@ -163,6 +163,7 @@ good-names=i,
k, k,
f, f,
s, s,
js,
ex, ex,
Run, Run,
_ _

View file

@ -24,7 +24,6 @@ class Interpreter(abc.ABC):
def __init__(self) -> None: def __init__(self) -> None:
"""Base JS interpreter class""" """Base JS interpreter class"""
pass
def __getitem__(self, name: str) -> Any: def __getitem__(self, name: str) -> Any:
"""Support for `js[name]` syntax """Support for `js[name]` syntax
@ -45,7 +44,6 @@ class Interpreter(abc.ABC):
Args: Args:
func (str): JS function func (str): JS function
""" """
pass
@abc.abstractmethod @abc.abstractmethod
def get_var(self, name: str) -> Any: def get_var(self, name: str) -> Any:
@ -58,10 +56,11 @@ class Interpreter(abc.ABC):
Returns: Returns:
Variable value Variable value
""" """
pass
class NodeInterpreter(Interpreter): class NodeInterpreter(Interpreter):
"""Node.JS interpreter wrapper,
starts a simple web server in background"""
def __init__( def __init__(
self, self,
@ -84,12 +83,14 @@ class NodeInterpreter(Interpreter):
self.url = f'http://{host}:{port}' self.url = f'http://{host}:{port}'
# pylint: disable=consider-using-with
self.proc = subprocess.Popen( self.proc = subprocess.Popen(
args=[ args=[
node, server_js, node, server_js,
f'{port}', host, f'{port}', host,
], ],
) )
# pylint: enable=consider-using-with
time.sleep(0.1) time.sleep(0.1)
def exec_js(self, func: str) -> None: def exec_js(self, func: str) -> None:
@ -107,11 +108,15 @@ class NodeInterpreter(Interpreter):
class Js2PyInterpreter(Interpreter): class Js2PyInterpreter(Interpreter):
"""Js2Py interpreter,
uses js2py library to execute code"""
# Thanks to http://regex.inginf.units.it # Thanks to http://regex.inginf.units.it
arrowexp = regex.compile(r'\w[^\}]*+') arrowexp = regex.compile(r'\w[^\}]*+')
def __init__(self) -> None: def __init__(self) -> None:
"""Js2Py interpreter,
uses js2py library to execute code"""
super().__init__() super().__init__()
@ -179,8 +184,9 @@ def atob(s: str) -> str:
def get_interpreter( def get_interpreter(
*args,
create: Type[Interpreter] = Js2PyInterpreter, create: Type[Interpreter] = Js2PyInterpreter,
*args, **kwargs) -> 'Interpreter': **kwargs) -> 'Interpreter':
"""Get or create a JS interpreter. """Get or create a JS interpreter.
`*args` and `**kwargs` will be passed `*args` and `**kwargs` will be passed
directly to JS interpreter `__init__` directly to JS interpreter `__init__`
@ -193,7 +199,7 @@ def get_interpreter(
JS interpreter instance JS interpreter instance
""" """
global js global js # pylint: disable=global-statement
# create if none # create if none
if js is None: if js is None: