[+] update commands
1. add basic cli.py module; 2. add stubs for debugpy;
This commit is contained in:
parent
dedff2aee5
commit
34c65f7ba5
@ -3,6 +3,7 @@ mypy_path =
|
|||||||
mypy-stubs,
|
mypy-stubs,
|
||||||
deps/com.github.aiortc.aiortc/src,
|
deps/com.github.aiortc.aiortc/src,
|
||||||
mypy-stubs/marisa-trie-types,
|
mypy-stubs/marisa-trie-types,
|
||||||
|
mypy-stubs/types-debugpy,
|
||||||
python
|
python
|
||||||
|
|
||||||
plugins =
|
plugins =
|
||||||
|
2
deps/com.github.aiortc.aiortc
vendored
2
deps/com.github.aiortc.aiortc
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a98c397d68335854d076fc61925559693d408d28
|
Subproject commit 1c158ef28435e2e0345a5d2682db8a2057d71522
|
7
mypy-stubs/types-debugpy/debugpy/__init__.pyi
Normal file
7
mypy-stubs/types-debugpy/debugpy/__init__.pyi
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
def listen(
|
||||||
|
addr: tuple[str, int],
|
||||||
|
) -> None: ...
|
||||||
|
|
||||||
|
def wait_for_client() -> None: ...
|
||||||
|
|
||||||
|
def breakpoint() -> None: ...
|
176
python/online/fxreader/pr34/commands_typed/cli.py
Normal file
176
python/online/fxreader/pr34/commands_typed/cli.py
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
import dataclasses
|
||||||
|
import io
|
||||||
|
import glob
|
||||||
|
import pathlib
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import abc
|
||||||
|
|
||||||
|
from .os import shutil_which
|
||||||
|
|
||||||
|
from typing import (
|
||||||
|
Optional,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class Project:
|
||||||
|
source_dir : pathlib.Path
|
||||||
|
build_dir : pathlib.Path
|
||||||
|
dest_dir : pathlib.Path
|
||||||
|
|
||||||
|
class CLI(abc.ABC):
|
||||||
|
@property
|
||||||
|
@abc.abstractmethod
|
||||||
|
def projects(self) -> dict[str, Project]:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def deploy_wheel(
|
||||||
|
self,
|
||||||
|
project_name: str,
|
||||||
|
argv: Optional[list[str]] = None,
|
||||||
|
output_dir: Optional[pathlib.Path] = None,
|
||||||
|
force: Optional[bool] = None,
|
||||||
|
) -> None:
|
||||||
|
project = self.projects[project_name]
|
||||||
|
|
||||||
|
# subprocess.check_call([
|
||||||
|
# sys.argv[0],
|
||||||
|
# # sys.executable,
|
||||||
|
# '-p', options.project,
|
||||||
|
# Command.meson_setup.value,
|
||||||
|
# ])
|
||||||
|
|
||||||
|
assert argv is None or len(argv) == 0
|
||||||
|
|
||||||
|
self.meson_install(
|
||||||
|
project_name=project_name,
|
||||||
|
force=force,
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
sys.executable,
|
||||||
|
'-m',
|
||||||
|
'build',
|
||||||
|
'-w', '-n',
|
||||||
|
'-Csetup-args=-Dmodes=pyproject',
|
||||||
|
'-Csetup-args=-Dinstall_path=%s' % str(project.dest_dir),
|
||||||
|
# '-Cbuild-dir=%s' % str(project.build_dir),
|
||||||
|
str(project.source_dir),
|
||||||
|
]
|
||||||
|
|
||||||
|
if not output_dir is None:
|
||||||
|
cmd.extend(['-o', str(output_dir)])
|
||||||
|
|
||||||
|
subprocess.check_call(cmd)
|
||||||
|
|
||||||
|
def meson_install(
|
||||||
|
self,
|
||||||
|
project_name: str,
|
||||||
|
force: Optional[bool] = None,
|
||||||
|
argv: Optional[list[str]] = None,
|
||||||
|
) -> None:
|
||||||
|
project = self.projects[project_name]
|
||||||
|
|
||||||
|
if force is None:
|
||||||
|
force = False
|
||||||
|
|
||||||
|
if argv is None:
|
||||||
|
argv = []
|
||||||
|
|
||||||
|
if force and project.dest_dir.exists():
|
||||||
|
shutil.rmtree(project.dest_dir)
|
||||||
|
|
||||||
|
subprocess.check_call([
|
||||||
|
shutil_which('meson', True,),
|
||||||
|
'install',
|
||||||
|
'-C',
|
||||||
|
project.build_dir,
|
||||||
|
'--destdir', project.dest_dir,
|
||||||
|
*argv,
|
||||||
|
])
|
||||||
|
|
||||||
|
for o in glob.glob(
|
||||||
|
str(project.dest_dir / 'lib' / 'pkgconfig' / '*.pc'),
|
||||||
|
recursive=True,
|
||||||
|
):
|
||||||
|
logger.info(dict(
|
||||||
|
path=o,
|
||||||
|
action='patch prefix',
|
||||||
|
))
|
||||||
|
|
||||||
|
with io.open(o, 'r') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
with io.open(o, 'w') as f:
|
||||||
|
f.write(
|
||||||
|
content.replace('prefix=/', 'prefix=${pcfiledir}/../../')
|
||||||
|
)
|
||||||
|
def ninja(
|
||||||
|
self,
|
||||||
|
project_name: str,
|
||||||
|
argv: Optional[list[str]] = None,
|
||||||
|
) -> None:
|
||||||
|
project = self.projects[project_name]
|
||||||
|
|
||||||
|
if argv is None:
|
||||||
|
argv = []
|
||||||
|
|
||||||
|
subprocess.check_call([
|
||||||
|
shutil_which('ninja', True),
|
||||||
|
'-C',
|
||||||
|
str(project.build_dir),
|
||||||
|
*argv,
|
||||||
|
])
|
||||||
|
|
||||||
|
def meson_compile(
|
||||||
|
self,
|
||||||
|
project_name: str,
|
||||||
|
argv: Optional[list[str]] = None,
|
||||||
|
) -> None:
|
||||||
|
project = self.projects[project_name]
|
||||||
|
|
||||||
|
if argv is None:
|
||||||
|
argv = []
|
||||||
|
|
||||||
|
subprocess.check_call([
|
||||||
|
shutil_which('meson', True,),
|
||||||
|
'compile',
|
||||||
|
'-C',
|
||||||
|
project.build_dir,
|
||||||
|
*argv,
|
||||||
|
])
|
||||||
|
|
||||||
|
def meson_setup(
|
||||||
|
self,
|
||||||
|
project_name: str,
|
||||||
|
force: bool,
|
||||||
|
argv: Optional[list[str]] = None,
|
||||||
|
) -> None:
|
||||||
|
project = self.projects[project_name]
|
||||||
|
|
||||||
|
if argv is None:
|
||||||
|
argv = []
|
||||||
|
|
||||||
|
if force:
|
||||||
|
if project.build_dir.exists():
|
||||||
|
logger.info(dict(action='removing build dir', path=project.build_dir))
|
||||||
|
shutil.rmtree(project.build_dir)
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
shutil_which('meson', True,),
|
||||||
|
'setup',
|
||||||
|
str(project.source_dir),
|
||||||
|
str(project.build_dir),
|
||||||
|
'-Dmodes=["meson"]',
|
||||||
|
# '-Dpkgconfig.relocatable=true',
|
||||||
|
'-Dprefix=/',
|
||||||
|
*argv,
|
||||||
|
]
|
||||||
|
|
||||||
|
logger.info(dict(cmd=cmd))
|
||||||
|
|
||||||
|
subprocess.check_call(cmd)
|
25
python/online/fxreader/pr34/commands_typed/os.py
Normal file
25
python/online/fxreader/pr34/commands_typed/os.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import shutil
|
||||||
|
|
||||||
|
from typing import (overload, Optional, Literal,)
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def shutil_which(
|
||||||
|
name: str,
|
||||||
|
raise_on_failure: Literal[True],
|
||||||
|
) -> str: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def shutil_which(
|
||||||
|
name: str,
|
||||||
|
raise_on_failure: bool,
|
||||||
|
) -> Optional[str]: ...
|
||||||
|
|
||||||
|
def shutil_which(
|
||||||
|
name: str,
|
||||||
|
raise_on_failure: bool,
|
||||||
|
) -> Optional[str]:
|
||||||
|
res = shutil.which(name)
|
||||||
|
if res is None and raise_on_failure:
|
||||||
|
raise NotImplementedError
|
||||||
|
else:
|
||||||
|
return res
|
Loading…
Reference in New Issue
Block a user