[~] Refactor
This commit is contained in:
parent
82a7c62ca8
commit
32579007e4
45
m.py
45
m.py
@ -12,7 +12,7 @@ import subprocess
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
from typing import (Optional, Any,)
|
from typing import (Optional, Any, TypeAlias, Literal, cast,)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
@ -138,6 +138,17 @@ def inside_env() -> bool:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return False
|
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:
|
def run(argv: Optional[list[str]] = None) -> None:
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
@ -152,43 +163,41 @@ def run(argv: Optional[list[str]] = None) -> None:
|
|||||||
if argv is None:
|
if argv is None:
|
||||||
argv = sys.argv[1:]
|
argv = sys.argv[1:]
|
||||||
|
|
||||||
class Commands(enum.StrEnum):
|
|
||||||
js = 'js'
|
|
||||||
mypy = 'mypy'
|
|
||||||
env = 'env'
|
|
||||||
ruff = 'ruff'
|
|
||||||
m2 = 'm2'
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
#'command',
|
'command',
|
||||||
'_command',
|
#'_command',
|
||||||
choices=[
|
choices=[
|
||||||
o.value
|
o
|
||||||
for o in Commands
|
for o in Command_args
|
||||||
],
|
],
|
||||||
#required=True,
|
#required=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
options, args = parser.parse_known_args(argv)
|
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)
|
js(args)
|
||||||
elif options.command is Commands.env:
|
elif options.command == 'env':
|
||||||
env(args)
|
env(args)
|
||||||
elif options.command is Commands.mypy:
|
elif options.command == 'mypy':
|
||||||
mypy(args)
|
mypy(args)
|
||||||
elif options.command is Commands.ruff:
|
elif options.command == 'ruff':
|
||||||
ruff(args)
|
ruff(args)
|
||||||
elif options.command is Commands.m2:
|
elif options.command == 'm2':
|
||||||
if not inside_env():
|
if not inside_env():
|
||||||
env(['--', 'm.py', 'm2', *args])
|
env(['--', 'm.py', 'm2', *args])
|
||||||
return
|
return
|
||||||
|
|
||||||
import python.tasks.cython
|
import python.tasks.cython
|
||||||
python.tasks.cython.mypyc_build(pathlib.Path('m.py'))
|
python.tasks.cython.mypyc_build(
|
||||||
|
pathlib.Path('m.py')
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -14,4 +14,4 @@ def cythonize(
|
|||||||
#exclude_failures=False,
|
#exclude_failures=False,
|
||||||
#show_all_warnings=False,
|
#show_all_warnings=False,
|
||||||
#**options
|
#**options
|
||||||
) -> setuptools.extension.Extension: ...
|
) -> list[setuptools.extension.Extension]: ...
|
||||||
|
@ -3,8 +3,10 @@ import pathlib
|
|||||||
|
|
||||||
class build_ext:
|
class build_ext:
|
||||||
extensions : list[setuptools.extension.Extension]
|
extensions : list[setuptools.extension.Extension]
|
||||||
build_temp : pathlib.Path
|
#build_temp : pathlib.Path
|
||||||
build_lib: pathlib.Path
|
#build_lib: pathlib.Path
|
||||||
|
build_temp: str
|
||||||
|
build_lib: str
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
...
|
...
|
||||||
|
@ -46,15 +46,16 @@ def build(content: str, module: M) -> M:
|
|||||||
|
|
||||||
if not output_dir.exists() or True:
|
if not output_dir.exists() or True:
|
||||||
os.makedirs(str(output_dir), exist_ok=True)
|
os.makedirs(str(output_dir), exist_ok=True)
|
||||||
|
|
||||||
source_path = output_dir / ('_%s.pyx' % sha256sum)
|
source_path = output_dir / ('_%s.pyx' % sha256sum)
|
||||||
if not source_path.exists():
|
if not source_path.exists():
|
||||||
with io.open(str(source_path), 'w') as f:
|
with io.open(str(source_path), 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
t1 = Cython.Build.Inline._get_build_extension()
|
t1 = Cython.Build.Inline._get_build_extension()
|
||||||
t1.extensions = [Cython.Build.cythonize(str(source_path))]
|
t1.extensions = Cython.Build.cythonize(str(source_path))
|
||||||
t1.build_temp = pathlib.Path('/')
|
t1.build_temp = str(pathlib.Path('/'))
|
||||||
t1.build_lib = output_dir
|
t1.build_lib = str(output_dir)
|
||||||
#t2 = Cython.Build.Inline.Extension(
|
#t2 = Cython.Build.Inline.Extension(
|
||||||
# name=sha256sum,
|
# name=sha256sum,
|
||||||
#)
|
#)
|
||||||
@ -135,8 +136,8 @@ def mypyc_build(file_path: pathlib.Path) -> Any:
|
|||||||
[str(source_path)],
|
[str(source_path)],
|
||||||
target_dir=str(output_dir / 'build')
|
target_dir=str(output_dir / 'build')
|
||||||
)
|
)
|
||||||
t1.build_temp = output_dir
|
t1.build_temp = str(output_dir)
|
||||||
t1.build_lib = lib_dir
|
t1.build_lib = str(lib_dir)
|
||||||
#t2 = Cython.Build.Inline.Extension(
|
#t2 = Cython.Build.Inline.Extension(
|
||||||
# name=sha256sum,
|
# name=sha256sum,
|
||||||
#)
|
#)
|
||||||
|
Loading…
Reference in New Issue
Block a user