Repository navigation
feat: install Telegram-Archive from PyPI as a command and a Python library - #493
Conversation
A package named "src" cannot be published to PyPI or imported next to other projects. The code now lives in telegram_archive/, moved with git mv so history follows it. Existing Docker deployments keep working. Both images still ship a small src/ package that maps every "src.<name>" import to the telegram_archive module object itself, so "python -m src schedule" and "uvicorn src.web.main:app" run the same code with the same module state. The entrypoint accepts both names for the auth check, and the images' default commands use the new name.
A pip install has no entrypoint script and no repository checkout, so the schema could only be built by create_all, which leaves the database unstamped. The Alembic config, env.py and every revision now live in telegram_archive/, with paths relative to alembic.ini. "telegram-archive migrate" runs alembic upgrade head for pip installs and fresh databases. The Docker entrypoint keeps its stamping ladder and now finds the config through telegram_archive.db.migrations.alembic_config(). The image sets ALEMBIC_CONFIG, so a bare "alembic ..." inside the container keeps working. With the top-level alembic/ directory gone, ruff sorts "alembic" as the third-party package it is, which reorders imports in the migrations and their tests.
"from telegram_archive import Config, run_backup" followed by "asyncio.run(run_backup(Config()))" runs one backup of every configured account, the same path the backup command takes. The names load lazily through a module __getattr__, so "import telegram_archive" still works in the viewer image, which has no telethon.
telegram-archive migrate failed with "unable to open database file" when the data directory did not exist yet. The Docker entrypoint creates it before migrating and DatabaseManager creates it before opening SQLite; env.py now does the same, so migrate works as the first command.
The wheel and sdist carry only telegram_archive, with its templates, static files, alembic.ini, script.py.mako and every migration. The license is a PEP 639 SPDX expression, which builds on current setuptools without warnings; the license classifier it replaces had to go. A new Package workflow builds both on every pull request, checks their metadata and contents, and installs the wheel in a clean venv to run the CLI, the Python API import and the migrate command. The release workflow gains a PyPI job that refuses a tag that does not match the version files and uploads through trusted publishing, with no API token.
README gains an "Install from PyPI" section with the commands and a short Python API example, and says Docker stays the main way to run it. The changelog's Unreleased entry covers the rename, the compatibility package for "python -m src", the migrate command and PyPI publishing.
…ity package The migrations now live under telegram_archive/, which the entry above already covers.
…pace migrate imported only the models, so it never loaded .env and migrated /data/backups while every other command used the .env path. env.py now imports config, which loads it. version_locations had no path_separator, so Alembic split it on spaces and an install path with a space found no revisions: migrate left an empty alembic_version and reported success. The line is gone; the default <script_location>/versions is never split.
A wallpaper mounted at /app/src/web/static/<file>, the documented path before the rename, silently 404d because the viewer serves only telegram_archive/web/static. The viewer image links the old path to it.
…ned schema README.md is the PyPI long description, so repository-relative images and doc links break there. The Python API example now sets BACKUP_PATH, and the migrate note says the other commands build a schema migrate cannot adopt later, instead of claiming they create none.
…ew name is released The compose file, init scripts and README pin the 8.16.1 image, which has no telegram_archive module. python -m src and the /app/src wallpaper path work on that image and on every later one through the compatibility package, so they stay until the release that bumps the pins.
|
Important Review skippedToo many files! This PR contains 254 files, which is 154 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry. ⚙️ Run configurationConfiguration used: Repository: GeiserX/Telegram-Archive/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (57)
📒 Files selected for processing (254)
You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🐳 Dev images published!
The dev/test instance will pick up these changes automatically (Portainer GitOps). To test locally: docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #493 +/- ##
==========================================
- Coverage 94.84% 94.29% -0.56%
==========================================
Files 36 71 +35
Lines 14180 15878 +1698
==========================================
+ Hits 13449 14972 +1523
- Misses 731 906 +175
🚀 New features to boost your workflow:
|
…brary (#493) pip install telegram-archive gives the telegram-archive command and an importable package. The source package is telegram_archive, with a src compatibility package kept in the Docker images. Migrations ship inside the package and run with telegram-archive migrate. Releases publish to PyPI through trusted publishing from the release workflow. Docker examples keep the old entrypoint until the release that bumps the image pins.
Telegram-Archive could only run from its Docker images. #492 asks for a PyPI package, so other tools can install it with pip and drive it as a command or from Python.
pip install telegram-archivenow gives:telegram-archivecommand, with the same subcommands as the image and a newmigratethat creates or upgrades the schema;from telegram_archive import Config, TelegramBackup, run_backupfor use as a library.A release tag publishes it to PyPI through trusted publishing. There is no token, and the job refuses a tag that doesn't match the version.
To get there, the
srcpackage is nowtelegram_archive, and the migrations ship inside it. Existing deployments need no change. A smallsrccompatibility package in both images keepspython -m src ...,uvicorn src.web.main:appand the/app/src/web/staticwallpaper mount working, and it never loads a second copy of any module. For that reason the compose file and the Docker examples stay onpython -m srcuntil the release that bumps the image pins.A new Package workflow builds the wheel on every pull request. It installs the wheel in a clean environment and runs the command, the API import and
migrateagainst a fresh SQLite database.Before the first tag publishes, two one-time steps are needed: a pending trusted publisher on PyPI (project
telegram-archive, workflowrelease.yml, environmentpypi) and apypienvironment in this repo. Until then only the PyPI job of a release fails. The GitHub release and the images are unaffected.migratehas no stamping ladder. A SQLite database that another command created first needsalembic stamp headonce, and the README says so.Closes #492