[~] Refactor

This commit is contained in:
Siarhei Siniak 2024-11-10 12:58:00 +03:00
parent 82a7c62ca8
commit 32579007e4
4 changed files with 38 additions and 26 deletions

45
m.py

@ -12,7 +12,7 @@ import subprocess
import os
from typing import (Optional, Any,)
from typing import (Optional, Any, TypeAlias, Literal, cast,)
logger = logging.getLogger()
@ -138,6 +138,17 @@ def inside_env() -> bool:
except Exception:
return False
#class Commands(enum.StrEnum):
# js = 'js'
# mypy = 'mypy'
# env = 'env'
# ruff = 'ruff'
# m2 = 'm2'
Command_args = ['js', 'mypy', 'env', 'ruff', 'm2']
Command : TypeAlias = Literal['js', 'mypy', 'env', 'ruff', 'm2']
def run(argv: Optional[list[str]] = None) -> None:
logging.basicConfig(
level=logging.INFO,
@ -152,43 +163,41 @@ def run(argv: Optional[list[str]] = None) -> None:
if argv is None:
argv = sys.argv[1:]
class Commands(enum.StrEnum):
js = 'js'
mypy = 'mypy'
env = 'env'
ruff = 'ruff'
m2 = 'm2'
parser = argparse.ArgumentParser()
parser.add_argument(
#'command',
'_command',
'command',
#'_command',
choices=[
o.value
for o in Commands
o
for o in Command_args
],
#required=True,
)
options, args = parser.parse_known_args(argv)
options.command = Commands(options._command)
assert options.command in cast(list[str], Command_args)
if options.command is Commands.js:
#options.command = Commands(options._command)
if options.command == 'js':
js(args)
elif options.command is Commands.env:
elif options.command == 'env':
env(args)
elif options.command is Commands.mypy:
elif options.command == 'mypy':
mypy(args)
elif options.command is Commands.ruff:
elif options.command == 'ruff':
ruff(args)
elif options.command is Commands.m2:
elif options.command == 'm2':
if not inside_env():
env(['--', 'm.py', 'm2', *args])
return
import python.tasks.cython
python.tasks.cython.mypyc_build(pathlib.Path('m.py'))
python.tasks.cython.mypyc_build(
pathlib.Path('m.py')
)
else:
raise NotImplementedError

@ -14,4 +14,4 @@ def cythonize(
#exclude_failures=False,
#show_all_warnings=False,
#**options
) -> setuptools.extension.Extension: ...
) -> list[setuptools.extension.Extension]: ...

@ -3,8 +3,10 @@ import pathlib
class build_ext:
extensions : list[setuptools.extension.Extension]
build_temp : pathlib.Path
build_lib: pathlib.Path
#build_temp : pathlib.Path
#build_lib: pathlib.Path
build_temp: str
build_lib: str
def run(self) -> None:
...

@ -46,15 +46,16 @@ def build(content: str, module: M) -> M:
if not output_dir.exists() or True:
os.makedirs(str(output_dir), exist_ok=True)
source_path = output_dir / ('_%s.pyx' % sha256sum)
if not source_path.exists():
with io.open(str(source_path), 'w') as f:
f.write(content)
t1 = Cython.Build.Inline._get_build_extension()
t1.extensions = [Cython.Build.cythonize(str(source_path))]
t1.build_temp = pathlib.Path('/')
t1.build_lib = output_dir
t1.extensions = Cython.Build.cythonize(str(source_path))
t1.build_temp = str(pathlib.Path('/'))
t1.build_lib = str(output_dir)
#t2 = Cython.Build.Inline.Extension(
# name=sha256sum,
#)
@ -135,8 +136,8 @@ def mypyc_build(file_path: pathlib.Path) -> Any:
[str(source_path)],
target_dir=str(output_dir / 'build')
)
t1.build_temp = output_dir
t1.build_lib = lib_dir
t1.build_temp = str(output_dir)
t1.build_lib = str(lib_dir)
#t2 = Cython.Build.Inline.Extension(
# name=sha256sum,
#)