From 3d9ff30a00e4701540424a5b42fa391c6173c31f Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Sun, 8 Jan 2023 18:07:32 -0600 Subject: [PATCH] Reorganize for multi-project builds, improve build helper --- build_helper.py | 55 ++++++++++++------- .../{ => mentionbot}/docs/sample_config.ini | 0 mentionbot/{ => mentionbot}/pyproject.toml | 0 mentionbot/{ => mentionbot}/setup.cfg | 0 mentionbot/{ => mentionbot}/setup.py | 0 .../src/mentionbot/__init__.py | 0 .../src/mentionbot/__main__.py | 0 .../{ => mentionbot}/src/mentionbot/abc.py | 0 .../{ => mentionbot}/src/mentionbot/tests.py | 0 .../{ => strikebot}/docs/sample_config.ini | 0 strikebot/{ => strikebot}/pyproject.toml | 0 strikebot/{ => strikebot}/setup.cfg | 0 strikebot/{ => strikebot}/setup.py | 0 .../{ => strikebot}/src/strikebot/__init__.py | 0 .../{ => strikebot}/src/strikebot/__main__.py | 0 .../{ => strikebot}/src/strikebot/common.py | 0 strikebot/{ => strikebot}/src/strikebot/db.py | 0 .../{ => strikebot}/src/strikebot/live_ws.py | 0 .../{ => strikebot}/src/strikebot/queue.py | 0 .../src/strikebot/reddit_api.py | 5 +- .../{ => strikebot}/src/strikebot/tests.py | 0 .../{ => strikebot}/src/strikebot/updates.py | 0 22 files changed, 37 insertions(+), 23 deletions(-) rename mentionbot/{ => mentionbot}/docs/sample_config.ini (100%) rename mentionbot/{ => mentionbot}/pyproject.toml (100%) rename mentionbot/{ => mentionbot}/setup.cfg (100%) rename mentionbot/{ => mentionbot}/setup.py (100%) rename mentionbot/{ => mentionbot}/src/mentionbot/__init__.py (100%) rename mentionbot/{ => mentionbot}/src/mentionbot/__main__.py (100%) rename mentionbot/{ => mentionbot}/src/mentionbot/abc.py (100%) rename mentionbot/{ => mentionbot}/src/mentionbot/tests.py (100%) rename strikebot/{ => strikebot}/docs/sample_config.ini (100%) rename strikebot/{ => strikebot}/pyproject.toml (100%) rename strikebot/{ => strikebot}/setup.cfg (100%) rename strikebot/{ => strikebot}/setup.py (100%) rename strikebot/{ => strikebot}/src/strikebot/__init__.py (100%) rename strikebot/{ => strikebot}/src/strikebot/__main__.py (100%) rename strikebot/{ => strikebot}/src/strikebot/common.py (100%) rename strikebot/{ => strikebot}/src/strikebot/db.py (100%) rename strikebot/{ => strikebot}/src/strikebot/live_ws.py (100%) rename strikebot/{ => strikebot}/src/strikebot/queue.py (100%) rename strikebot/{ => strikebot}/src/strikebot/reddit_api.py (99%) rename strikebot/{ => strikebot}/src/strikebot/tests.py (100%) rename strikebot/{ => strikebot}/src/strikebot/updates.py (100%) diff --git a/build_helper.py b/build_helper.py index c747894..07d3be2 100644 --- a/build_helper.py +++ b/build_helper.py @@ -1,5 +1,7 @@ """ -A few tools to help keep Debian packages and artifacts well organized. +A few tools to help keep Debian packages and artifacts well organized. Run me from the counting repo root. + +Run as root if doing a build, as the """ from argparse import ArgumentParser @@ -24,18 +26,26 @@ def _is_output(path: Path) -> bool: ) -project_root = Path(__file__).parent -upstream_root = project_root.joinpath("strikebot") -build_dir = project_root.joinpath("build") - parser = ArgumentParser() + tmp = parser.add_subparsers(dest = "cmd", required = True) +project_cmd_parsers = [ + tmp.add_parser("build"), + tmp.add_parser("clean"), +] -tmp.add_parser("build") -tmp.add_parser("clean") +for subparser in project_cmd_parsers: + subparser.add_argument("project") args = parser.parse_args() + +project_root = Path(__file__).parent.joinpath(args.project) +upstream_root = project_root.joinpath(args.project) +build_dir = project_root.joinpath("build") + if args.cmd == "build": + build_dir.mkdir(exist_ok = True) + # extract version from Python package config patt = re.compile("version *= *(.+?) *$") with upstream_root.joinpath("setup.cfg").open() as f: @@ -43,25 +53,30 @@ if args.cmd == "build": version = m[1] # delete stale "orig" tarball - for p in project_root.glob("strikebot_*.orig.tar.xz"): + for p in project_root.glob(f"{args.project}_*.orig.tar.xz"): p.unlink() # regenerate the "orig" tarball from the current source - run(["dh_make", "--yes", "--python", "--createorig", "-p", "strikebot_" + version], cwd = upstream_root) + run(["dh_make", "--yes", "--python", "--createorig", "-p", f"{args.project}_{version}"], cwd = upstream_root) - # build the source package - run(["debuild", "-i", "-us", "-uc", "-S"], cwd = upstream_root, check = True) + try: + # build the source package + run(["debuild", "-i", "-us", "-uc", "-S"], cwd = upstream_root, check = True) - [orig_path] = project_root.glob("strikebot_*.orig.tar.xz") - orig_name = orig_path.name - - # move outputs to build directory - for p in project_root.iterdir(): - if _is_output(p): - p.rename(build_dir.joinpath(p.relative_to(project_root))) + [orig_path] = project_root.glob(f"{args.project}_*.orig.tar.xz") + orig_name = orig_path.name - # create temporary link for orig tarball to satisfy binary package build - orig_path.symlink_to(build_dir.joinpath(orig_name).relative_to(project_root)) + try: + # build binary package + run(["pdebuild"], cwd = upstream_root, check = True) + finally: + # clean up + orig_path.unlink() + finally: + # move source package and intermediates to build directory + for p in project_root.iterdir(): + if _is_output(p): + p.rename(build_dir.joinpath(p.relative_to(project_root))) elif args.cmd == "clean": for p in build_dir.iterdir(): if _is_output(p): diff --git a/mentionbot/docs/sample_config.ini b/mentionbot/mentionbot/docs/sample_config.ini similarity index 100% rename from mentionbot/docs/sample_config.ini rename to mentionbot/mentionbot/docs/sample_config.ini diff --git a/mentionbot/pyproject.toml b/mentionbot/mentionbot/pyproject.toml similarity index 100% rename from mentionbot/pyproject.toml rename to mentionbot/mentionbot/pyproject.toml diff --git a/mentionbot/setup.cfg b/mentionbot/mentionbot/setup.cfg similarity index 100% rename from mentionbot/setup.cfg rename to mentionbot/mentionbot/setup.cfg diff --git a/mentionbot/setup.py b/mentionbot/mentionbot/setup.py similarity index 100% rename from mentionbot/setup.py rename to mentionbot/mentionbot/setup.py diff --git a/mentionbot/src/mentionbot/__init__.py b/mentionbot/mentionbot/src/mentionbot/__init__.py similarity index 100% rename from mentionbot/src/mentionbot/__init__.py rename to mentionbot/mentionbot/src/mentionbot/__init__.py diff --git a/mentionbot/src/mentionbot/__main__.py b/mentionbot/mentionbot/src/mentionbot/__main__.py similarity index 100% rename from mentionbot/src/mentionbot/__main__.py rename to mentionbot/mentionbot/src/mentionbot/__main__.py diff --git a/mentionbot/src/mentionbot/abc.py b/mentionbot/mentionbot/src/mentionbot/abc.py similarity index 100% rename from mentionbot/src/mentionbot/abc.py rename to mentionbot/mentionbot/src/mentionbot/abc.py diff --git a/mentionbot/src/mentionbot/tests.py b/mentionbot/mentionbot/src/mentionbot/tests.py similarity index 100% rename from mentionbot/src/mentionbot/tests.py rename to mentionbot/mentionbot/src/mentionbot/tests.py diff --git a/strikebot/docs/sample_config.ini b/strikebot/strikebot/docs/sample_config.ini similarity index 100% rename from strikebot/docs/sample_config.ini rename to strikebot/strikebot/docs/sample_config.ini diff --git a/strikebot/pyproject.toml b/strikebot/strikebot/pyproject.toml similarity index 100% rename from strikebot/pyproject.toml rename to strikebot/strikebot/pyproject.toml diff --git a/strikebot/setup.cfg b/strikebot/strikebot/setup.cfg similarity index 100% rename from strikebot/setup.cfg rename to strikebot/strikebot/setup.cfg diff --git a/strikebot/setup.py b/strikebot/strikebot/setup.py similarity index 100% rename from strikebot/setup.py rename to strikebot/strikebot/setup.py diff --git a/strikebot/src/strikebot/__init__.py b/strikebot/strikebot/src/strikebot/__init__.py similarity index 100% rename from strikebot/src/strikebot/__init__.py rename to strikebot/strikebot/src/strikebot/__init__.py diff --git a/strikebot/src/strikebot/__main__.py b/strikebot/strikebot/src/strikebot/__main__.py similarity index 100% rename from strikebot/src/strikebot/__main__.py rename to strikebot/strikebot/src/strikebot/__main__.py diff --git a/strikebot/src/strikebot/common.py b/strikebot/strikebot/src/strikebot/common.py similarity index 100% rename from strikebot/src/strikebot/common.py rename to strikebot/strikebot/src/strikebot/common.py diff --git a/strikebot/src/strikebot/db.py b/strikebot/strikebot/src/strikebot/db.py similarity index 100% rename from strikebot/src/strikebot/db.py rename to strikebot/strikebot/src/strikebot/db.py diff --git a/strikebot/src/strikebot/live_ws.py b/strikebot/strikebot/src/strikebot/live_ws.py similarity index 100% rename from strikebot/src/strikebot/live_ws.py rename to strikebot/strikebot/src/strikebot/live_ws.py diff --git a/strikebot/src/strikebot/queue.py b/strikebot/strikebot/src/strikebot/queue.py similarity index 100% rename from strikebot/src/strikebot/queue.py rename to strikebot/strikebot/src/strikebot/queue.py diff --git a/strikebot/src/strikebot/reddit_api.py b/strikebot/strikebot/src/strikebot/reddit_api.py similarity index 99% rename from strikebot/src/strikebot/reddit_api.py rename to strikebot/strikebot/src/strikebot/reddit_api.py index 2059707..0cf5daa 100644 --- a/strikebot/src/strikebot/reddit_api.py +++ b/strikebot/strikebot/src/strikebot/reddit_api.py @@ -219,8 +219,8 @@ class ApiClientPool: def enqueue_request(self, request: _Request, resp_tx = None) -> None: self._logger.debug("request {}: {}".format(obj_digest(request), type(request).__name__)) self._request_queue.push((request, resp_tx)) - self._check_queue_size() self._logger.debug(f"{len(self._request_queue)} requests in queue") + self._check_queue_size() async def worker_impl(self, task_status): task_status.started() @@ -274,8 +274,7 @@ class ApiClientPool: await resp_tx.send(resp) if error: - self._request_queue.push((request, resp_tx)) - self._check_queue_size() + self.enqueue_request(request, resp_tx) if self._last_error: spread = dt.timedelta(seconds = request_time - self._last_error) if spread <= self._error_window: diff --git a/strikebot/src/strikebot/tests.py b/strikebot/strikebot/src/strikebot/tests.py similarity index 100% rename from strikebot/src/strikebot/tests.py rename to strikebot/strikebot/src/strikebot/tests.py diff --git a/strikebot/src/strikebot/updates.py b/strikebot/strikebot/src/strikebot/updates.py similarity index 100% rename from strikebot/src/strikebot/updates.py rename to strikebot/strikebot/src/strikebot/updates.py -- 2.30.2