diff --git a/.mypy.ini b/.mypy.ini index bc4a8f4..e606004 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -3,6 +3,7 @@ mypy_path = mypy-stubs, deps/com.github.aiortc.aiortc/src, mypy-stubs/marisa-trie-types, + mypy-stubs/types-debugpy, python plugins = diff --git a/deps/com.github.aiortc.aiortc b/deps/com.github.aiortc.aiortc index a98c397..1c158ef 160000 --- a/deps/com.github.aiortc.aiortc +++ b/deps/com.github.aiortc.aiortc @@ -1 +1 @@ -Subproject commit a98c397d68335854d076fc61925559693d408d28 +Subproject commit 1c158ef28435e2e0345a5d2682db8a2057d71522 diff --git a/mypy-stubs/types-debugpy/debugpy/__init__.pyi b/mypy-stubs/types-debugpy/debugpy/__init__.pyi new file mode 100644 index 0000000..a5df157 --- /dev/null +++ b/mypy-stubs/types-debugpy/debugpy/__init__.pyi @@ -0,0 +1,7 @@ +def listen( + addr: tuple[str, int], +) -> None: ... + +def wait_for_client() -> None: ... + +def breakpoint() -> None: ... \ No newline at end of file diff --git a/python/online/fxreader/pr34/commands_typed/cli.py b/python/online/fxreader/pr34/commands_typed/cli.py new file mode 100644 index 0000000..23fc950 --- /dev/null +++ b/python/online/fxreader/pr34/commands_typed/cli.py @@ -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) \ No newline at end of file diff --git a/python/online/fxreader/pr34/commands_typed/os.py b/python/online/fxreader/pr34/commands_typed/os.py new file mode 100644 index 0000000..a4b3563 --- /dev/null +++ b/python/online/fxreader/pr34/commands_typed/os.py @@ -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 \ No newline at end of file