From a77c5411a0404429c2db2ca914c120f6ce60f2bb Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 16 Mar 2025 00:09:38 -0300 Subject: [PATCH 1/6] chore: :bookmark: Bump version. --- pyproject.toml | 2 +- uv.lock | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9998523..0efec3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "payphone" -version = "0.43.0" +version = "0.45.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.12" diff --git a/uv.lock b/uv.lock index 5d94b11..2d076dc 100644 --- a/uv.lock +++ b/uv.lock @@ -1,4 +1,5 @@ version = 1 +revision = 1 requires-python = ">=3.12" [[package]] @@ -127,7 +128,7 @@ version = "8.1.8" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "anyio" }, - { name = "colorama", marker = "platform_system == 'Windows'" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/cb/b5/e1e5fdf1c1bb7e6e614987c120a98d9324bf8edfaa5f5cd16a6235c9d91b/asyncclick-8.1.8.tar.gz", hash = "sha256:0f0eb0f280e04919d67cf71b9fcdfb4db2d9ff7203669c40284485c149578e4c", size = 232900 } wheels = [ @@ -188,7 +189,7 @@ name = "click" version = "8.1.8" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "colorama", marker = "platform_system == 'Windows'" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 } wheels = [ @@ -404,7 +405,7 @@ wheels = [ [[package]] name = "payphone" -version = "0.43.0" +version = "0.44.0" source = { virtual = "." } dependencies = [ { name = "aerich" }, From 3e0586f89cfb13a15b8323c681ebb5a92782d001 Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 16 Mar 2025 00:11:51 -0300 Subject: [PATCH 2/6] feat(scripts): :sparkles: Make `deploy.py` read latest version from `pyproject.toml`. --- scripts/deploy.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/deploy.py b/scripts/deploy.py index 5cfb65e..81d22ce 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -2,14 +2,24 @@ import os import time import getpass +try: + import toml + +except ImportError: + print( + "You need to install `toml` to use this file. Run `pip install toml` and try again." + ) + sys.exit() + username = input("Username for git.nyeki.dev: ") password = getpass.getpass("Password for git.nyeki.dev: ") -latest_tag = input("Latest tag (empty for latest): ") or "latest" - -print(f"Updating to tag {latest_tag}...") - os.system(f"git pull https://{username}:{password}@git.nyeki.dev/payphone/payphone") + +data = toml.load(open("pyproject.toml")) +version = data["project"]["version"].split(".") +latest_tag = "v" + version[1] + os.system( f"microk8s kubectl set image sts/bot bot=registry.nyeki.dev/payphone/payphone/shard:{latest_tag}" ) From 76857b7dcb369c24436cfde8e64e2846dbfa445a Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 16 Mar 2025 00:15:56 -0300 Subject: [PATCH 3/6] feat(scripts): :sparkles: Make `deploy.py` read the amount of replicas from `k8s/bot.yml`. --- scripts/deploy.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/deploy.py b/scripts/deploy.py index 81d22ce..d14d0fb 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -11,6 +11,15 @@ except ImportError: ) sys.exit() +try: + import yaml + +except ImportError: + print( + "You need to install `yaml` to use this file. Run `pip install pyyaml` and try again." + ) + sys.exit() + username = input("Username for git.nyeki.dev: ") password = getpass.getpass("Password for git.nyeki.dev: ") @@ -34,9 +43,14 @@ print("Waiting 15 seconds to run migrations...") time.sleep(15) -shards = input("How many shards are there deployed?: ") +with open("./k8s/bot.yml") as stream: + try: + data = yaml.safe_load(stream) + + os.system(f"microk8s kubectl exec bot-{data["spec"]["replicas"] - 1} -- uv run aerich upgrade") + except yaml.YAMLError as exc: + print("Could not read the amount of deployed shards.") -os.system(f"microk8s kubectl exec bot-{int(shards) - 1} -- uv run aerich upgrade") print("Done!") From 4788fff949a1e52897eac7c7ef83ac00771ee26e Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 16 Mar 2025 00:19:42 -0300 Subject: [PATCH 4/6] feat(scripts): :bug: Make `deploy.py` output the yaml parsing errors. --- scripts/deploy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/deploy.py b/scripts/deploy.py index d14d0fb..ed60e70 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -50,6 +50,7 @@ with open("./k8s/bot.yml") as stream: os.system(f"microk8s kubectl exec bot-{data["spec"]["replicas"] - 1} -- uv run aerich upgrade") except yaml.YAMLError as exc: print("Could not read the amount of deployed shards.") + print(exc) print("Done!") From 28d243a37ac986b50089a05aa64575e8f6a1428a Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 16 Mar 2025 00:28:00 -0300 Subject: [PATCH 5/6] fix(scripts): :bug: Fix yaml loading in `deploy.py`. --- pyproject.toml | 6 +++++- scripts/deploy.py | 3 ++- uv.lock | 30 +++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0efec3a..ba9a3c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,11 @@ requires-python = ">=3.12" dependencies = [ "aerich>=0.8.2", "aiohttp>=3.10.10", "orjson>=3.10.11", "py-cord>=2.6.1", "redis[hiredis]>=5.2.0", "rich>=13.9.4", "tortoise-orm[accel,asyncpg]>=0.21.7", "typer>=0.13.0",] [dependency-groups] -dev = [ "python-dotenv>=1.0.1", "toml>=0.10.2",] +dev = [ + "python-dotenv>=1.0.1", + "pyyaml>=6.0.2", + "toml>=0.10.2", +] [tool.aerich] tortoise_orm = "payphone.db.setup.CONFIG" diff --git a/scripts/deploy.py b/scripts/deploy.py index ed60e70..f34111f 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -45,7 +45,8 @@ time.sleep(15) with open("./k8s/bot.yml") as stream: try: - data = yaml.safe_load(stream) + docs = yaml.load_all(stream, yaml.Loader) + data = docs[0] os.system(f"microk8s kubectl exec bot-{data["spec"]["replicas"] - 1} -- uv run aerich upgrade") except yaml.YAMLError as exc: diff --git a/uv.lock b/uv.lock index 2d076dc..b0c28df 100644 --- a/uv.lock +++ b/uv.lock @@ -405,7 +405,7 @@ wheels = [ [[package]] name = "payphone" -version = "0.44.0" +version = "0.45.0" source = { virtual = "." } dependencies = [ { name = "aerich" }, @@ -421,6 +421,7 @@ dependencies = [ [package.dev-dependencies] dev = [ { name = "python-dotenv" }, + { name = "pyyaml" }, { name = "toml" }, ] @@ -439,6 +440,7 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ { name = "python-dotenv", specifier = ">=1.0.1" }, + { name = "pyyaml", specifier = ">=6.0.2" }, { name = "toml", specifier = ">=0.10.2" }, ] @@ -600,6 +602,32 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/eb/38/ac33370d784287baa1c3d538978b5e2ea064d4c1b93ffbd12826c190dd10/pytz-2025.1-py2.py3-none-any.whl", hash = "sha256:89dd22dca55b46eac6eda23b2d72721bf1bdfef212645d81513ef5d03038de57", size = 507930 }, ] +[[package]] +name = "pyyaml" +version = "6.0.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e", size = 130631 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/86/0c/c581167fc46d6d6d7ddcfb8c843a4de25bdd27e4466938109ca68492292c/PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab", size = 183873 }, + { url = "https://files.pythonhosted.org/packages/a8/0c/38374f5bb272c051e2a69281d71cba6fdb983413e6758b84482905e29a5d/PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725", size = 173302 }, + { url = "https://files.pythonhosted.org/packages/c3/93/9916574aa8c00aa06bbac729972eb1071d002b8e158bd0e83a3b9a20a1f7/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5", size = 739154 }, + { url = "https://files.pythonhosted.org/packages/95/0f/b8938f1cbd09739c6da569d172531567dbcc9789e0029aa070856f123984/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425", size = 766223 }, + { url = "https://files.pythonhosted.org/packages/b9/2b/614b4752f2e127db5cc206abc23a8c19678e92b23c3db30fc86ab731d3bd/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476", size = 767542 }, + { url = "https://files.pythonhosted.org/packages/d4/00/dd137d5bcc7efea1836d6264f049359861cf548469d18da90cd8216cf05f/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48", size = 731164 }, + { url = "https://files.pythonhosted.org/packages/c9/1f/4f998c900485e5c0ef43838363ba4a9723ac0ad73a9dc42068b12aaba4e4/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b", size = 756611 }, + { url = "https://files.pythonhosted.org/packages/df/d1/f5a275fdb252768b7a11ec63585bc38d0e87c9e05668a139fea92b80634c/PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4", size = 140591 }, + { url = "https://files.pythonhosted.org/packages/0c/e8/4f648c598b17c3d06e8753d7d13d57542b30d56e6c2dedf9c331ae56312e/PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8", size = 156338 }, + { url = "https://files.pythonhosted.org/packages/ef/e3/3af305b830494fa85d95f6d95ef7fa73f2ee1cc8ef5b495c7c3269fb835f/PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba", size = 181309 }, + { url = "https://files.pythonhosted.org/packages/45/9f/3b1c20a0b7a3200524eb0076cc027a970d320bd3a6592873c85c92a08731/PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1", size = 171679 }, + { url = "https://files.pythonhosted.org/packages/7c/9a/337322f27005c33bcb656c655fa78325b730324c78620e8328ae28b64d0c/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133", size = 733428 }, + { url = "https://files.pythonhosted.org/packages/a3/69/864fbe19e6c18ea3cc196cbe5d392175b4cf3d5d0ac1403ec3f2d237ebb5/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484", size = 763361 }, + { url = "https://files.pythonhosted.org/packages/04/24/b7721e4845c2f162d26f50521b825fb061bc0a5afcf9a386840f23ea19fa/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5", size = 759523 }, + { url = "https://files.pythonhosted.org/packages/2b/b2/e3234f59ba06559c6ff63c4e10baea10e5e7df868092bf9ab40e5b9c56b6/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc", size = 726660 }, + { url = "https://files.pythonhosted.org/packages/fe/0f/25911a9f080464c59fab9027482f822b86bf0608957a5fcc6eaac85aa515/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652", size = 751597 }, + { url = "https://files.pythonhosted.org/packages/14/0d/e2c3b43bbce3cf6bd97c840b46088a3031085179e596d4929729d8d68270/PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183", size = 140527 }, + { url = "https://files.pythonhosted.org/packages/fa/de/02b54f42487e3d3c6efb3f89428677074ca7bf43aae402517bc7cca949f3/PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563", size = 156446 }, +] + [[package]] name = "redis" version = "5.2.1" From 1fb54330bf1acaab1e398e04b7d4ca6a2cc3c1cc Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 16 Mar 2025 00:29:17 -0300 Subject: [PATCH 6/6] fix(scripts): :ambulance: Yet another hotfix for `deploy.py`. --- scripts/deploy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy.py b/scripts/deploy.py index f34111f..bd60a25 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -45,7 +45,7 @@ time.sleep(15) with open("./k8s/bot.yml") as stream: try: - docs = yaml.load_all(stream, yaml.Loader) + docs = list(yaml.load_all(stream, yaml.Loader)) data = docs[0] os.system(f"microk8s kubectl exec bot-{data["spec"]["replicas"] - 1} -- uv run aerich upgrade")