From b06d469eca7e86ae25381d7a0b1509250ffe8e60 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Mon, 5 Sep 2022 22:53:11 -0500 Subject: [PATCH] Restructure for Debian packaging (WIP) --- .gitignore | 1 + build_helper.py | 62 +++++++++++++++++++ {docs => strikebot/docs}/sample_config.ini | 0 pyproject.toml => strikebot/pyproject.toml | 0 setup.cfg => strikebot/setup.cfg | 2 +- setup.py => strikebot/setup.py | 0 {src => strikebot/src}/strikebot/__init__.py | 0 {src => strikebot/src}/strikebot/__main__.py | 3 +- {src => strikebot/src}/strikebot/common.py | 0 {src => strikebot/src}/strikebot/db.py | 0 {src => strikebot/src}/strikebot/live_ws.py | 0 {src => strikebot/src}/strikebot/queue.py | 0 .../src}/strikebot/reddit_api.py | 0 {src => strikebot/src}/strikebot/tests.py | 0 {src => strikebot/src}/strikebot/updates.py | 0 15 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 build_helper.py rename {docs => strikebot/docs}/sample_config.ini (100%) rename pyproject.toml => strikebot/pyproject.toml (100%) rename setup.cfg => strikebot/setup.cfg (89%) rename setup.py => strikebot/setup.py (100%) rename {src => strikebot/src}/strikebot/__init__.py (100%) rename {src => strikebot/src}/strikebot/__main__.py (98%) rename {src => strikebot/src}/strikebot/common.py (100%) rename {src => strikebot/src}/strikebot/db.py (100%) rename {src => strikebot/src}/strikebot/live_ws.py (100%) rename {src => strikebot/src}/strikebot/queue.py (100%) rename {src => strikebot/src}/strikebot/reddit_api.py (100%) rename {src => strikebot/src}/strikebot/tests.py (100%) rename {src => strikebot/src}/strikebot/updates.py (100%) diff --git a/.gitignore b/.gitignore index fbf1bc5..9de7c6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.egg-info __pycache__ .mypy_cache +.pybuild/ diff --git a/build_helper.py b/build_helper.py new file mode 100644 index 0000000..c669c83 --- /dev/null +++ b/build_helper.py @@ -0,0 +1,62 @@ +""" +A few tools to help keep Debian packages and artifacts well organized. +""" + +from argparse import ArgumentParser +from pathlib import Path +from subprocess import run +import re + + +def _is_output(path: Path) -> bool: + return any( + path.name.endswith(suffix) + for suffix in [ + ".build", + ".buildinfo", + ".changes", + ".deb", + ".debian.tar.xz", + ".dsc", + ] + ) + + +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) + +tmp.add_parser("build") +tmp.add_parser("clean") + +args = parser.parse_args() +if args.cmd == "build": + # extract version from Python package config + patt = re.compile("version *= *(.+?) *$") + with upstream_root.joinpath("setup.cfg").open() as f: + [m] = filter(None, map(patt.match, f)) + version = m[1] + + # delete stale "orig" tarball + for p in project_root.glob("strikebot_*.orig.tar.xz"): + p.unlink() + + # regenerate the "orig" tarball from the current source + run(["dh_make", "-y", "--indep", "--createorig", "-p", "strikebot_" + version], cwd = upstream_root) + + # build the package + run(["debuild"], cwd = upstream_root, check = True) + + # 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))) +elif args.cmd == "clean": + for p in build_dir.iterdir(): + if _is_output(p): + p.unlink() +else: + raise AssertionError() diff --git a/docs/sample_config.ini b/strikebot/docs/sample_config.ini similarity index 100% rename from docs/sample_config.ini rename to strikebot/docs/sample_config.ini diff --git a/pyproject.toml b/strikebot/pyproject.toml similarity index 100% rename from pyproject.toml rename to strikebot/pyproject.toml diff --git a/setup.cfg b/strikebot/setup.cfg similarity index 89% rename from setup.cfg rename to strikebot/setup.cfg index eb1fd25..f200179 100644 --- a/setup.cfg +++ b/strikebot/setup.cfg @@ -9,7 +9,7 @@ packages = strikebot python_requires = ~= 3.9 install_requires = asks ~= 2.4 - beautifulsoup4 ~= 4.11 + beautifulsoup4 ~= 4.9 trio == 0.19 trio-websocket == 0.9.2 triopg == 0.6.0 diff --git a/setup.py b/strikebot/setup.py similarity index 100% rename from setup.py rename to strikebot/setup.py diff --git a/src/strikebot/__init__.py b/strikebot/src/strikebot/__init__.py similarity index 100% rename from src/strikebot/__init__.py rename to strikebot/src/strikebot/__init__.py diff --git a/src/strikebot/__main__.py b/strikebot/src/strikebot/__main__.py similarity index 98% rename from src/strikebot/__main__.py rename to strikebot/src/strikebot/__main__.py index 63da2e1..4c2b1d9 100644 --- a/src/strikebot/__main__.py +++ b/strikebot/src/strikebot/__main__.py @@ -1,6 +1,7 @@ from enum import Enum from inspect import getmodule from logging import FileHandler, getLogger, StreamHandler +from pathlib import Path from signal import SIGUSR1 from sys import stdout from traceback import StackSummary @@ -21,7 +22,7 @@ from strikebot.live_ws import HealingReadPool, PoolMerger from strikebot.reddit_api import ApiClientPool -_DEBUG_LOG_PATH: Optional[str] = None # path to file to write debug logs to, if any +_DEBUG_LOG_PATH: Optional[Path] = None # file to write debug logs to, if any _TaskKind = Enum( diff --git a/src/strikebot/common.py b/strikebot/src/strikebot/common.py similarity index 100% rename from src/strikebot/common.py rename to strikebot/src/strikebot/common.py diff --git a/src/strikebot/db.py b/strikebot/src/strikebot/db.py similarity index 100% rename from src/strikebot/db.py rename to strikebot/src/strikebot/db.py diff --git a/src/strikebot/live_ws.py b/strikebot/src/strikebot/live_ws.py similarity index 100% rename from src/strikebot/live_ws.py rename to strikebot/src/strikebot/live_ws.py diff --git a/src/strikebot/queue.py b/strikebot/src/strikebot/queue.py similarity index 100% rename from src/strikebot/queue.py rename to strikebot/src/strikebot/queue.py diff --git a/src/strikebot/reddit_api.py b/strikebot/src/strikebot/reddit_api.py similarity index 100% rename from src/strikebot/reddit_api.py rename to strikebot/src/strikebot/reddit_api.py diff --git a/src/strikebot/tests.py b/strikebot/src/strikebot/tests.py similarity index 100% rename from src/strikebot/tests.py rename to strikebot/src/strikebot/tests.py diff --git a/src/strikebot/updates.py b/strikebot/src/strikebot/updates.py similarity index 100% rename from src/strikebot/updates.py rename to strikebot/src/strikebot/updates.py -- 2.30.2