diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e075abd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,12 @@ +* text=auto eol=lf + +*.sh text eol=lf +*.bat text eol=crlf +*.ps1 text eol=lf + +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.pdf binary diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 834236c..fc30620 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -3,6 +3,6 @@ contact_links: - name: Report a security vulnerability url: https://github.com/coldsofttech/CommitRocket/security/advisories/new about: Please report security problems privately, not in a public issue. - - name: Questions and ideas - url: https://github.com/coldsofttech/CommitRocket/discussions - about: Ask a question or float an idea before opening an issue. + - name: Questions and support + url: https://github.com/coldsofttech/CommitRocket/blob/main/SUPPORT.md + about: See how to get help before opening an issue. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5fc1d01..d5a7459 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,17 +1,12 @@ -## What does this change? +## What changed - - -## How was it tested? - - + ## Checklist -- [ ] `uv run ruff check .` passes -- [ ] `uv run pytest -m "not integration"` passes +- [ ] Tests added or updated +- [ ] `uv run ruff check .` and `uv run pytest -m "not integration"` pass - [ ] `uv run pytest -m integration` passes (if the change touches the run flow, Git handling or LFS) -- [ ] Tests added or updated for the change -- [ ] `CHANGELOG.md` has a short entry under `[Unreleased]` (what changed for the reader, in one or two lines) -- [ ] `README.md` updated if user-facing behavior or options changed; technical details go in `docs/` +- [ ] `CHANGELOG.md` has a short `[Unreleased]` entry +- [ ] README or `docs/` updated if behaviour changed - [ ] No secrets, tokens or private paths in the code, tests or logs diff --git a/.github/social-preview.html b/.github/social-preview.html deleted file mode 100644 index f14d88f..0000000 --- a/.github/social-preview.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - CommitRocket - Push huge changes in small batches - - - - Python 3.11+ - - CLI - - Git LFS - - - diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d17057d..4dc2a3e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,3 +25,6 @@ jobs: - name: Ruff run: uv run ruff check . + + - name: Mypy + run: uv run mypy diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bf80843..5aed770 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,6 +51,7 @@ jobs: permissions: contents: write id-token: write + attestations: write steps: - uses: actions/checkout@v7 @@ -59,6 +60,11 @@ jobs: - name: Build run: uv build + - name: Attest build provenance + uses: actions/attest-build-provenance@v4 + with: + subject-path: dist/* + - name: Publish to PyPI run: uv publish --trusted-publishing always diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml new file mode 100644 index 0000000..22f0770 --- /dev/null +++ b/.markdownlint-cli2.yaml @@ -0,0 +1,4 @@ +config: + MD013: false # line length + MD033: false # inline HTML + MD041: false # first line heading (templates start with a subheading) diff --git a/CHANGELOG.md b/CHANGELOG.md index 506a746..0b4db9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## [Unreleased] +## [0.1.3] - 2026-11-14 + +### Added +- `--resume` continues an interrupted run with the settings it started with. Running again with different settings starts a new run. +- An interrupted run is remembered in a file inside `.git` and removed when the run finishes. +- Commits now end with a `Prepared and Committed By: 🚀 CommitRocket (...)` attribution line, never added twice. +- `--no-attribution` (alias `--ignore-attribution`, or `no-attribution = true` in the config file) skips it. + ## [0.1.2] - 2026-10-25 ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89a7d9d..0070ee1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,6 +9,7 @@ By taking part you agree to follow the [Code of Conduct](CODE_OF_CONDUCT.md). - Use the issue templates. For a bug, include the exact command, the output, your versions (`commitrocket --version`, `commitrocket doctor`), and the relevant lines from the log file (re-run with `--level DEBUG`). Remove secrets and private paths. +- **Questions:** see [SUPPORT.md](SUPPORT.md) for where to ask. - **Security problems:** do not open an issue. Follow the [Security Policy](SECURITY.md). ## Setting up diff --git a/README.md b/README.md index d941376..75e6086 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ Got a huge pile of changes that a single push would choke on? CommitRocket splits them into size-limited batches, commits each batch, and pushes as it goes, with live progress. +CommitRocket is a command-line tool: you install it and run `commitrocket`. It is not a +Python library and has no Python API to import. + ## Why CommitRocket? Pushing a lot of data in one go tends to go wrong. A single commit with gigabytes of videos, @@ -59,7 +62,17 @@ temporary settings live in the repository and are restored afterwards. pip install commitrocket ``` -Requires Python 3.11+ and [Git](https://git-scm.com/). +Requires Python 3.11 or later and [Git](https://git-scm.com/). Because it is a program +rather than a library, [pipx](https://pipx.pypa.io/) and [uv](https://docs.astral.sh/uv/) +are a good fit too, and keep it out of your project environments: + +``` +pipx install commitrocket +uv tool install commitrocket +``` + +Check the install with `commitrocket --version`. Git LFS is optional: only `--use-lfs` +needs it, and CommitRocket offers to install it when it is missing. ## Use @@ -73,402 +86,81 @@ right away. Before it starts, CommitRocket checks that you are on a branch with an upstream and have nothing staged, then asks for confirmation. +The options you will use most: + | Option | What it does | | --- | --- | -| `--repo` | The Git repository to work on (default: the current folder) | | `--message` | Commit message used for every batch (required, here or in a config file) | -| `--message-template` | Shape of each commit message (default `{message} #{n}`, see below) | -| `--number` | Number to start the `#` suffix from (default 1) | -| `--config` | Read settings from this TOML file (see "Config file") | -| `--remote` / `--branch` | Push to this remote / remote branch instead of the upstream | -| `--no-push` | Commit every batch but don't push them | -| `--include` / `--exclude` | Only handle / leave alone files matching a pattern (repeatable) | -| `--include-from` / `--exclude-from` | Read those patterns from a file | +| `--resume` | Continue the interrupted run in this repository with the parameters it started with (see [Interrupted or failed runs](#interrupted-or-failed-runs)) | | `--limit-mib` | Target size of each batch in MiB (default 100) | -| `--batch-type` | How files are picked: `deterministic` (default), `sequential` or `soft` (see below) | | `--dry-run` | Show the planned batches and commit messages without changing anything | -| `--retries` | Retry a failed push this many times with growing waits (default 3, `0` = never) | -| `--post-buffer-mib` | Raise Git's `http.postBuffer` for this run, for large pushes over HTTPS | -| `--max-mib` | Largest single file allowed, in MiB (default 3x the limit) | +| `--include` / `--exclude` | Only handle / leave alone files matching a pattern (repeatable) | +| `--use-lfs` | Store files over 100 MiB with Git LFS for this run (see "Large files with Git LFS") | +| `--no-push` | Commit every batch but don't push them | | `--force` | Skip the confirmation prompt | -| `--compression-threads` | Threads Git uses to compress data while pushing (0 = automatic) | -| `--lfs-threads` | How many Git LFS files upload at the same time | -| `--lfs-batch-mib` | Total size of LFS files pushed together (default: same as `--limit-mib`) | -| `--level` | Detail written to the log file: `DEBUG`, `INFO` (default), `WARNING` or `ERROR` | -| `--log-file` | Write the log to this file instead of the default folder | -| `--lfs-threshold-mib` | With `--use-lfs`, files larger than this use LFS (default 100, `0` = every file) | -| `--use-lfs` | Store files over 100 MiB with Git LFS for this run (see below) | -| `--no-lfs-commit-rules` | With `--use-lfs`, keep LFS rules local to the run (checkouts and clones then show pointer files, not real files) | -| `--report` | Write a JSON summary of the run to this file | -| `--notify` | Show a desktop notification when the run ends | -| `--notify-webhook` | Send a JSON summary to this web address when the run ends | - -There is also `commitrocket doctor`, which checks your setup (see "Check your setup"). - -### Choosing which files to handle -`--include` and `--exclude` take `.gitignore`-style patterns and can be repeated: - -| Pattern | Matches | -| --- | --- | -| `*.mp4` | Every `.mp4` file, in any folder (this is how you select by extension) | -| `raw/` | The `raw` folder and everything in it | -| `/notes.txt` | Only `notes.txt` in the repository root | -| `videos/**/*.mov` | `.mov` files anywhere under `videos` | -| `!keep.mp4` | Re-includes a file matched by an earlier pattern in the same list | - -With `--include`, only matching files are handled. Anything matching `--exclude` is left -alone, and exclusion always wins. Files that are filtered out are not staged, committed or -counted as skipped; they simply stay pending. - -For longer lists, put one pattern per line in a file (blank lines and `#` comments are -ignored) and pass it with `--include-from` or `--exclude-from`. A file named -`.commitrocketignore` in the repository root is read automatically as a permanent list of -excludes. - -``` -commitrocket --repo . --message "Videos" --include "*.mp4" --include "*.mov" --exclude "raw/" -commitrocket --repo . --message "Videos" --include-from patterns.txt -``` +There is also `commitrocket doctor`, which checks Git, git-lfs, your config and the remote without changing anything +(see [doctor](docs/guides/cli.md#doctor)). +Run `commitrocket --help` or see the [command line guide](docs/guides/cli.md) for every +option with its default and limits, and the exit codes. ### Config file -Save your usual options so you don't have to retype them. CommitRocket reads -`commitrocket.toml` in the repository folder, or else the `[tool.commitrocket]` table of -`pyproject.toml`; `--config FILE` points at a different file. Option names are the same as -on the command line, with `-` or `_`. Options typed on the command line win over the file, -and `--include`/`--exclude` lists are combined. +Save your usual options so you don't have to retype them, in `commitrocket.toml` in the +repository folder or in the `[tool.commitrocket]` table of `pyproject.toml`: ```toml # commitrocket.toml message = "Videos" use-lfs = true limit-mib = 50 -batch-type = "sequential" exclude = ["raw/", "*.tmp"] -message-template = "{message} #{n} ({files} files, {size:.0f} MiB)" -``` - -```toml -# or in pyproject.toml -[tool.commitrocket] -message = "Videos" -retries = 5 -``` - -**A config file inside a repository is not fully trusted**, because anyone who can change the -repository can change it. If you run CommitRocket in a repository you cloned, a file found -there is not allowed to turn on `force`, choose `remote` or `branch`, set `report`, -`log-file` or `notify-webhook`, or read pattern files (`include-from`, `exclude-from`). -Those settings are ignored with a warning. To use them, keep them in a file you trust and -pass it explicitly: `commitrocket --config path/to/commitrocket.toml`. They also work as -normal command-line options. - -### Commit message templates - -`--message-template` decides the message of each batch. The default is `{message} #{n}`. - -| Placeholder | Value | -| --- | --- | -| `{message}` | The `--message` text | -| `{n}` | The commit number (starts at `--number`) | -| `{batch}` | The batch's position in this run, starting at 1 | -| `{files}` | Number of files in the batch | -| `{size}` | Size of the batch in MiB (e.g. `{size:.1f}`) | -| `{first}` | Path of the first file in the batch | -| `{date}` | Today's date, `YYYY-MM-DD` | - -``` -commitrocket --repo . --message "Course" --message-template "{message} part {n}: {files} files ({size:.0f} MiB)" -``` - -### Pushing somewhere else, or not at all - -By default each batch is pushed to the branch's upstream. `--remote` and `--branch` choose -another destination, for example a backup remote or a different branch; HEAD is pushed to -that remote branch. With `--no-push` the batches are committed locally and a later run -pushes them (the "interrupted runs" resume does this). `--no-push` can't be combined with -`--use-lfs`, because the large files would stay on your machine while a later plain -`git push` published pointers without them. - -### Report and notifications - -`--report out.json` writes a machine-readable summary every time, including when the run -fails, is interrupted or is a dry run, so scripts and CI can read the result: - -```json -{ - "schema_version": 1, - "status": "success", - "exit_code": 0, - "target": "origin/main", - "duration_seconds": 412.7, - "totals": { "batches": 3, "files": 42, "size_bytes": 1234567890, "deferred_files": 0 }, - "batches": [ - { "number": 1, "message": "Videos #1", "commit": "e57cffb...", "file_count": 14, - "size_bytes": 412345678, "lfs_file_count": 2, "pushed": true, "verified": true, - "files": ["..."] } - ], - "deferred": [], - "error": null, - "log_file": "..." -} -``` - -`status` is one of `success`, `completed_with_deferred_files`, `dry_run`, `cancelled`, -`aborted` (stopped before doing anything, for example files needing `--use-lfs`), -`interrupted` and `failed`. The report also lists your settings, what was resumed, the LFS -files and the commit that holds the LFS rules. It never contains the webhook address. - -Long runs can tell you when they are done: - -| Option | What happens | -| --- | --- | -| `--notify` | A desktop notification: a toast on Windows, a notification on macOS, `notify-send` on Linux. If none of these works (for example over SSH), the terminal bell sounds instead. | -| `--notify-webhook URL` | A JSON message is POSTed to the address. It has `text` and `content` fields, so Slack, Teams and Discord incoming webhooks work, plus `status`, `batches`, `files` and `duration_seconds` for your own endpoint. [ntfy](https://ntfy.sh) also works. | - -Notifications are sent when the run ends, whether it succeeded or not, and never for -`--dry-run`. A notification that can't be delivered never changes the run's result. - -### Check your setup - -``` -commitrocket doctor -commitrocket doctor --repo path/to/repo --remote backup --offline -``` - -Checks Git and git-lfs, your config file, the log folder, the repository, branch and push -target, whether the remote is reachable and accepts a push (a dry run), staged and -unpushed files, and pending files over 100 MiB. It changes nothing. Use `--offline` to skip -the checks that contact the remote. The exit code is 1 if any check fails. - -### Examples - -Run these from inside the repository (`--repo .`), or point `--repo` at any path. - -**Push everything in 100 MiB batches (the default)** -``` -commitrocket --repo . --message "Add assets" -``` - -**Leave it running and get told when it's done** -``` -commitrocket --repo . --message "Videos" --use-lfs --notify -commitrocket --repo . --message "Videos" --notify-webhook https://ntfy.sh/my-topic -``` - -**Results for scripts and CI** -``` -commitrocket --repo . --message "Nightly" --force --report result.json -``` - -**Check everything is ready** -``` -commitrocket doctor -``` - -**Only some files, or everything except some** -``` -commitrocket --repo . --message "Videos" --include "*.mp4" --exclude "raw/" -``` - -**Push to a different remote or branch** -``` -commitrocket --repo . --message "Backup" --remote backup --branch main -``` - -**Commit now, push later** -``` -commitrocket --repo . --message "Add assets" --no-push -commitrocket --repo . --message "Add assets" # later: pushes the saved commits -``` - -**Videos in LFS that clones can download too** -``` -commitrocket --repo . --message "Videos" --use-lfs -``` - -**See what would happen first** - -Prints every batch, its commit message and size, and any files that would be skipped. -Nothing is staged, committed, pushed or installed. -``` -commitrocket --repo . --message "Add assets" --use-lfs --dry-run -``` - -**Flaky connection or "RPC failed" errors** - -Failed pushes are retried automatically (3 times by default, after 5, 15 and 45 -seconds). A bigger HTTP buffer helps with timeouts on large uploads over HTTPS. -``` -commitrocket --repo . --message "Videos" --retries 5 --post-buffer-mib 500 -``` - -**Smaller batches for a slow or unreliable connection** - -Each push is shorter, so a failure costs less to repeat. -``` -commitrocket --repo . --message "Add assets" --limit-mib 50 -``` - -**Continue numbering after an earlier run** - -If the last commit was `Videos #21`, the next batch becomes `Videos #22`. -``` -commitrocket --repo . --message "Videos" --number 22 -``` - -**Run without prompts (scripts, scheduled jobs)** -``` -commitrocket --repo . --message "Nightly sync" --force -``` - -**Keep files in order, such as numbered lectures** - -`sequential` never skips ahead, so `01`, `02`, `03` land in commits in that order. -``` -commitrocket --repo . --message "Course videos" --batch-type sequential -``` - -**Fewer, larger pushes** - -`soft` lets a batch run slightly past the limit instead of leaving gaps. -``` -commitrocket --repo . --message "Add assets" --batch-type soft --limit-mib 100 --max-mib 300 -``` - -**Files over 100 MiB (videos, archives, datasets)** - -GitHub rejects these, so use LFS. Without `--use-lfs`, CommitRocket stops before -committing anything and lists the files. -``` -commitrocket --repo . --message "Videos" --use-lfs ``` -**Many large files, faster uploads** +Options typed on the command line win over the file. A config file inside a repository is +not fully trusted, so it cannot turn on `force`, choose `remote` or `branch`, or set +`report`, `log-file`, `notify-webhook` or the pattern files; pass such a file yourself with +`--config` to use those. The [configuration guide](docs/guides/configuration.md) lists every +key and explains how files are found and trusted. -Group several LFS files per push and upload four at a time. -``` -commitrocket --repo . --message "Videos" --use-lfs --lfs-batch-mib 500 --lfs-threads 4 -``` +### More -**Also move mid-size files (over 50 MiB) to LFS** +Everything else is in the [command line guide](docs/guides/cli.md): -GitHub warns about files above 50 MiB, even though it accepts them. -``` -commitrocket --repo . --message "Assets" --use-lfs --lfs-threshold-mib 50 -``` - -**Send every file through LFS** - -Use with care: clones will show pointer files for all content. -``` -commitrocket --repo . --message "Archive" --use-lfs --lfs-threshold-mib 0 -``` - -**Allow bigger individual files** - -Files above `--max-mib` (default 3x the limit) are skipped and reported at the end. -``` -commitrocket --repo . --message "Videos" --use-lfs --max-mib 500 -``` - -**Find out why a push failed** - -The log records every Git command and the push output. Its path is printed at the end. -``` -commitrocket --repo . --message "Add assets" --level DEBUG -commitrocket --repo . --message "Add assets" --level DEBUG --log-file push-debug.log -``` - -### Logs - -Every run writes its own log file, and the path is shown at the end of the run. Logs are -kept here by default: - -| System | Folder | -| --- | --- | -| Windows | `%LOCALAPPDATA%\CommitRocket\Logs\` | -| macOS | `~/Library/Logs/CommitRocket/` | -| Linux | `~/.local/state/commitrocket/` (or `$XDG_STATE_HOME/commitrocket/`) | - -Files are named `commitrocket-YYYYMMDD-HHMMSS.log`. Use `--level DEBUG` to also record -every Git command and the push output, which helps when a push fails. Old logs are not -deleted automatically. - -### Batch types - -Files are always taken in alphabetical order. For files A=60, B=50, C=30, D=20 MiB with a -100 MiB limit: - -| Type | How it picks | Batches | -| --- | --- | --- | -| `deterministic` (default) | Fills each batch, skipping a file that doesn't fit and trying later ones | A + C, then B + D | -| `sequential` | Strict order; a batch ends at the first file that doesn't fit | A, then B + C + D | -| `soft` | Strict order; keeps adding until the batch reaches or passes the limit, never above `--max-mib` in total | A + B, then C + D | - -Files larger than the batch limit (but under the maximum) get a batch of their own. -Files over the maximum are skipped and listed at the end so you can decide what to do. +- [File patterns](docs/guides/cli.md#file-patterns) for `--include` and `--exclude` +- [Commit messages](docs/guides/cli.md#commit-messages), templates and the attribution line +- [Batch types](docs/guides/cli.md#batch-types) +- [Report and notifications](docs/guides/cli.md#report-and-notifications) for scripts and CI +- [Logs](docs/guides/cli.md#logs) and [`commitrocket doctor`](docs/guides/cli.md#doctor) +- [Examples](docs/guides/cli.md#examples), and settings in the + [configuration guide](docs/guides/configuration.md) ### Large files with Git LFS Hosts like GitHub reject files over 100 MiB. With `--use-lfs`, CommitRocket stores those -files with Git LFS instead: - -1. Installs git-lfs if it is missing (asks first, unless `--force`). -2. Routes each file over 100 MiB through LFS using a rule that only exists on your - machine. Nothing extra is committed to your repository. -3. Pushes your files in batches as usual. -4. Removes the local LFS setup when it finishes, even if the run fails. - -The large files are stored in LFS on the remote. Because no tracking rules are committed, -a fresh clone will show small pointer files for them until LFS tracking is set up there. - -By default only files over 100 MiB use LFS. Lower the cut-off with `--lfs-threshold-mib` -(for example `50`), or use `0` to send every file through LFS. Take care with `0`: because -no tracking rules are committed, anyone cloning the repository will see small pointer -files in place of all your content, and LFS storage and bandwidth quotas on the host are -used up quickly. Git's own settings files (`.gitattributes`, `.gitignore`, `.lfsconfig`) -always stay as normal files. The threshold cannot be above 100, since larger files are -rejected by hosts. - -So that checkouts and clones receive the real files, CommitRocket commits the LFS rules by default. It commits -one rule per file type (for example `*.mp4`) to `.gitattributes` as ` (LFS rules)`, -pushes it first, and your files follow as LFS pointers. Because rules are per type, every -file of that type is stored in LFS from then on, including small ones and future ones. -Files without an extension get an exact-path rule. `.gitattributes` must have no -uncommitted changes beforehand. Pass `--no-lfs-commit-rules` to skip this; videos then turn into -text pointer files after a pull, reset or clone. - -If a run fails after committing LFS files but before pushing them, the LFS hooks are left -installed so the files can still be uploaded. Run CommitRocket again to finish; avoid a -plain `git push` unless the hooks are still installed. - -Each LFS file normally gets its own push. To upload several at once, raise -`--lfs-batch-mib` (for example `--lfs-batch-mib 500 --lfs-threads 4`). - -The thread settings only change the repository's own Git configuration for the duration -of the run and are put back afterwards. Your global Git configuration is never touched. - -If you run CommitRocket without `--use-lfs` and a file is over 100 MiB, it stops before -committing anything and tells you to use the flag. - -### Contributing and security - -Bug reports and ideas are welcome: see [CONTRIBUTING.md](CONTRIBUTING.md). Please report -security problems privately, as described in [SECURITY.md](SECURITY.md). Everyone taking -part is expected to follow the [Code of Conduct](CODE_OF_CONDUCT.md). +files with Git LFS instead: it installs git-lfs if it is missing (asking first, unless +`--force`), commits one rule per file type to `.gitattributes` so clones get the real +files, pushes your files as usual, and removes its local LFS setup when it finishes, even +if the run fails. Without `--use-lfs`, a file over 100 MiB stops the run before anything is +committed. See [Using Git LFS](docs/guides/cli.md#using-git-lfs) for the threshold, the +rules commit, thread settings and what happens after a failed run. ### Interrupted or failed runs -If a run stops, whether it failed or you pressed Ctrl+C, just run the same command again. -CommitRocket picks up where it stopped: +If a run stops, whether it failed or you pressed Ctrl+C, CommitRocket remembers it in a small +file inside `.git`, so it is never committed. Carry on with the same command, or let it reuse +the settings the run started with: + +``` +commitrocket --repo . --resume +``` -- Commits that were made but not pushed are pushed first (they are listed in the plan, and - the usual confirmation applies). -- Files left staged by the interrupted batch are recognised as its own and committed with - their original message. Files you staged yourself still stop the run. -- Numbering continues after the interrupted batch. +Commits that were made but not pushed are pushed first, the files the run had staged are +committed with their original message, and numbering continues where it stopped. Repeating a +setting with `--resume` is fine as long as the value is the same; to change settings, run +without `--resume` and a new run starts. See +[Interrupted runs](docs/guides/cli.md#interrupted-runs) for the details and the cases where +`--resume` refuses to continue. ### Checks after each push @@ -488,3 +180,16 @@ git reset --mixed origin/main ``` Then run the same CommitRocket command again. + +## Support, contributing and security + +For help, see [SUPPORT.md](SUPPORT.md). Contributions are welcome. Start with +[CONTRIBUTING.md](CONTRIBUTING.md) and follow the [Code of Conduct](CODE_OF_CONDUCT.md). To +report a vulnerability, please read [SECURITY.md](SECURITY.md) first and do not open a +public issue. The guides and technical notes are listed in [docs/README.md](docs/README.md). + +## License + +See [LICENSE](LICENSE). CommitRocket depends on [Rich](https://github.com/Textualize/rich) +(MIT) and [pathspec](https://github.com/cpburnett/python-pathspec) (MPL-2.0). Git and +Git LFS are separate programs with their own licenses and are never bundled. diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..ae43184 --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,7 @@ +# Support + +- **Start with the docs:** the [README](README.md) covers installing and using CommitRocket. For every option see the [command line guide](docs/guides/cli.md); for more detail see the [architecture notes](docs/architecture.md) and the [development guide](docs/development.md). +- **Check your setup:** run `commitrocket doctor`. It reports your Python, Git and git-lfs versions, your config file, whether the remote is reachable and where logs are kept. +- **Questions and ideas:** use [GitHub Discussions](../../discussions) if enabled, otherwise open an issue with the feature request form. +- **Bugs:** open an issue with the bug report form. Include the CommitRocket version (`commitrocket --version`), your operating system, your Python, Git and git-lfs versions, your Git host, the full command and the error output. The log file helps too; re-run with `--level DEBUG` and attach the relevant lines. Leave out tokens, credentials and private paths. +- **Security problems:** see [SECURITY.md](SECURITY.md). Do not open a public issue. diff --git a/.github/social-preview.png b/brand/social-preview.png similarity index 100% rename from .github/social-preview.png rename to brand/social-preview.png diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..7160a19 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,5 @@ +# Documentation + +- **Guides:** [command line](guides/cli.md) and [configuration](guides/configuration.md). Start with the [project README](../README.md) for installing and a first run. +- **[Architecture](architecture.md) and [development](development.md):** how the repository fits together, how to work on it, and how it is tested and released. +- **Help and security:** [SUPPORT.md](../SUPPORT.md) for questions and bug reports, [SECURITY.md](../SECURITY.md) for vulnerabilities. diff --git a/docs/architecture.md b/docs/architecture.md index e762beb..2dc8420 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,20 +1,78 @@ # Architecture -Source lives in `src/commitrocket/`: - -| Module | Responsibility | -| --- | --- | -| `cli.py` | argparse, option validation, builds the `Console`, calls `runner.run` | -| `runner.py` | Preflight checks, confirmation, and the batch → commit → push loop; returns an exit code | -| `batching.py` | `select_batch` / `estimate_batch_count` (size-based packing) | -| `git.py` | `run_git` wrapper and pending/staged file helpers | -| `push.py` | Streams `git push --progress`; `parse_progress_line` is pure and unit tested | -| `ui.py` | Rich progress bar, run-info panel, final summary | -| `lfs.py` | `--use-lfs`: candidate detection (> 100 MiB), git-lfs install, `LfsSession` (enable / revert / uninstall) | -| `errors.py` | `CommitRocketError`, `GitError` | - -The `Console` is created in `cli.py` and passed down, so the logic is usable without a -global. +This document records the design as implemented. + +## Layers + +The command-line interface is a thin wrapper: it parses and validates options, builds +the `Console` and calls `core/runner`. The `Console` is created in `cli/execute.py` and +passed down, so the logic is usable without a global. + +``` +src/commitrocket/ + __init__.py __version__ + __main__.py python -m commitrocket + cli/ command-line interface + entry.py main(): dispatches `commitrocket doctor` or a normal run + parser.py argparse definition of every option + validate.py option checks and the effective --max-mib + execute.py run_main(): config, logging, run, report, notifications + resume.py run parameters and applying --resume + doctor.py doctor_main(): argparse and output for `commitrocket doctor` + core/ the batching logic + runner/ the run itself + flow.py run(): preflight, confirmation and the commit/push sequence + batches.py process_batches: the batch -> commit -> push loop + resume.py resume checks and state, resumed commits, committed LFS rules + setup.py LFS planning, local git config, LFS session set-up and release + dry_run.py --dry-run planning + helpers.py own_output_files, push_target + batching.py select_batch / plan_batches / estimate_batch_count + filters.py include / exclude via pathspec (gitignore-style) + options.py RunOptions + template.py commit message templates and the attribution line + verify.py post-push and LFS pointer checks + eta.py EtaEstimator, format_duration + git/ everything that talks to git + git.py run_git, pending/staged helpers, PushTarget, LocalConfig + lfs.py LFS candidates, git-lfs install, LfsSession + push.py streams `git push --progress`, retries + journal.py the resume journal (.git/commitrocket-journal.jsonl) + io/ what the user sees and what a run writes + ui.py Rich progress, panels and tables + logs.py per-run log file and redaction + report.py RunReport (the --report JSON) + notify.py desktop and webhook notifications + scripts/ toast.ps1, notification.applescript + support/ shared helpers + config.py commitrocket.toml / [tool.commitrocket] -> option defaults + doctor.py the checks behind `commitrocket doctor` + errors.py CommitRocketError, GitError, PushError + security.py redaction and input validation +``` + +`git/` depends only on `support/`, and `core/` builds on `git/` and `support/`. `io/` +renders what `core/` and `cli/` produce. Only `cli/` calls the runner, and +`support/doctor.py` is the one support module that looks across the others, because +it checks them all. + +## Imports and start-up + +Imports are lazy: a module imports what it needs inside the function that uses it. A +name that a class body, a default argument or a module constant needs when the module +loads (a base class, a compiled regular expression, a dataclass field default, `MIB`) +stays at the top of its module. This keeps `import commitrocket` cheap and means a +command pays only for the code it runs: `commitrocket --version` loads neither `rich` +nor `pathspec`, and a `--no-push` run never loads the push code. + +Settings that are data rather than logic live in files read on first use: the +notification scripts in `io/scripts/`. + +## Tests + +`tests/unit/` mirrors this tree (`cli/`, `core/`, `core/runner/`, `git/`, `io/`, +`support/`), with one `test_.py` per module that holds logic; +`tests/integration/` runs the real CLI against a local bare repository. See [development.md](development.md) for the markers and how to run them. Exit codes: `0` success, `1` error or cancelled, `2` bad repo path or deferred files remain, `130` interrupted. @@ -36,19 +94,28 @@ remain, `130` interrupted. ## Dry run, retries, resume and verification -- **`--dry-run`**: `runner.run` does all read-only preflight (including resume detection - and the over-100 MiB checks), then `batching.plan_batches` simulates the real selection - loop and `ui.print_dry_run` shows it. It returns 0 before any prompt, LFS install, config +- **`--dry-run`**: `run` (`core/runner/flow.py`) does all read-only preflight (including resume detection + and the over-100 MiB checks), then `core/runner/dry_run.py` simulates the real selection + loop (`batching.plan_batches`) and `ui.print_dry_run` shows it. It returns 0 before any prompt, LFS install, config change, journal write or commit. - **`--retries`**: `push.push_with_retries` wraps `push_with_progress`. A failed push raises `PushError` whose `retryable` flag is false when the output matches `NON_RETRYABLE_MARKERS` (host rejections, auth). Otherwise it waits 5 s, 15 s, 45 s... The same retry count applies to the post-push `ls-remote`. -- **Resume**: `journal.Journal` (`.git/commitrocket-journal.json`) is written before `git - add` and cleared after `git commit`. At startup, staged files that are a subset of the - journal's files are committed with its message and number; other staged files abort. - Unpushed commits (after the >100 MiB stuck-commit check) are pushed before new batches, - and numbering continues from `max(--number, journal number + 1)`. +- **Resume**: `git/journal.py::Journal` (`.git/commitrocket-journal.jsonl`, so never tracked) is an + append-only event log: `run` (version, every run parameter, branch, target, starting + HEAD), `staged` (before `git add`), `committed`, `pushed`, `resumed` and + `interrupted`/`failed`. `Journal.state()` replays it and ignores a line cut short by a + crash. `cli/resume.py::run_params` collects the parameters (everything except `NOT_RUN_PARAMS`) into + `RunOptions.params`. In `core/runner/flow.py::run`, a journal whose params equal the current ones + continues the run (plain re-run or `--resume`); different params replace it with a new + run. `--resume` (`cli/resume.py::apply_resume`) loads the stored params into the parsed arguments + and errors on explicitly passed values that differ; `core/runner/resume.py::check_resume` verifies + branch, target and that the last recorded commit is still in HEAD's history. Staged files + that are a subset of the in-flight batch are committed with its message and number; + other staged files abort. Unpushed commits (after the >100 MiB stuck-commit check) are + pushed before new batches, and numbering continues from the last committed number. The + journal is deleted when a run finishes; `--dry-run` never writes it. - **`--post-buffer-mib`**: sets `http.postBuffer` through `LocalConfig` for HTTP(S) remotes only (checked with `git remote get-url`), restored afterwards. - **Verification**: `verify.verify_remote_head` compares `git ls-remote ` @@ -60,20 +127,20 @@ remain, `130` interrupted. ## Options, config, filters, templates, targets, doctor -- **`RunOptions`** (`options.py`) carries every setting from `cli.py` to `runner.run`. -- **Config** (`config.py`): `cli.run_main` locates the file with a small pre-parser +- **`RunOptions`** (`core/options.py`) carries every setting from `cli/execute.py` to `run`. +- **Config** (`support/config.py`): `cli/execute.py::run_main` locates the file with a small pre-parser (`--repo`, `--config`), `find_config` reads `commitrocket.toml` or `[tool.commitrocket]` (via `tomllib`), and `apply_config` validates each value against the argparse action (type, choices, flag, append list) and installs it with `parser.set_defaults`, so the command line wins. `--include`/`--exclude` are `append` actions, so command-line values are added to the config's lists. -- **Filters** (`filters.py`): `FileFilter` uses `pathspec` (`gitwildmatch`, i.e. +- **Filters** (`core/filters.py`): `FileFilter` uses `pathspec` (`gitwildmatch`, i.e. `.gitignore` semantics). Include narrows, exclude wins; `.commitrocketignore` and - `--*-from` files are read with `read_patterns`. `runner.list_pending` applies the filter + `--*-from` files are read with `read_patterns`. `list_pending` in `core/runner/flow.py` applies the filter everywhere pending files are listed. -- **Templates** (`template.py`): `str.format` with fixed fields; `validate_template` +- **Templates** (`core/template.py`): `str.format` with fixed fields; `validate_template` renders sample values at startup so bad templates fail before any work. -- **Push target** (`git.PushTarget` / `resolve_target`): explicit `--remote/--branch`, +- **Push target** (`git/git.py`: `PushTarget` / `resolve_target`): explicit `--remote/--branch`, else `branch..remote/merge`, else the local branch name. Pushes use `git push HEAD:refs/heads/`. "Unpushed" means `refs/remotes//..HEAD`, or `HEAD --not --remotes=` when that @@ -81,22 +148,22 @@ remain, `130` interrupted. - **`--no-push`**: skips push and verification; rejected together with `--use-lfs`. - **`--lfs-commit-rules`** (default on with `--use-lfs`; `--no-lfs-commit-rules` turns it off): `LfsSession.write_committed_rules` appends one rule per extension (`committed_rule_lines`; exact path for extension-less or odd names) to - `.gitattributes` after checking it is clean. The runner commits it as + `.gitattributes` after checking it is clean. The runner (`core/runner/resume.py::commit_lfs_rules`) commits it as ` (LFS rules)` and pushes it before the first batch. Local-only rules in `.git/info/attributes` are not used in this mode; only the hooks are installed. - **LFS hook safety**: `verify.unpushed_has_lfs_pointers` scans unpushed blobs for LFS pointers. If any exist, resume installs the hooks before pushing, and a failed run keeps them installed (`LfsSession.close(uninstall_hooks=False)`) so a later push still uploads the data. -- **Doctor** (`doctor.py`): `collect_checks` returns `(status, name, detail)` rows +- **Doctor** (`support/doctor.py`): `collect_checks` returns `(status, name, detail)` rows (pass/warn/fail/skip) and `run_doctor` prints them; exit 1 if any failed. Network checks - are `git ls-remote` and `git push --dry-run`, skipped with `--offline`. `cli.main` + are `git ls-remote` and `git push --dry-run`, skipped with `--offline`. `cli/entry.py::main` dispatches `commitrocket doctor ...` before normal argument parsing, so existing invocations are unchanged. ## Report and notifications -`report.RunReport` is created in `cli.run_main` and filled by `runner.run`: it sets +`io/report.py::RunReport` is created in `cli/execute.py::run_main` and filled by `run`: it sets `status` (`success`, `completed_with_deferred_files`, `dry_run`, `cancelled`, `aborted`, `interrupted`, `failed`) at every exit path, records each batch (commit SHA, message, sizes, `pushed`, `verified`) as it happens, and holds the deferred files, resume counts and @@ -104,26 +171,27 @@ LFS details. `RunReport.write` writes JSON via a temporary file and `os.replace` reader never sees a half-written report. The settings come from `asdict(RunOptions)`; the webhook URL is deliberately not part of `RunOptions`, so it can't leak into a report. -`cli.run_main` calls `finish`, writes the report and then `notify.send_notifications` +`run_main` calls `finish`, writes the report and then `notify.send_notifications` (skipped for `--dry-run`), all before logging is closed. Desktop notifications use only built-in tools and pass the text through environment variables (`CR_TITLE`, `CR_BODY`) to avoid quoting problems: Windows PowerShell's `Windows.UI.Notifications` toast (using PowerShell's own AppUserModelID, which Windows already trusts), `osascript` on macOS, -`notify-send` on Linux, then the terminal bell. The webhook is a stdlib `urllib` POST +`notify-send` on Linux, then the terminal bell. The Windows and macOS scripts are files in +`io/scripts/` (`toast.ps1`, `notification.applescript`), read only when a notification is sent. The webhook is a stdlib `urllib` POST restricted to http(s) URLs with a 10 s timeout. Delivery errors are logged and printed, never raised. ## Security hardening -Findings from the security review and what addresses them (`security.py` holds the helpers): +Findings from the security review and what addresses them (`support/security.py` holds the helpers): - **Literal file names**: `run_git` sets `GIT_LITERAL_PATHSPECS=1`, so a name such as `[ab].txt` stages only that file instead of also matching `a.txt` and `b.txt`. - **No option injection**: `--remote` / `--branch` (and values from config or the upstream) are rejected if empty, starting with `-`, or containing spaces or control - characters (`validate_ref_part`, checked in `cli.validate` and `git.resolve_target`), + characters (`validate_ref_part`, checked in `cli/validate.py` and `git/git.py::resolve_target`), and `--` precedes the remote in `push`, `ls-remote` and `remote get-url`. -- **Untrusted repository config**: `config.apply_config` ignores `SENSITIVE_KEYS` +- **Untrusted repository config**: `support/config.py::apply_config` ignores `SENSITIVE_KEYS` (`force`, `remote`, `branch`, `report`, `log_file`, `notify_webhook`, `include_from`, `exclude_from`) unless the file was passed with `--config`. The ignored names are printed and logged. @@ -132,7 +200,7 @@ Findings from the security review and what addresses them (`security.py` holds t shown on the console, and to the report's `error` field. - **Private files**: log and report files are restricted to the owner (`0600`, best effort on Windows). -- **Rule injection**: `lfs.attribute_line` refuses file names with control characters, so +- **Rule injection**: `git/lfs.py::attribute_line` refuses file names with control characters, so a newline cannot add attribute lines. - **Report temp file**: `RunReport.write` uses `tempfile.mkstemp` (random name, created exclusively) in the target folder, then `os.replace`. @@ -142,7 +210,7 @@ Findings from the security review and what addresses them (`security.py` holds t ## Logging -`logs.setup_logging` (called from `cli.main`) attaches one `FileHandler` to the +`io/logs.py::setup_logging` (called from `cli/execute.py` and `cli/doctor.py`) attaches one `FileHandler` to the `commitrocket` logger, with `propagate = False` so nothing reaches the console, which is Rich's job. The file is `commitrocket-.log` in `default_log_dir()` (per OS) or `--log-file`. If the file can't be opened the run continues without logging. Modules use @@ -153,11 +221,11 @@ log path is printed after the run on every exit path. ## ETA -`eta.EtaEstimator` (not Rich's `TimeRemainingColumn`) computes the ETA as remaining bytes +`core/eta.py::EtaEstimator` (not Rich's `TimeRemainingColumn`) computes the ETA as remaining bytes divided by the run's average speed: bytes completed, including the part of the current batch already uploaded, over the time since the first batch started. It reports nothing for the first 5 seconds. The estimator is attached to the overall task as a task field, -and `ui.EtaColumn` calls it on every Rich refresh, so the countdown ticks without needing +and the progress column built in `io/ui.py::make_progress` calls it on every Rich refresh, so the countdown ticks without needing progress events. The push row has no estimator and shows no ETA. ## Batch types diff --git a/docs/development.md b/docs/development.md index 71287b5..df69c52 100644 --- a/docs/development.md +++ b/docs/development.md @@ -7,6 +7,36 @@ uv sync # creates .venv with the dev tools uv run pre-commit install # lint + unit tests before every commit ``` +The layout of the code is described in [architecture.md](architecture.md). Tests live in +`tests/`, with `tests/unit/` mirroring `src/commitrocket/`; see [Tests](#tests) below. + +## Common tasks + +``` +uv run pytest -m "not integration" -n auto # unit tests +uv run pytest -m integration # end to end, against a local bare repository +uv run ruff check . # lint +uv run mypy # type check +``` + +`sweepito.toml` configures Sweepito for this repository, if you use it to clean caches and +build output (`.venv/` is kept). + +## Imports + +Imports are lazy: a module imports what it needs inside the function that uses it. A name +needed when the module loads (a base class, a compiled regular expression, a dataclass field +default, a module constant) stays at the top of its module. Tests that patch a standard +library module should patch the module itself (for example `sys` or `shutil`), not an +attribute of the module under test, because the import happens inside the function. + +## Data files + +Notification scripts are kept out of the code and read when a notification is sent: +`src/commitrocket/io/scripts/toast.ps1` (Windows) and `notification.applescript` (macOS). +They receive the title and body through the `CR_TITLE` and `CR_BODY` environment variables, +never in the script text. Both are packaged with the wheel. + ## Tests Tests are marked, so you can pick what to run: @@ -17,6 +47,12 @@ Tests are marked, so you can pick what to run: | `uv run pytest -m "not integration"` | Unit tests only (fast; what pre-commit runs) | | `uv run pytest -m integration` | End-to-end tests in `tests/integration/` | +Unit tests live in `tests/unit/` and mirror `src/commitrocket/`: a test for +`core/batching.py` goes in `tests/unit/core/test_batching.py`. Shared fixtures are in +`tests/conftest.py`. The test folders have no `__init__.py` and pytest runs with +`--import-mode=importlib`, so two modules in different folders can both have a +`test_doctor.py` or `test_resume.py`. + Pre-commit and the `tests.yml` workflow run pytest in parallel with `pytest-xdist` (`-n auto`, one worker per CPU core). Add `-n auto` locally for speed, or leave it off when debugging a single test, since output and breakpoints are easier without workers. @@ -26,10 +62,11 @@ so they need only Git. They carry `pytestmark = pytest.mark.integration`; new en tests belong in `tests/integration/` with the same marker. Markers are registered in `pyproject.toml` and `--strict-markers` is on, so a typo in a marker name is an error. -## Lint +## Lint and type check ``` uv run ruff check . +uv run mypy ``` ## Pre-commit @@ -43,24 +80,30 @@ versions with `uv run pre-commit autoupdate`. | Workflow | When | What | | --- | --- | --- | -| `lint.yml` | Pushes to `main`, pull requests | `ruff check` | +| `lint.yml` | Pushes to `main`, pull requests | `ruff check` and `mypy` | | `tests.yml` | Pushes to `main`, pull requests | Unit then integration tests on Ubuntu with Python 3.11, 3.12, 3.13, 3.14 and 3.15, and on Windows and macOS with 3.11. The 3.15 job may fail without failing the build while that version is a pre-release. | -| `release.yml` | Pushing a tag like `v0.2.0` | Checks the tag against the package version, re-runs lint and all tests, builds with `uv build`, publishes to PyPI and creates a GitHub release with the files attached | +| `release.yml` | Pushing a tag like `v0.2.0` | Checks the tag against the package version, re-runs lint and all tests, builds with `uv build`, attests the build provenance, publishes to PyPI and creates a GitHub release with the files attached | ## Releasing -1. Update `version` in `pyproject.toml` and `__version__` in - `src/commitrocket/__init__.py` (they must match), and move the `[Unreleased]` entries in - `CHANGELOG.md` under the new version. -2. Commit and push to `main`. -3. Tag and push the tag: +1. Choose the version with [Semantic Versioning](https://semver.org/): a patch (`0.1.3`) + for fixes only, a minor (`0.2.0`) for new features, a major for breaking changes to the + command line. Before 1.0, a minor may also carry breaking changes; say so under + `### Changed`. Update `version` in `pyproject.toml` and `__version__` in + `src/commitrocket/__init__.py` (they must match). +2. Move the `[Unreleased]` entries in `CHANGELOG.md` under the new version, keeping the + headings that are used. +3. Commit and push to `main`. +4. Tag and push the tag: ``` git tag v0.2.0 git push origin v0.2.0 ``` -One-time setup: create a PyPI API token and save it as the repository secret -`PYPI_API_TOKEN`. The publish job uses a GitHub environment named `pypi`, which you can -configure with required reviewers if you want a manual approval before each release. Scope -the token to this project once the first release has created it on PyPI. +The release workflow checks the tag against both versions, runs lint and all tests, +publishes to PyPI with trusted publishing (no API token is stored), and creates a GitHub +release. Trusted publishing needs the repository, the workflow `release.yml` and the +`pypi` environment registered as a trusted publisher in the PyPI project settings. The +`pypi` GitHub environment can require reviewers if you want a manual approval before each +release. diff --git a/docs/guides/cli.md b/docs/guides/cli.md new file mode 100644 index 0000000..2261890 --- /dev/null +++ b/docs/guides/cli.md @@ -0,0 +1,489 @@ +# Command line guide + +``` +commitrocket --message [options] +commitrocket doctor [options] +``` + +| Command | What it does | +|---|---| +| `commitrocket` | Split the pending changes into size-limited batches, commit each one and push it | +| `commitrocket doctor` | Check that Git, git-lfs, the repository, the remote and your settings are ready. Changes nothing | + +Add `--help` for the options of either command. Run the command inside the repository, or +point at it with `--repo`. + +## How a run works + +1. CommitRocket looks at the files you have changed or added and not yet committed. +2. It packs them into batches no bigger than `--limit-mib`, using the rule chosen with + `--batch-type`. +3. For each batch it stages the files, makes a commit and pushes it, then checks that the + remote now has that commit. +4. Files bigger than `--max-mib` are left out and listed at the end. With `--use-lfs`, big + files go through Git LFS instead of being left out. + +A run asks for confirmation first. Use `--dry-run` to see the plan without changing +anything, and `--force` to skip the question. + +## Exit codes + +| Code | Meaning | +|---|---| +| 0 | Everything was processed | +| 1 | An error stopped the run, or you cancelled at the prompt | +| 2 | The run did not start, or files were left out: bad repository path, files over the host limit without `--use-lfs`, unpushed commits that the host would reject, or files above `--max-mib` | +| 130 | Interrupted with Ctrl+C. Run the same command again to resume | + +`commitrocket doctor` exits 1 if any check failed and 0 otherwise. + +## Options + +### Repository and message + +| Option | Default | What it does | +|---|---|---| +| `--repo PATH` | `.` | The Git repository to work in | +| `--config FILE` | none | Read settings from this TOML file instead of `commitrocket.toml` or `[tool.commitrocket]` in `pyproject.toml` | +| `--message TEXT` | none | Base commit message. Required here or in the config file | +| `--message-template TEXT` | `{message} #{n}` | The message of each batch. Placeholders: `message`, `n`, `batch`, `files`, `size`, `first`, `date` | +| `--no-attribution`, `--ignore-attribution` | off | Do not append the "Prepared and Committed By: CommitRocket" line to commit messages | +| `--number N` | 1 | Number of the first commit (`{n}` in the template) | + +### Choosing files + +All patterns use `.gitignore` syntax. Exclusion always wins over inclusion, and patterns in +`.commitrocketignore` are always excluded. + +| Option | What it does | +|---|---| +| `--include GLOB` | Only handle files matching this pattern. Repeat for more | +| `--exclude GLOB` | Leave files matching this pattern alone. Repeat for more | +| `--include-from FILE` | Read `--include` patterns from a file, one per line (`#` starts a comment) | +| `--exclude-from FILE` | Read `--exclude` patterns from a file, one per line | + +### Batches + +| Option | Default | What it does | +|---|---|---| +| `--limit-mib N` | 100 | Normal batch size in MiB. Must be positive | +| `--max-mib N` | 3 x `--limit-mib` | Largest single file to handle, in MiB. Must be at least `--limit-mib`. Bigger files are left out | +| `--batch-type TYPE` | `deterministic` | How files are picked: `deterministic` packs first-fit and skips files that do not fit, `sequential` takes files strictly in order, `soft` takes files in order and may pass `--limit-mib` up to `--max-mib` | + +### Pushing + +| Option | Default | What it does | +|---|---|---| +| `--remote NAME` | the branch's upstream remote | Remote to push to | +| `--branch NAME` | the upstream branch, else the current branch name | Remote branch to push to | +| `--no-push` | off | Commit every batch but do not push. A later run pushes them. Cannot be combined with `--use-lfs` | +| `--retries N` | 3 | Retry a failed push this many times, waiting 5 s, 15 s, 45 s and so on. Rejections such as file-size limits are never retried | +| `--post-buffer-mib N` | none | Raise Git's `http.postBuffer` for this run (HTTP and HTTPS remotes only). Helps with "RPC failed" and HTTP 408/500 errors on large pushes | +| `--compression-threads N` | Git's default | Threads Git uses to compress objects (`pack.threads`; 0 means automatic) | + +`--remote` and `--branch` may not be empty, start with `-`, or contain spaces or control +characters. + +### Git LFS + +| Option | Default | What it does | +|---|---|---| +| `--use-lfs` | off | Send big files through Git LFS for this run, installing git-lfs if needed and undoing the local setup afterwards | +| `--lfs-threshold-mib N` | 100 | With `--use-lfs`, files larger than this go through LFS. Between 0 and 100; 0 means every file | +| `--lfs-commit-rules` / `--no-lfs-commit-rules` | on | With `--use-lfs`, commit one LFS rule per file extension to `.gitattributes` so clones get real files. With `--no-lfs-commit-rules` the rules stay local to the run and clones contain LFS pointer files | +| `--lfs-threads N` | git-lfs default | Concurrent LFS uploads (`lfs.concurrenttransfers`). Must be positive | +| `--lfs-batch-mib N` | same as `--limit-mib` | Total size of LFS files pushed together, so they can upload at the same time | + +### Safety + +| Option | What it does | +|---|---| +| `--dry-run` | Show the batches and commit messages that would be made, without staging, committing or pushing anything | +| `--force` | Skip the confirmation prompt, and install git-lfs without asking | +| `--resume` | Continue the interrupted run in this repository with the settings it started with (see [Interrupted runs](#interrupted-runs)) | + +### Output + +| Option | Default | What it does | +|---|---|---| +| `--report FILE` | none | Write a JSON summary of the run. Also written when the run fails, is interrupted or is a dry run | +| `--notify` | off | Show a desktop notification when the run ends | +| `--notify-webhook URL` | none | Send a JSON summary to this http(s) URL when the run ends (Slack, Discord, Teams, ntfy or your own endpoint) | +| `--level LEVEL` | `INFO` | Log level written to the log file: `DEBUG`, `INFO`, `WARNING` or `ERROR`. `DEBUG` also records every git command and the push output | +| `--log-file FILE` | per-user log folder | Write the log here instead | + +Notifications are not sent for a dry run. + +## Config file + +Every option above except `--repo`, `--config`, `--help` and `--version` can be set in +`commitrocket.toml` or in a `[tool.commitrocket]` table of `pyproject.toml`. Use the option +name, with dashes or underscores. Flags take `true` or `false`, and `include`, `exclude`, +`include-from` and `exclude-from` take lists. Options given on the command line win. + +```toml +# commitrocket.toml +message = "Add photos" +limit-mib = 50 +exclude = ["*.tmp", "cache/"] +use-lfs = true +``` + +A config file found inside the repository is untrusted, because anyone who can change the +repository can change it. It cannot set `force`, `remote`, `branch`, `report`, `log-file`, +`notify-webhook`, `include-from` or `exclude-from`: those are ignored, and CommitRocket +prints which ones. They work in a file you name yourself with `--config`. + +## doctor + +``` +commitrocket doctor [--repo PATH] [--remote NAME] [--branch NAME] [--config FILE] [--offline] +``` + +It reports the Python, Git and git-lfs versions, the config file in use, whether the log +folder is writable, the repository, branch and push target, whether the remote is reachable +and a push would be accepted, staged files, unpushed commits and pending files. Each row is +`PASS`, `WARN`, `FAIL` or `SKIP`. `--offline` skips the two checks that contact the remote. + +## File patterns + +`--include` and `--exclude` take `.gitignore`-style patterns and can be repeated: + +| Pattern | Matches | +| --- | --- | +| `*.mp4` | Every `.mp4` file, in any folder (this is how you select by extension) | +| `raw/` | The `raw` folder and everything in it | +| `/notes.txt` | Only `notes.txt` in the repository root | +| `videos/**/*.mov` | `.mov` files anywhere under `videos` | +| `!keep.mp4` | Re-includes a file matched by an earlier pattern in the same list | + +With `--include`, only matching files are handled. Anything matching `--exclude` is left +alone, and exclusion always wins. Files that are filtered out are not staged, committed or +counted as skipped; they simply stay pending. + +For longer lists, put one pattern per line in a file (blank lines and `#` comments are +ignored) and pass it with `--include-from` or `--exclude-from`. A file named +`.commitrocketignore` in the repository root is read automatically as a permanent list of +excludes. + +``` +commitrocket --repo . --message "Videos" --include "*.mp4" --include "*.mov" --exclude "raw/" +commitrocket --repo . --message "Videos" --include-from patterns.txt +``` + +## Commit messages + +`--message-template` decides the message of each batch. The default is `{message} #{n}`. + +| Placeholder | Value | +| --- | --- | +| `{message}` | The `--message` text | +| `{n}` | The commit number (starts at `--number`) | +| `{batch}` | The batch's position in this run, starting at 1 | +| `{files}` | Number of files in the batch | +| `{size}` | Size of the batch in MiB (e.g. `{size:.1f}`) | +| `{first}` | Path of the first file in the batch | +| `{date}` | Today's date, `YYYY-MM-DD` | + +``` +commitrocket --repo . --message "Course" --message-template "{message} part {n}: {files} files ({size:.0f} MiB)" +``` + +### Attribution + +Every commit [CommitRocket](https://pypi.org/project/commitrocket/) creates ends with an +attribution line, separated from the message by a blank line: + +``` +Prepared and Committed By: 🚀 CommitRocket (https://github.com/coldsofttech/CommitRocket) +``` + +It is added to batch commits, the LFS rules commit and resumed commits, and it is shown in +`--dry-run` output and the JSON report. It is never added twice to the same message. To +leave your messages exactly as written, pass `--no-attribution` (or `--ignore-attribution`), +or set `no-attribution = true` in the config file. + +## Batch types + +Files are always taken in alphabetical order. For files A=60, B=50, C=30, D=20 MiB with a +100 MiB limit: + +| Type | How it picks | Batches | +| --- | --- | --- | +| `deterministic` (default) | Fills each batch, skipping a file that doesn't fit and trying later ones | A + C, then B + D | +| `sequential` | Strict order; a batch ends at the first file that doesn't fit | A, then B + C + D | +| `soft` | Strict order; keeps adding until the batch reaches or passes the limit, never above `--max-mib` in total | A + B, then C + D | + +Files larger than the batch limit (but under the maximum) get a batch of their own. +Files over the maximum are skipped and listed at the end so you can decide what to do. + +## Using Git LFS + +Hosts like GitHub reject files over 100 MiB. With `--use-lfs`, CommitRocket stores those +files with Git LFS instead: + +1. Installs git-lfs if it is missing (asks first, unless `--force`). +2. Routes each file over 100 MiB through LFS using a rule that only exists on your + machine. Nothing extra is committed to your repository. +3. Pushes your files in batches as usual. +4. Removes the local LFS setup when it finishes, even if the run fails. + +The large files are stored in LFS on the remote. Because no tracking rules are committed, +a fresh clone will show small pointer files for them until LFS tracking is set up there. + +By default only files over 100 MiB use LFS. Lower the cut-off with `--lfs-threshold-mib` +(for example `50`), or use `0` to send every file through LFS. Take care with `0`: because +no tracking rules are committed, anyone cloning the repository will see small pointer +files in place of all your content, and LFS storage and bandwidth quotas on the host are +used up quickly. Git's own settings files (`.gitattributes`, `.gitignore`, `.lfsconfig`) +always stay as normal files. The threshold cannot be above 100, since larger files are +rejected by hosts. + +So that checkouts and clones receive the real files, CommitRocket commits the LFS rules by default. It commits +one rule per file type (for example `*.mp4`) to `.gitattributes` as ` (LFS rules)`, +pushes it first, and your files follow as LFS pointers. Because rules are per type, every +file of that type is stored in LFS from then on, including small ones and future ones. +Files without an extension get an exact-path rule. `.gitattributes` must have no +uncommitted changes beforehand. Pass `--no-lfs-commit-rules` to skip this; videos then turn into +text pointer files after a pull, reset or clone. + +If a run fails after committing LFS files but before pushing them, the LFS hooks are left +installed so the files can still be uploaded. Run CommitRocket again to finish; avoid a +plain `git push` unless the hooks are still installed. + +Each LFS file normally gets its own push. To upload several at once, raise +`--lfs-batch-mib` (for example `--lfs-batch-mib 500 --lfs-threads 4`). + +The thread settings only change the repository's own Git configuration for the duration +of the run and are put back afterwards. Your global Git configuration is never touched. + +If you run CommitRocket without `--use-lfs` and a file is over 100 MiB, it stops before +committing anything and tells you to use the flag. + +## Report and notifications + +`--report out.json` writes a machine-readable summary every time, including when the run +fails, is interrupted or is a dry run, so scripts and CI can read the result: + +```json +{ + "schema_version": 1, + "status": "success", + "exit_code": 0, + "target": "origin/main", + "duration_seconds": 412.7, + "totals": { "batches": 3, "files": 42, "size_bytes": 1234567890, "deferred_files": 0 }, + "batches": [ + { "number": 1, "message": "Videos #1", "commit": "e57cffb...", "file_count": 14, + "size_bytes": 412345678, "lfs_file_count": 2, "pushed": true, "verified": true, + "files": ["..."] } + ], + "deferred": [], + "error": null, + "log_file": "..." +} +``` + +`status` is one of `success`, `completed_with_deferred_files`, `dry_run`, `cancelled`, +`aborted` (stopped before doing anything, for example files needing `--use-lfs`), +`interrupted` and `failed`. The report also lists your settings, what was resumed, the LFS +files and the commit that holds the LFS rules. It never contains the webhook address. + +Long runs can tell you when they are done: + +| Option | What happens | +| --- | --- | +| `--notify` | A desktop notification: a toast on Windows, a notification on macOS, `notify-send` on Linux. If none of these works (for example over SSH), the terminal bell sounds instead. | +| `--notify-webhook URL` | A JSON message is POSTed to the address. It has `text` and `content` fields, so Slack, Teams and Discord incoming webhooks work, plus `status`, `batches`, `files` and `duration_seconds` for your own endpoint. [ntfy](https://ntfy.sh) also works. | + +Notifications are sent when the run ends, whether it succeeded or not, and never for +`--dry-run`. A notification that can't be delivered never changes the run's result. + +## Logs + +Every run writes its own log file, and the path is shown at the end of the run. Logs are +kept here by default: + +| System | Folder | +| --- | --- | +| Windows | `%LOCALAPPDATA%\CommitRocket\Logs\` | +| macOS | `~/Library/Logs/CommitRocket/` | +| Linux | `~/.local/state/commitrocket/` (or `$XDG_STATE_HOME/commitrocket/`) | + +Files are named `commitrocket-YYYYMMDD-HHMMSS.log`. Use `--level DEBUG` to also record +every Git command and the push output, which helps when a push fails. Old logs are not +deleted automatically. + + +## Interrupted runs + +If a run stops, whether from an error, a failed push or Ctrl+C, CommitRocket remembers it in +a small file inside `.git` (`commitrocket-journal.jsonl`), so it is never committed. It is +deleted when a run finishes. + +To carry on, either run the same command again or use `--resume`: + +``` +commitrocket --repo . --resume +``` + +- `--resume` reuses the settings the interrupted run started with, so you don't type them + again. Options that only affect how a run is shown or written (`--force`, `--dry-run`, + `--report`, `--log-file`, `--level`, `--notify`, `--notify-webhook`) are not remembered and + work as usual. +- You may repeat a setting with `--resume`, but only with the same value. A different value + is an error. To change settings, run without `--resume`: a new run starts. +- Running the same command again without `--resume` also continues the run when the + settings are identical. With different settings it starts a new run and replaces the old + record. +- `--resume` stops with a clear message if there is no interrupted run, if the record is + damaged or from another version, if you are on a different branch or push target, or if + the repository changed (a commit the run made is no longer in the branch's history). + +When continuing, CommitRocket recognises the files it left staged, commits them with their +original message, pushes any commits that are still waiting, and carries on numbering from +there. Files you staged yourself still stop the run. + +## Examples + +Run these from inside the repository (`--repo .`), or point `--repo` at any path. + +**Push everything in 100 MiB batches (the default)** +``` +commitrocket --repo . --message "Add assets" +``` + +**Leave it running and get told when it's done** +``` +commitrocket --repo . --message "Videos" --use-lfs --notify +commitrocket --repo . --message "Videos" --notify-webhook https://ntfy.sh/my-topic +``` + +**Results for scripts and CI** +``` +commitrocket --repo . --message "Nightly" --force --report result.json +``` + +**Check everything is ready** +``` +commitrocket doctor +``` + +**Only some files, or everything except some** +``` +commitrocket --repo . --message "Videos" --include "*.mp4" --exclude "raw/" +``` + +**Push to a different remote or branch** +``` +commitrocket --repo . --message "Backup" --remote backup --branch main +``` + +**Commit now, push later** +``` +commitrocket --repo . --message "Add assets" --no-push +commitrocket --repo . --message "Add assets" # later: pushes the saved commits +``` + +**Videos in LFS that clones can download too** +``` +commitrocket --repo . --message "Videos" --use-lfs +``` + +**See what would happen first** + +Prints every batch, its commit message and size, and any files that would be skipped. +Nothing is staged, committed, pushed or installed. +``` +commitrocket --repo . --message "Add assets" --use-lfs --dry-run +``` + +**Flaky connection or "RPC failed" errors** + +Failed pushes are retried automatically (3 times by default, after 5, 15 and 45 +seconds). A bigger HTTP buffer helps with timeouts on large uploads over HTTPS. +``` +commitrocket --repo . --message "Videos" --retries 5 --post-buffer-mib 500 +``` + +**Smaller batches for a slow or unreliable connection** + +Each push is shorter, so a failure costs less to repeat. +``` +commitrocket --repo . --message "Add assets" --limit-mib 50 +``` + +**Continue numbering after an earlier run** + +If the last commit was `Videos #21`, the next batch becomes `Videos #22`. +``` +commitrocket --repo . --message "Videos" --number 22 +``` + +**Run without prompts (scripts, scheduled jobs)** +``` +commitrocket --repo . --message "Nightly sync" --force +``` + +**Keep files in order, such as numbered lectures** + +`sequential` never skips ahead, so `01`, `02`, `03` land in commits in that order. +``` +commitrocket --repo . --message "Course videos" --batch-type sequential +``` + +**Fewer, larger pushes** + +`soft` lets a batch run slightly past the limit instead of leaving gaps. +``` +commitrocket --repo . --message "Add assets" --batch-type soft --limit-mib 100 --max-mib 300 +``` + +**Files over 100 MiB (videos, archives, datasets)** + +GitHub rejects these, so use LFS. Without `--use-lfs`, CommitRocket stops before +committing anything and lists the files. +``` +commitrocket --repo . --message "Videos" --use-lfs +``` + +**Many large files, faster uploads** + +Group several LFS files per push and upload four at a time. +``` +commitrocket --repo . --message "Videos" --use-lfs --lfs-batch-mib 500 --lfs-threads 4 +``` + +**Also move mid-size files (over 50 MiB) to LFS** + +GitHub warns about files above 50 MiB, even though it accepts them. +``` +commitrocket --repo . --message "Assets" --use-lfs --lfs-threshold-mib 50 +``` + +**Send every file through LFS** + +Use with care: clones will show pointer files for all content. +``` +commitrocket --repo . --message "Archive" --use-lfs --lfs-threshold-mib 0 +``` + +**Allow bigger individual files** + +Files above `--max-mib` (default 3x the limit) are skipped and reported at the end. +``` +commitrocket --repo . --message "Videos" --use-lfs --max-mib 500 +``` + +**Find out why a push failed** + +The log records every Git command and the push output. Its path is printed at the end. +``` +commitrocket --repo . --message "Add assets" --level DEBUG +commitrocket --repo . --message "Add assets" --level DEBUG --log-file push-debug.log +``` + +**Check the setup without contacting the remote** +``` +commitrocket doctor --repo path/to/repo --offline +``` diff --git a/docs/guides/configuration.md b/docs/guides/configuration.md new file mode 100644 index 0000000..9a11d94 --- /dev/null +++ b/docs/guides/configuration.md @@ -0,0 +1,110 @@ +# Configuration + +CommitRocket reads defaults from `commitrocket.toml`, or from a `[tool.commitrocket]` table +in `pyproject.toml`, in the repository folder. Use `--config FILE` to read a different +file. Precedence: command line, config file, built-in defaults. `include` and `exclude` +lists from the file and the command line are combined. A flag set to `true` in the file +cannot be switched off from the command line (except `lfs-commit-rules`, which has +`--no-lfs-commit-rules`). + +## Where the file is found + +Without `--config`, CommitRocket looks only in the repository folder (`--repo`, default the +current folder), not in parent folders: + +1. `commitrocket.toml`, if it exists. +2. Otherwise the `[tool.commitrocket]` table of `pyproject.toml`, if the table has any + settings. + +Run `commitrocket doctor` to see which file is in use. CommitRocket also prints +`Using config: ` at the start of a run. + +## Trusting a config file + +A file found in the repository might belong to someone else (a cloned repository, a +downloaded folder), because anyone who can change the repository can change it. So a file +found this way **cannot** set options that skip the confirmation, push somewhere else, +write files or contact other servers: + +`force`, `remote`, `branch`, `report`, `log-file`, `notify-webhook`, `include-from` and +`exclude-from`. + +These settings are ignored, and CommitRocket prints and logs which ones. If you wrote the +file and trust it, name it yourself, which counts as trusting it: + +``` +commitrocket --config commitrocket.toml +``` + +Everything else (limits, batch type, filters, retries, `use-lfs`, `dry-run` and so on) +works from a found file as usual. All of these settings work as normal command-line +options too. + +## Keys + +Keys use the option names, with dashes or underscores: `limit-mib` for `--limit-mib`. +Unknown keys or invalid values stop the run with exit code 2 and a message naming the file +and the key. The options `repo`, `config`, `help` and `version` cannot be set in a file. + +```toml +# commitrocket.toml +message = "Add videos" +message-template = "{message} #{n} ({files} files, {size:.0f} MiB)" +limit-mib = 50 +batch-type = "sequential" +exclude = ["raw/", "*.tmp"] +use-lfs = true +retries = 5 +``` + +The same settings in `pyproject.toml`: + +```toml +[tool.commitrocket] +message = "Add videos" +limit-mib = 50 +``` + +| Key | Type | Meaning | +|---|---|---| +| `message` | string | Base commit message | +| `message-template` | string | Message of each batch; placeholders `message`, `n`, `batch`, `files`, `size`, `first`, `date` | +| `no-attribution` | true / false | Do not append the CommitRocket attribution line | +| `number` | integer | Number of the first commit | +| `include`, `exclude` | list of strings | `.gitignore`-style patterns | +| `include-from`, `exclude-from` | list of strings | Files of patterns (only from a trusted file) | +| `limit-mib` | integer | Normal batch size in MiB | +| `max-mib` | integer | Largest single file in MiB | +| `batch-type` | string | `deterministic`, `sequential` or `soft` | +| `remote`, `branch` | string | Push target (only from a trusted file) | +| `no-push` | true / false | Commit but do not push | +| `retries` | integer | Push retries | +| `post-buffer-mib` | integer | Raise `http.postBuffer` for the run | +| `compression-threads` | integer | `pack.threads` for the run | +| `use-lfs` | true / false | Send big files through Git LFS | +| `lfs-threshold-mib` | integer | Size above which files go through LFS (0 to 100) | +| `lfs-commit-rules` | true / false | Commit LFS rules to `.gitattributes` (default `true`) | +| `lfs-threads` | integer | Concurrent LFS uploads | +| `lfs-batch-mib` | integer | Total size of LFS files pushed together | +| `dry-run` | true / false | Only show the plan | +| `force` | true / false | Skip the confirmation (only from a trusted file) | +| `report` | string | Path of the JSON report (only from a trusted file) | +| `notify` | true / false | Desktop notification at the end | +| `notify-webhook` | string | http(s) URL for the end-of-run summary (only from a trusted file) | +| `level` | string | `DEBUG`, `INFO`, `WARNING` or `ERROR` | +| `log-file` | string | Log file path (only from a trusted file) | + +Types are checked: a flag must be `true` or `false`, the list keys must be lists of +strings, and a list or table is rejected where a single value is expected. The command line +limits apply too, for example `limit-mib` must be positive and `max-mib` at least `limit-mib`. +`--no-push` still cannot be combined with `use-lfs`. See the +[command line guide](cli.md) for what each option does. + +## Ignore file + +`.commitrocketignore` in the repository root lists extra patterns to leave out, one per +line in `.gitignore` syntax. They are always excluded, whether or not a config file exists. + +## Environment variables + +CommitRocket does not read any environment variables for its settings. diff --git a/pyproject.toml b/pyproject.toml index f8d6ffa..aa7449f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "commitrocket" -version = "0.1.2" +version = "0.1.3" description = "Batch Git changes by size, commit each batch, and push with live progress." readme = "README.md" license = { file = "LICENSE" } @@ -34,7 +34,13 @@ Issues = "https://github.com/coldsofttech/CommitRocket/issues" commitrocket = "commitrocket.cli:main" [dependency-groups] -dev = ["pytest>=8", "pytest-xdist>=3", "ruff>=0.6", "pre-commit>=3"] +dev = [ + "pytest>=8", + "pytest-xdist>=3", + "ruff>=0.6", + "pre-commit>=3", + "mypy>=1.10", +] [tool.uv] package = true @@ -45,7 +51,7 @@ packages = ["src/commitrocket"] [tool.pytest.ini_options] testpaths = ["tests"] pythonpath = ["src"] -addopts = "--strict-markers" +addopts = "--strict-markers --import-mode=importlib" markers = [ "integration: end-to-end runs against a local bare repository (slower; excluded from pre-commit, run in CI)", ] @@ -57,3 +63,7 @@ src = ["src", "tests"] [tool.ruff.lint] select = ["E", "F", "I", "UP", "B"] + +[tool.mypy] +files = ["src"] +python_version = "3.11" diff --git a/src/commitrocket/__init__.py b/src/commitrocket/__init__.py index 9fccbdc..c05ab0d 100644 --- a/src/commitrocket/__init__.py +++ b/src/commitrocket/__init__.py @@ -1,3 +1,3 @@ """CommitRocket: batch Git changes by size, commit each batch, and push.""" -__version__ = "0.1.2" +__version__ = "0.1.3" diff --git a/src/commitrocket/cli.py b/src/commitrocket/cli.py deleted file mode 100644 index d3d639e..0000000 --- a/src/commitrocket/cli.py +++ /dev/null @@ -1,437 +0,0 @@ -import argparse -import logging -import sys - -from rich.console import Console -from rich.markup import escape - -from commitrocket import __version__ -from commitrocket.batching import BATCH_TYPES, DETERMINISTIC -from commitrocket.config import ConfigError, apply_config, find_config -from commitrocket.doctor import run_doctor -from commitrocket.errors import CommitRocketError -from commitrocket.lfs import LFS_THRESHOLD_MIB -from commitrocket.logs import ( - DEFAULT_LEVEL, - LOG_LEVELS, - close_logging, - default_log_dir, - setup_logging, -) -from commitrocket.notify import is_valid_webhook, send_notifications -from commitrocket.options import RunOptions -from commitrocket.report import RunReport -from commitrocket.runner import run -from commitrocket.security import validate_ref_part -from commitrocket.template import DEFAULT_TEMPLATE, PLACEHOLDERS, validate_template - -DEFAULT_LIMIT_MIB = 100 -DEFAULT_RETRIES = 3 - - -def build_parser(): - parser = argparse.ArgumentParser( - prog="commitrocket", - description="Batch Git changes, commit each batch, and push " - "with progress reporting. Run 'commitrocket doctor' to check your setup.", - allow_abbrev=False, - ) - parser.add_argument("--version", action="version", version=__version__) - parser.add_argument( - "--repo", default=".", help="Path to the Git repository (default: .)" - ) - parser.add_argument( - "--config", - default=None, - help="Read settings from this TOML file instead of commitrocket.toml / " - "[tool.commitrocket] in pyproject.toml. Command-line options win", - ) - parser.add_argument( - "--message", - default=None, - help="Base commit message (required, here or in the config file)", - ) - parser.add_argument( - "--message-template", - default=DEFAULT_TEMPLATE, - help=f"Commit message for each batch (default: '{DEFAULT_TEMPLATE}'). " - f"Placeholders: {', '.join(PLACEHOLDERS)}", - ) - parser.add_argument( - "--number", - type=int, - default=1, - help="Starting commit suffix number (default: 1)", - ) - parser.add_argument("--force", action="store_true", help="Skip confirmation") - parser.add_argument( - "--remote", - default=None, - help="Remote to push to (default: the branch's upstream remote)", - ) - parser.add_argument( - "--branch", - default=None, - help="Remote branch to push to (default: the branch's upstream branch, " - "or the current branch name)", - ) - parser.add_argument( - "--no-push", - action="store_true", - help="Commit every batch but don't push; a later run pushes them", - ) - parser.add_argument( - "--include", - action="append", - default=None, - metavar="GLOB", - help="Only handle files matching this .gitignore-style pattern " - "(repeatable), e.g. '*.mp4' or 'videos/**'", - ) - parser.add_argument( - "--exclude", - action="append", - default=None, - metavar="GLOB", - help="Leave files matching this pattern alone (repeatable); wins over " - "--include. Patterns in .commitrocketignore are always excluded", - ) - parser.add_argument( - "--include-from", - action="append", - default=None, - metavar="FILE", - help="Read --include patterns from a file, one per line (# comments)", - ) - parser.add_argument( - "--exclude-from", - action="append", - default=None, - metavar="FILE", - help="Read --exclude patterns from a file, one per line (# comments)", - ) - parser.add_argument( - "--limit-mib", - type=int, - default=DEFAULT_LIMIT_MIB, - help=f"Normal batch limit in MiB (default: {DEFAULT_LIMIT_MIB})", - ) - parser.add_argument( - "--max-mib", - type=int, - default=None, - help="Maximum individual file size in MiB (default: 3x --limit-mib)", - ) - parser.add_argument( - "--use-lfs", - action="store_true", - help="Track files above 100 MiB with Git LFS for this run, " - "installing git-lfs if needed and reverting the setup afterwards", - ) - parser.add_argument( - "--lfs-commit-rules", - dest="lfs_commit_rules", - action="store_true", - default=True, - help="With --use-lfs, commit LFS rules to .gitattributes (one per file " - "extension) so clones and checkouts get real files (default)", - ) - parser.add_argument( - "--no-lfs-commit-rules", - dest="lfs_commit_rules", - action="store_false", - help="With --use-lfs, keep the LFS rules local to this run. Checkouts " - "and clones will then contain LFS pointer files instead of the real files", - ) - parser.add_argument( - "--dry-run", - action="store_true", - help="Show the batches and commit messages that would be created, " - "without staging, committing or pushing anything", - ) - parser.add_argument( - "--retries", - type=int, - default=DEFAULT_RETRIES, - help="Retry a failed push this many times, waiting 5 s, 15 s, 45 s... " - f"(default: {DEFAULT_RETRIES}). Rejections such as file-size limits are " - "never retried", - ) - parser.add_argument( - "--post-buffer-mib", - type=int, - default=None, - help="Raise Git's http.postBuffer to this many MiB for this run " - "(repository config only; HTTP/HTTPS remotes). Helps with 'RPC failed' " - "and HTTP 408/500 errors on large pushes", - ) - parser.add_argument( - "--report", - default=None, - metavar="FILE", - help="Write a machine-readable JSON summary of the run to this file " - "(also written when the run fails, is interrupted or is a dry run)", - ) - parser.add_argument( - "--notify", - action="store_true", - help="Show a desktop notification when the run ends (Windows toast, " - "macOS notification, Linux notify-send; terminal bell if none works)", - ) - parser.add_argument( - "--notify-webhook", - default=None, - metavar="URL", - help="POST a JSON summary to this http(s) URL when the run ends " - "(Slack, Discord, Teams, ntfy or your own endpoint)", - ) - parser.add_argument( - "--level", - type=str.upper, - choices=LOG_LEVELS, - default=DEFAULT_LEVEL, - help=f"Log level written to the log file (default: {DEFAULT_LEVEL}); " - "DEBUG also records every git command and the push output", - ) - parser.add_argument( - "--log-file", - default=None, - help="Write the log here instead of the default per-user log folder " - f"({str(default_log_dir()).replace('%', '%%')})", - ) - parser.add_argument( - "--batch-type", - choices=BATCH_TYPES, - default=DETERMINISTIC, - help="How files are picked for a batch: 'deterministic' packs first-fit " - "and skips files that don't fit; 'sequential' takes files strictly in " - "order; 'soft' takes files in order and may pass --limit-mib, up to " - "--max-mib (default: deterministic)", - ) - parser.add_argument( - "--compression-threads", - type=int, - default=None, - help="Threads Git uses to compress objects when pushing (pack.threads; " - "0 = auto). Set in the repository's local config for this run only", - ) - parser.add_argument( - "--lfs-threads", - type=int, - default=None, - help="Concurrent Git LFS uploads (lfs.concurrenttransfers). Set in the " - "repository's local config for this run only", - ) - parser.add_argument( - "--lfs-threshold-mib", - type=int, - default=LFS_THRESHOLD_MIB, - help="With --use-lfs, files larger than this go through Git LFS " - f"(default: {LFS_THRESHOLD_MIB}, the most hosts accept; 0 = every file)", - ) - parser.add_argument( - "--lfs-batch-mib", - type=int, - default=None, - help="Max total size of LFS files pushed together so they can upload " - "concurrently (default: same as --limit-mib)", - ) - return parser - - -def validate(parser, args): - """Reject invalid combinations; returns the effective --max-mib.""" - if not args.message or not args.message.strip(): - parser.error("--message is required (or set 'message' in the config file)") - if args.limit_mib <= 0: - parser.error("--limit-mib must be positive") - if args.number < 0: - parser.error("--number cannot be negative") - if args.compression_threads is not None and args.compression_threads < 0: - parser.error("--compression-threads cannot be negative") - if args.lfs_threads is not None and args.lfs_threads <= 0: - parser.error("--lfs-threads must be positive") - if not 0 <= args.lfs_threshold_mib <= LFS_THRESHOLD_MIB: - parser.error( - f"--lfs-threshold-mib must be between 0 and {LFS_THRESHOLD_MIB}; " - "larger files would be rejected by the host" - ) - if args.retries < 0: - parser.error("--retries cannot be negative") - if args.post_buffer_mib is not None and args.post_buffer_mib <= 0: - parser.error("--post-buffer-mib must be positive") - if args.lfs_batch_mib is not None and args.lfs_batch_mib <= 0: - parser.error("--lfs-batch-mib must be positive") - if args.no_push and args.use_lfs: - parser.error( - "--no-push cannot be combined with --use-lfs: the large files would " - "stay local and a later plain 'git push' would publish LFS pointers " - "without their data" - ) - - for label, value in (("--remote", args.remote), ("--branch", args.branch)): - if value is not None: - try: - validate_ref_part(value, label) - except CommitRocketError as exc: - parser.error(str(exc)) - if args.notify_webhook and not is_valid_webhook(args.notify_webhook): - parser.error("--notify-webhook must be an http:// or https:// URL") - - template_error = validate_template(args.message_template) - if template_error: - parser.error(template_error) - - max_mib = args.max_mib if args.max_mib is not None else args.limit_mib * 3 - if max_mib < args.limit_mib: - parser.error("--max-mib must be greater than or equal to --limit-mib") - return max_mib - - -def run_main(argv): - parser = build_parser() - - # Find the config file first: its values become the parser's defaults, so - # anything given on the command line still wins. - pre = argparse.ArgumentParser(add_help=False, allow_abbrev=False) - pre.add_argument("--repo", default=".") - pre.add_argument("--config") - known, _ = pre.parse_known_args(argv) - - config_path = None - ignored_settings = [] - try: - config_path, values = find_config(known.repo, known.config) - if values: - # Only a file named with --config is trusted with sensitive settings. - ignored_settings = apply_config( - parser, values, config_path, trusted=bool(known.config) - ) - except ConfigError as exc: - parser.error(str(exc)) - - args = parser.parse_args(argv) - max_mib = validate(parser, args) - - options = RunOptions( - repo=args.repo, - message=args.message, - message_template=args.message_template, - number=args.number, - force=args.force, - remote=args.remote, - branch=args.branch, - no_push=args.no_push, - include=args.include or [], - exclude=args.exclude or [], - include_from=args.include_from or [], - exclude_from=args.exclude_from or [], - limit_mib=args.limit_mib, - max_mib=max_mib, - batch_type=args.batch_type, - use_lfs=args.use_lfs, - lfs_commit_rules=args.lfs_commit_rules, - lfs_threshold_mib=args.lfs_threshold_mib, - lfs_threads=args.lfs_threads, - lfs_batch_mib=args.lfs_batch_mib, - compression_threads=args.compression_threads, - dry_run=args.dry_run, - retries=args.retries, - post_buffer_mib=args.post_buffer_mib, - report=args.report, - ) - - console = Console() - log_path = setup_logging(args.level, args.log_file) - options.log_file = str(log_path) if log_path else None - if log_path is None: - console.print( - "[yellow]Could not open a log file; continuing without one.[/yellow]" - ) - if config_path: - console.print(f"[dim]Using config: {escape(str(config_path))}[/dim]") - if ignored_settings: - names = ", ".join(ignored_settings) - console.print( - f"[yellow]Ignored from {escape(str(config_path))}: {escape(names)}. " - "Settings that skip the prompt, change where files are pushed or " - "written, or contact other servers are only used from a file you " - "pass with --config.[/yellow]" - ) - logging.getLogger(__name__).warning( - "Ignored sensitive settings from untrusted config %s: %s", - config_path, - names, - ) - - report = RunReport(options) - try: - code = run(console, options, report) - report.finish(code, log_path) - - if args.report: - try: - report_path = report.write(args.report) - console.print(f"\n[dim]Report: {report_path}[/dim]") - except OSError as exc: - console.print(f"[yellow]Could not write the report: {exc}[/yellow]") - logging.getLogger(__name__).warning("Report not written: %s", exc) - - if (args.notify or args.notify_webhook) and not args.dry_run: - send_notifications( - console, report, desktop=args.notify, webhook=args.notify_webhook - ) - finally: - close_logging() - - if log_path: - console.print(f"\n[dim]Log file: {log_path}[/dim]") - return code - - -def doctor_main(argv): - parser = argparse.ArgumentParser( - prog="commitrocket doctor", - description="Check that Git, git-lfs, the repository, the remote and " - "your settings are ready for a run. Changes nothing.", - allow_abbrev=False, - ) - parser.add_argument("--repo", default=".", help="Repository to check (default: .)") - parser.add_argument("--remote", default=None, help="Remote to check") - parser.add_argument("--branch", default=None, help="Remote branch to check") - parser.add_argument("--config", default=None, help="Config file to check") - parser.add_argument( - "--offline", - action="store_true", - help="Skip the checks that contact the remote", - ) - args = parser.parse_args(argv) - - console = Console() - log_path = setup_logging(DEFAULT_LEVEL, None) - try: - code = run_doctor( - console, - args.repo, - remote=args.remote, - branch=args.branch, - offline=args.offline, - config_path=args.config, - ) - finally: - close_logging() - - if log_path: - console.print(f"\n[dim]Log file: {log_path}[/dim]") - return code - - -def main(argv=None): - argv = list(sys.argv[1:] if argv is None else argv) - if argv and argv[0] == "doctor": - return doctor_main(argv[1:]) - return run_main(argv) - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/src/commitrocket/cli/__init__.py b/src/commitrocket/cli/__init__.py new file mode 100644 index 0000000..86eef44 --- /dev/null +++ b/src/commitrocket/cli/__init__.py @@ -0,0 +1,4 @@ +from commitrocket.cli.entry import main +from commitrocket.cli.parser import build_parser + +__all__ = ["build_parser", "main"] diff --git a/src/commitrocket/cli/doctor.py b/src/commitrocket/cli/doctor.py new file mode 100644 index 0000000..b7e0f25 --- /dev/null +++ b/src/commitrocket/cli/doctor.py @@ -0,0 +1,42 @@ +def doctor_main(argv): + import argparse + + from rich.console import Console + + from commitrocket.io.logs import DEFAULT_LEVEL, close_logging, setup_logging + from commitrocket.support.doctor import run_doctor + + parser = argparse.ArgumentParser( + prog="commitrocket doctor", + description="Check that Git, git-lfs, the repository, the remote and " + "your settings are ready for a run. Changes nothing.", + allow_abbrev=False, + ) + parser.add_argument("--repo", default=".", help="Repository to check (default: .)") + parser.add_argument("--remote", default=None, help="Remote to check") + parser.add_argument("--branch", default=None, help="Remote branch to check") + parser.add_argument("--config", default=None, help="Config file to check") + parser.add_argument( + "--offline", + action="store_true", + help="Skip the checks that contact the remote", + ) + args = parser.parse_args(argv) + + console = Console() + log_path = setup_logging(DEFAULT_LEVEL, None) + try: + code = run_doctor( + console, + args.repo, + remote=args.remote, + branch=args.branch, + offline=args.offline, + config_path=args.config, + ) + finally: + close_logging() + + if log_path: + console.print(f"\n[dim]Log file: {log_path}[/dim]") + return code diff --git a/src/commitrocket/cli/entry.py b/src/commitrocket/cli/entry.py new file mode 100644 index 0000000..c852e1d --- /dev/null +++ b/src/commitrocket/cli/entry.py @@ -0,0 +1,12 @@ +def main(argv=None): + import sys + + argv = list(sys.argv[1:] if argv is None else argv) + if argv and argv[0] == "doctor": + from commitrocket.cli.doctor import doctor_main + + return doctor_main(argv[1:]) + + from commitrocket.cli.execute import run_main + + return run_main(argv) diff --git a/src/commitrocket/cli/execute.py b/src/commitrocket/cli/execute.py new file mode 100644 index 0000000..e2a250d --- /dev/null +++ b/src/commitrocket/cli/execute.py @@ -0,0 +1,121 @@ +def run_main(argv): + import argparse + import logging + + from rich.console import Console + from rich.markup import escape + + from commitrocket.cli.parser import build_parser + from commitrocket.cli.resume import apply_resume, run_params + from commitrocket.cli.validate import validate + from commitrocket.core.options import RunOptions + from commitrocket.core.runner import run + from commitrocket.io.logs import close_logging, setup_logging + from commitrocket.io.notify import send_notifications + from commitrocket.io.report import RunReport + from commitrocket.support.config import ConfigError, apply_config, find_config + + parser = build_parser() + + # Find the config file first: its values become the parser's defaults, so + # anything given on the command line still wins. + pre = argparse.ArgumentParser(add_help=False, allow_abbrev=False) + pre.add_argument("--repo", default=".") + pre.add_argument("--config") + known, _ = pre.parse_known_args(argv) + + config_path = None + ignored_settings = [] + try: + config_path, values = find_config(known.repo, known.config) + if values: + # Only a file named with --config is trusted with sensitive settings. + ignored_settings = apply_config( + parser, values, config_path, trusted=bool(known.config) + ) + except ConfigError as exc: + parser.error(str(exc)) + + args = parser.parse_args(argv) + if args.resume: + apply_resume(parser, argv, args, known.repo) + max_mib = validate(parser, args) + params = run_params(parser, args) + + options = RunOptions( + repo=args.repo, + message=args.message, + message_template=args.message_template, + attribution=not args.no_attribution, + number=args.number, + force=args.force, + remote=args.remote, + branch=args.branch, + no_push=args.no_push, + include=args.include or [], + exclude=args.exclude or [], + include_from=args.include_from or [], + exclude_from=args.exclude_from or [], + limit_mib=args.limit_mib, + max_mib=max_mib, + batch_type=args.batch_type, + use_lfs=args.use_lfs, + lfs_commit_rules=args.lfs_commit_rules, + lfs_threshold_mib=args.lfs_threshold_mib, + lfs_threads=args.lfs_threads, + lfs_batch_mib=args.lfs_batch_mib, + compression_threads=args.compression_threads, + dry_run=args.dry_run, + retries=args.retries, + post_buffer_mib=args.post_buffer_mib, + report=args.report, + resume=args.resume, + params=params, + ) + + console = Console() + log_path = setup_logging(args.level, args.log_file) + options.log_file = str(log_path) if log_path else None + if log_path is None: + console.print( + "[yellow]Could not open a log file; continuing without one.[/yellow]" + ) + if config_path: + console.print(f"[dim]Using config: {escape(str(config_path))}[/dim]") + if ignored_settings: + names = ", ".join(ignored_settings) + console.print( + f"[yellow]Ignored from {escape(str(config_path))}: {escape(names)}. " + "Settings that skip the prompt, change where files are pushed or " + "written, or contact other servers are only used from a file you " + "pass with --config.[/yellow]" + ) + logging.getLogger(__name__).warning( + "Ignored sensitive settings from untrusted config %s: %s", + config_path, + names, + ) + + report = RunReport(options) + try: + code = run(console, options, report) + report.finish(code, log_path) + + if args.report: + try: + report_path = report.write(args.report) + console.print(f"\n[dim]Report: {report_path}[/dim]") + except OSError as exc: + console.print(f"[yellow]Could not write the report: {exc}[/yellow]") + logging.getLogger(__name__).warning("Report not written: %s", exc) + + if (args.notify or args.notify_webhook) and not args.dry_run: + send_notifications( + console, report, desktop=args.notify, webhook=args.notify_webhook + ) + finally: + close_logging() + + if log_path: + console.print(f"\n[dim]Log file: {log_path}[/dim]") + return code diff --git a/src/commitrocket/cli/parser.py b/src/commitrocket/cli/parser.py new file mode 100644 index 0000000..793d591 --- /dev/null +++ b/src/commitrocket/cli/parser.py @@ -0,0 +1,235 @@ +DEFAULT_LIMIT_MIB = 100 +DEFAULT_RETRIES = 3 + + +def build_parser(): + import argparse + + from commitrocket import __version__ + from commitrocket.core.batching import BATCH_TYPES, DETERMINISTIC + from commitrocket.core.template import DEFAULT_TEMPLATE, PLACEHOLDERS + from commitrocket.git.lfs import LFS_THRESHOLD_MIB + from commitrocket.io.logs import DEFAULT_LEVEL, LOG_LEVELS, default_log_dir + + parser = argparse.ArgumentParser( + prog="commitrocket", + description="Batch Git changes, commit each batch, and push " + "with progress reporting. Run 'commitrocket doctor' to check your setup.", + allow_abbrev=False, + ) + parser.add_argument("--version", action="version", version=__version__) + parser.add_argument( + "--repo", default=".", help="Path to the Git repository (default: .)" + ) + parser.add_argument( + "--config", + default=None, + help="Read settings from this TOML file instead of commitrocket.toml / " + "[tool.commitrocket] in pyproject.toml. Command-line options win", + ) + parser.add_argument( + "--message", + default=None, + help="Base commit message (required, here or in the config file)", + ) + parser.add_argument( + "--message-template", + default=DEFAULT_TEMPLATE, + help=f"Commit message for each batch (default: '{DEFAULT_TEMPLATE}'). " + f"Placeholders: {', '.join(PLACEHOLDERS)}", + ) + parser.add_argument( + "--resume", + action="store_true", + help="Continue the interrupted run recorded in this repository, using the " + "parameters it started with. Other run parameters can't be given again " + "unless they are identical; run without --resume to start a new run", + ) + parser.add_argument( + "--no-attribution", + "--ignore-attribution", + dest="no_attribution", + action="store_true", + help="Don't append the 'Prepared and Committed By: CommitRocket' line " + "to commit messages", + ) + parser.add_argument( + "--number", + type=int, + default=1, + help="Starting commit suffix number (default: 1)", + ) + parser.add_argument("--force", action="store_true", help="Skip confirmation") + parser.add_argument( + "--remote", + default=None, + help="Remote to push to (default: the branch's upstream remote)", + ) + parser.add_argument( + "--branch", + default=None, + help="Remote branch to push to (default: the branch's upstream branch, " + "or the current branch name)", + ) + parser.add_argument( + "--no-push", + action="store_true", + help="Commit every batch but don't push; a later run pushes them", + ) + parser.add_argument( + "--include", + action="append", + default=None, + metavar="GLOB", + help="Only handle files matching this .gitignore-style pattern " + "(repeatable), e.g. '*.mp4' or 'videos/**'", + ) + parser.add_argument( + "--exclude", + action="append", + default=None, + metavar="GLOB", + help="Leave files matching this pattern alone (repeatable); wins over " + "--include. Patterns in .commitrocketignore are always excluded", + ) + parser.add_argument( + "--include-from", + action="append", + default=None, + metavar="FILE", + help="Read --include patterns from a file, one per line (# comments)", + ) + parser.add_argument( + "--exclude-from", + action="append", + default=None, + metavar="FILE", + help="Read --exclude patterns from a file, one per line (# comments)", + ) + parser.add_argument( + "--limit-mib", + type=int, + default=DEFAULT_LIMIT_MIB, + help=f"Normal batch limit in MiB (default: {DEFAULT_LIMIT_MIB})", + ) + parser.add_argument( + "--max-mib", + type=int, + default=None, + help="Maximum individual file size in MiB (default: 3x --limit-mib)", + ) + parser.add_argument( + "--use-lfs", + action="store_true", + help="Track files above 100 MiB with Git LFS for this run, " + "installing git-lfs if needed and reverting the setup afterwards", + ) + parser.add_argument( + "--lfs-commit-rules", + dest="lfs_commit_rules", + action="store_true", + default=True, + help="With --use-lfs, commit LFS rules to .gitattributes (one per file " + "extension) so clones and checkouts get real files (default)", + ) + parser.add_argument( + "--no-lfs-commit-rules", + dest="lfs_commit_rules", + action="store_false", + help="With --use-lfs, keep the LFS rules local to this run. Checkouts " + "and clones will then contain LFS pointer files instead of the real files", + ) + parser.add_argument( + "--dry-run", + action="store_true", + help="Show the batches and commit messages that would be created, " + "without staging, committing or pushing anything", + ) + parser.add_argument( + "--retries", + type=int, + default=DEFAULT_RETRIES, + help="Retry a failed push this many times, waiting 5 s, 15 s, 45 s... " + f"(default: {DEFAULT_RETRIES}). Rejections such as file-size limits are " + "never retried", + ) + parser.add_argument( + "--post-buffer-mib", + type=int, + default=None, + help="Raise Git's http.postBuffer to this many MiB for this run " + "(repository config only; HTTP/HTTPS remotes). Helps with 'RPC failed' " + "and HTTP 408/500 errors on large pushes", + ) + parser.add_argument( + "--report", + default=None, + metavar="FILE", + help="Write a machine-readable JSON summary of the run to this file " + "(also written when the run fails, is interrupted or is a dry run)", + ) + parser.add_argument( + "--notify", + action="store_true", + help="Show a desktop notification when the run ends (Windows toast, " + "macOS notification, Linux notify-send; terminal bell if none works)", + ) + parser.add_argument( + "--notify-webhook", + default=None, + metavar="URL", + help="POST a JSON summary to this http(s) URL when the run ends " + "(Slack, Discord, Teams, ntfy or your own endpoint)", + ) + parser.add_argument( + "--level", + type=str.upper, + choices=LOG_LEVELS, + default=DEFAULT_LEVEL, + help=f"Log level written to the log file (default: {DEFAULT_LEVEL}); " + "DEBUG also records every git command and the push output", + ) + parser.add_argument( + "--log-file", + default=None, + help="Write the log here instead of the default per-user log folder " + f"({str(default_log_dir()).replace('%', '%%')})", + ) + parser.add_argument( + "--batch-type", + choices=BATCH_TYPES, + default=DETERMINISTIC, + help="How files are picked for a batch: 'deterministic' packs first-fit " + "and skips files that don't fit; 'sequential' takes files strictly in " + "order; 'soft' takes files in order and may pass --limit-mib, up to " + "--max-mib (default: deterministic)", + ) + parser.add_argument( + "--compression-threads", + type=int, + default=None, + help="Threads Git uses to compress objects when pushing (pack.threads; " + "0 = auto). Set in the repository's local config for this run only", + ) + parser.add_argument( + "--lfs-threads", + type=int, + default=None, + help="Concurrent Git LFS uploads (lfs.concurrenttransfers). Set in the " + "repository's local config for this run only", + ) + parser.add_argument( + "--lfs-threshold-mib", + type=int, + default=LFS_THRESHOLD_MIB, + help="With --use-lfs, files larger than this go through Git LFS " + f"(default: {LFS_THRESHOLD_MIB}, the most hosts accept; 0 = every file)", + ) + parser.add_argument( + "--lfs-batch-mib", + type=int, + default=None, + help="Max total size of LFS files pushed together so they can upload " + "concurrently (default: same as --limit-mib)", + ) + return parser diff --git a/src/commitrocket/cli/resume.py b/src/commitrocket/cli/resume.py new file mode 100644 index 0000000..c5ec352 --- /dev/null +++ b/src/commitrocket/cli/resume.py @@ -0,0 +1,75 @@ +# Settings of a run that are not part of its identity: they never need to match +# the interrupted run when resuming. +NOT_RUN_PARAMS = { + "help", + "version", + "config", + "repo", + "resume", + "force", + "dry_run", + "report", + "log_file", + "level", + "notify", + "notify_webhook", +} + + +def run_params(parser, args): + """The parameters that identify a run, as stored in the journal.""" + return { + action.dest: getattr(args, action.dest) + for action in parser._actions + if action.dest not in NOT_RUN_PARAMS and hasattr(args, action.dest) + } + + +def explicit_arguments(argv): + """The destinations (and values) given on the command line, defaults excluded.""" + import argparse + + from commitrocket.cli.parser import build_parser + + parser = build_parser() + for action in parser._actions: + if action.dest != "help": + action.default = argparse.SUPPRESS + return vars(parser.parse_args(argv)) + + +def apply_resume(parser, argv, args, repo): + """Replace the run parameters in args with those stored by the interrupted run.""" + from commitrocket.git.git import run_git + from commitrocket.git.journal import Journal + from commitrocket.support.errors import CommitRocketError + + try: + root = run_git(repo, "rev-parse", "--show-toplevel").stdout.strip() + state = Journal(root).state() + except CommitRocketError as exc: + parser.error(f"--resume: {exc}") + if state is None: + parser.error( + "--resume: no interrupted run found in this repository. " + "Run without --resume to start a new run." + ) + + stored = state["params"] + given = explicit_arguments(argv) + differing = [ + action.option_strings[0] + for action in parser._actions + if action.dest in stored + and action.dest in given + and given[action.dest] != stored[action.dest] + ] + if differing: + parser.error( + "--resume reuses the parameters of the interrupted run, but these " + f"differ from it: {', '.join(differing)}. Remove them, or run without " + "--resume to start a new run." + ) + for dest, value in stored.items(): + if hasattr(args, dest): + setattr(args, dest, value) diff --git a/src/commitrocket/cli/validate.py b/src/commitrocket/cli/validate.py new file mode 100644 index 0000000..56ae0d5 --- /dev/null +++ b/src/commitrocket/cli/validate.py @@ -0,0 +1,53 @@ +def validate(parser, args): + """Reject invalid combinations; returns the effective --max-mib.""" + from commitrocket.core.template import validate_template + from commitrocket.git.lfs import LFS_THRESHOLD_MIB + from commitrocket.io.notify import is_valid_webhook + from commitrocket.support.errors import CommitRocketError + from commitrocket.support.security import validate_ref_part + + if not args.message or not args.message.strip(): + parser.error("--message is required (or set 'message' in the config file)") + if args.limit_mib <= 0: + parser.error("--limit-mib must be positive") + if args.number < 0: + parser.error("--number cannot be negative") + if args.compression_threads is not None and args.compression_threads < 0: + parser.error("--compression-threads cannot be negative") + if args.lfs_threads is not None and args.lfs_threads <= 0: + parser.error("--lfs-threads must be positive") + if not 0 <= args.lfs_threshold_mib <= LFS_THRESHOLD_MIB: + parser.error( + f"--lfs-threshold-mib must be between 0 and {LFS_THRESHOLD_MIB}; " + "larger files would be rejected by the host" + ) + if args.retries < 0: + parser.error("--retries cannot be negative") + if args.post_buffer_mib is not None and args.post_buffer_mib <= 0: + parser.error("--post-buffer-mib must be positive") + if args.lfs_batch_mib is not None and args.lfs_batch_mib <= 0: + parser.error("--lfs-batch-mib must be positive") + if args.no_push and args.use_lfs: + parser.error( + "--no-push cannot be combined with --use-lfs: the large files would " + "stay local and a later plain 'git push' would publish LFS pointers " + "without their data" + ) + + for label, value in (("--remote", args.remote), ("--branch", args.branch)): + if value is not None: + try: + validate_ref_part(value, label) + except CommitRocketError as exc: + parser.error(str(exc)) + if args.notify_webhook and not is_valid_webhook(args.notify_webhook): + parser.error("--notify-webhook must be an http:// or https:// URL") + + template_error = validate_template(args.message_template) + if template_error: + parser.error(template_error) + + max_mib = args.max_mib if args.max_mib is not None else args.limit_mib * 3 + if max_mib < args.limit_mib: + parser.error("--max-mib must be greater than or equal to --limit-mib") + return max_mib diff --git a/src/commitrocket/core/__init__.py b/src/commitrocket/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/commitrocket/batching.py b/src/commitrocket/core/batching.py similarity index 99% rename from src/commitrocket/batching.py rename to src/commitrocket/core/batching.py index b6d5b03..cb10b72 100644 --- a/src/commitrocket/batching.py +++ b/src/commitrocket/core/batching.py @@ -1,5 +1,3 @@ -from commitrocket.git import get_file_size - MIB = 1024 * 1024 SEQUENTIAL = "sequential" @@ -66,6 +64,8 @@ def select_batch( LFS files above limit_bytes are grouped up to lfs_limit_bytes (always at least one file) so their uploads can run concurrently. """ + from commitrocket.git.git import get_file_size + sized_files = [(path, get_file_size(repo, path)) for path in files] deferred = [(path, size) for path, size in sized_files if size > max_bytes] diff --git a/src/commitrocket/eta.py b/src/commitrocket/core/eta.py similarity index 90% rename from src/commitrocket/eta.py rename to src/commitrocket/core/eta.py index 5eb1b28..7ca4eef 100644 --- a/src/commitrocket/eta.py +++ b/src/commitrocket/core/eta.py @@ -1,5 +1,3 @@ -import time - # Wait for this much real upload time before trusting the measured speed. MIN_SECONDS = 5.0 @@ -19,7 +17,11 @@ class EtaEstimator: overhead such as `git add`, commit and push handshakes is included. """ - def __init__(self, clock=time.monotonic): + def __init__(self, clock=None): + if clock is None: + import time + + clock = time.monotonic self.clock = clock self.started_at = None diff --git a/src/commitrocket/filters.py b/src/commitrocket/core/filters.py similarity index 96% rename from src/commitrocket/filters.py rename to src/commitrocket/core/filters.py index 9bf5587..e3d9c25 100644 --- a/src/commitrocket/filters.py +++ b/src/commitrocket/core/filters.py @@ -1,9 +1,5 @@ from pathlib import Path -import pathspec - -from commitrocket.errors import CommitRocketError - IGNORE_FILE = ".commitrocketignore" @@ -12,6 +8,8 @@ def read_patterns(path): try: text = Path(path).expanduser().read_text(encoding="utf-8") except OSError as exc: + from commitrocket.support.errors import CommitRocketError + raise CommitRocketError(f"Cannot read pattern file {path}: {exc}") from exc return [ @@ -22,6 +20,8 @@ def read_patterns(path): def _spec(lines): + import pathspec + try: return pathspec.PathSpec.from_lines("gitignore", lines) except KeyError: diff --git a/src/commitrocket/options.py b/src/commitrocket/core/options.py similarity index 76% rename from src/commitrocket/options.py rename to src/commitrocket/core/options.py index 76abae7..721832d 100644 --- a/src/commitrocket/options.py +++ b/src/commitrocket/core/options.py @@ -1,8 +1,8 @@ from dataclasses import dataclass, field -from commitrocket.batching import DETERMINISTIC -from commitrocket.lfs import LFS_THRESHOLD_MIB -from commitrocket.template import DEFAULT_TEMPLATE +from commitrocket.core.batching import DETERMINISTIC +from commitrocket.core.template import DEFAULT_TEMPLATE +from commitrocket.git.lfs import LFS_THRESHOLD_MIB @dataclass @@ -17,6 +17,7 @@ class RunOptions: max_mib: int = 300 batch_type: str = DETERMINISTIC message_template: str = DEFAULT_TEMPLATE + attribution: bool = True remote: str | None = None branch: str | None = None no_push: bool = False @@ -36,3 +37,6 @@ class RunOptions: # Files the run itself writes; they are never committed, even inside the repo. log_file: str | None = None report: str | None = None + # --resume, and the parameters of the run as stored in the journal. + resume: bool = False + params: dict = field(default_factory=dict) diff --git a/src/commitrocket/core/runner/__init__.py b/src/commitrocket/core/runner/__init__.py new file mode 100644 index 0000000..5d5099f --- /dev/null +++ b/src/commitrocket/core/runner/__init__.py @@ -0,0 +1,4 @@ +from commitrocket.core.runner.flow import run +from commitrocket.core.runner.helpers import own_output_files + +__all__ = ["own_output_files", "run"] diff --git a/src/commitrocket/core/runner/batches.py b/src/commitrocket/core/runner/batches.py new file mode 100644 index 0000000..5852e5c --- /dev/null +++ b/src/commitrocket/core/runner/batches.py @@ -0,0 +1,168 @@ +import logging + +logger = logging.getLogger(__name__) + + +def process_batches( + console, + repo, + progress, + task, + push_task, + options, + target, + number, + limit_bytes, + max_bytes, + list_pending, + lfs_files=frozenset(), + lfs_limit_bytes=0, + estimator=None, + journal=None, + check_lfs=None, + verify=None, + report=None, +): + """Commit (and push) batches until only deferred files remain.""" + from commitrocket.core.batching import MIB, estimate_batch_count, select_batch + from commitrocket.core.runner.helpers import push_target + from commitrocket.core.template import add_attribution, render_message + from commitrocket.git.git import ( + add_files, + get_file_size, + get_staged_files, + run_git, + ) + from commitrocket.support.errors import CommitRocketError + + batch_count = 0 + commit_number = number + + # Progress is measured in bytes so the ETA reflects the real amount of work. + total_work = sum( + size + for size in (get_file_size(repo, path) for path in list_pending()) + if size <= max_bytes + ) + done_bytes = 0 + progress.update(task, total=max(total_work, 1), completed=0) + if estimator: + estimator.start() + + selection = ( + limit_bytes, + max_bytes, + lfs_files, + lfs_limit_bytes, + options.batch_type, + ) + + while True: + pending = list_pending() + if not pending: + break + + selected, _, total_bytes = select_batch(repo, pending, *selection) + + if not selected: + # Only oversized files remain; report them at the end. + break + + remaining_estimate = estimate_batch_count(repo, pending, *selection) + estimated_total = max(batch_count + remaining_estimate, batch_count + 1) + + progress.update( + task, + description=( + f"Batch {batch_count + 1}/{estimated_total}: commit #{commit_number}" + ), + ) + + console.rule(f"[bold cyan]Batch {batch_count + 1}[/bold cyan]") + console.print(f"Selected: {len(selected)} file(s), {total_bytes / MIB:.2f} MiB") + logger.info( + "Batch %d/%d: %d file(s), %.2f MiB, commit #%d", + batch_count + 1, + estimated_total, + len(selected), + total_bytes / MIB, + commit_number, + ) + logger.debug("Batch %d files: %s", batch_count + 1, selected) + + commit_message = add_attribution( + render_message( + options.message_template, + options.message, + commit_number, + batch_count + 1, + len(selected), + total_bytes / MIB, + selected[0], + ), + options.attribution, + ) + + # Lets an interrupted run recognise the files it left staged. + if journal: + journal.write(selected, commit_message, commit_number) + + add_files(repo, selected) + + if not get_staged_files(repo): + raise CommitRocketError("No staged changes to commit.") + + run_git(repo, "commit", "-m", commit_message) + commit_sha = run_git(repo, "rev-parse", "HEAD").stdout.strip() + if journal: + journal.committed(commit_number, commit_sha) + + entry = None + if report: + entry = report.add_batch( + commit_number, + commit_message, + selected, + total_bytes, + lfs_files=len(lfs_files.intersection(selected)), + commit=commit_sha, + ) + + # Catch files that did not become LFS pointers before uploading them. + if check_lfs: + check_lfs(selected) + + if not options.no_push: + push_target( + repo, + progress, + push_task, + console, + options, + target, + on_upload=lambda percent, base=done_bytes, size=total_bytes: ( + progress.update(task, completed=base + size * percent / 100) + ), + batch_bytes=total_bytes, + ) + + if entry: + entry["pushed"] = True + + if verify: + verify() + if entry: + entry["verified"] = True + if journal: + journal.pushed(commit_sha) + + batch_count += 1 + commit_number += 1 + done_bytes += total_bytes + progress.update(task, completed=done_bytes) + + outcome = "committed" if options.no_push else "committed and pushed" + console.print(f"[green]Batch {batch_count} {outcome}.[/green]") + logger.info("Batch %d %s", batch_count, outcome) + + return batch_count diff --git a/src/commitrocket/core/runner/dry_run.py b/src/commitrocket/core/runner/dry_run.py new file mode 100644 index 0000000..2573f39 --- /dev/null +++ b/src/commitrocket/core/runner/dry_run.py @@ -0,0 +1,62 @@ +import logging + +logger = logging.getLogger(__name__) + + +def run_dry( + console, + options, + report, + repo, + pending_files, + lfs_paths, + lfs_scope, + limit_bytes, + max_bytes, + lfs_limit_bytes, + start_number, +): + """Plan the batches without touching the repository and record them in report.""" + from commitrocket.core.batching import MIB, plan_batches + from commitrocket.core.template import add_attribution, render_message + from commitrocket.io.report import DRY_RUN + from commitrocket.io.ui import print_dry_run + + o = options + batches, deferred = plan_batches( + repo, + pending_files, + limit_bytes, + max_bytes, + frozenset(lfs_paths), + lfs_limit_bytes, + o.batch_type, + ) + messages = [ + add_attribution( + render_message( + o.message_template, + o.message, + start_number + index, + index + 1, + len(paths), + size / MIB, + paths[0], + ), + o.attribution, + ) + for index, (paths, size) in enumerate(batches) + ] + logger.info("Dry run: %d batch(es) planned", len(batches)) + for index, (paths, size) in enumerate(batches): + report.add_batch( + start_number + index, + messages[index], + paths, + size, + lfs_files=len(set(paths).intersection(lfs_paths)), + ) + report.set_deferred(deferred) + report.status = DRY_RUN + print_dry_run(console, batches, deferred, messages, lfs_paths, lfs_scope, o.no_push) + return 0 diff --git a/src/commitrocket/core/runner/flow.py b/src/commitrocket/core/runner/flow.py new file mode 100644 index 0000000..df15d2c --- /dev/null +++ b/src/commitrocket/core/runner/flow.py @@ -0,0 +1,407 @@ +import logging +import time +from pathlib import Path + +logger = logging.getLogger(__name__) + + +def run(console, options, report=None): + """Batch, commit and push pending changes. Returns a process exit code. + + The outcome is recorded in report (a RunReport) for --report and notifications. + """ + from commitrocket.io.report import RunReport + + o = options + report = report or RunReport(options) + repo = Path(o.repo).expanduser().resolve() + + if not repo.is_dir(): + console.print(f"[red]Repository directory not found: {repo}[/red]") + report.abort(f"Repository directory not found: {repo}") + return 2 + + started_at = time.monotonic() + lfs = None + config = None + journal = None + acting = False + completed = False + + try: + from commitrocket.core.batching import MIB + from commitrocket.core.filters import FileFilter + from commitrocket.core.runner.helpers import own_output_files + from commitrocket.core.runner.resume import read_resume_state + from commitrocket.core.runner.setup import plan_lfs + from commitrocket.git.git import ( + find_large_unpushed_blobs, + get_pending_files, + get_unpushed_commits, + resolve_target, + run_git, + ) + from commitrocket.git.lfs import HOST_LIMIT_MIB, find_lfs_candidates + from commitrocket.io.report import CANCELLED, DEFERRED, SUCCESS + from commitrocket.support.errors import CommitRocketError + + root = run_git(repo, "rev-parse", "--show-toplevel") + repo = Path(root.stdout.strip()).resolve() + + branch = run_git(repo, "branch", "--show-current").stdout.strip() + if not branch: + raise CommitRocketError( + "Detached HEAD. Check out a branch before continuing." + ) + + target = resolve_target(repo, branch, o.remote, o.branch) + report.repo = str(repo) + report.branch = branch + report.target = target.label + file_filter = FileFilter.from_options( + repo, o.include, o.exclude, o.include_from, o.exclude_from + ) + + # The run's own log and report must never be committed, or writing them + # would create a new batch forever. + own_files = own_output_files(repo, o) + + def raw_pending(): + return [p for p in get_pending_files(repo) if p not in own_files] + + def list_pending(): + return file_filter.apply(raw_pending()) + + logger.info( + "Run started: repo=%s branch=%s target=%s limit=%d MiB max=%d MiB " + "batch_type=%s use_lfs=%s dry_run=%s no_push=%s retries=%d", + repo, + branch, + target.label, + o.limit_mib, + o.max_mib, + o.batch_type, + o.use_lfs, + o.dry_run, + o.no_push, + o.retries, + ) + + journal, prior, same_run, entry, resume_staged = read_resume_state( + console, repo, o, branch, target.label + ) + + # Earlier failed runs can leave commits that the host will reject. + stuck = find_large_unpushed_blobs(repo, HOST_LIMIT_MIB * MIB, target.revs) + if stuck: + from commitrocket.io.ui import print_stuck_commits + + logger.warning("Unpushed commits contain large files: %s", stuck) + print_stuck_commits( + console, + get_unpushed_commits(repo, target.revs), + stuck, + target.label, + HOST_LIMIT_MIB, + ) + report.abort( + f"Unpushed commits contain files over {HOST_LIMIT_MIB} MiB: " + + ", ".join(path for path, _ in stuck[:5]) + ) + return 2 + + unpushed = get_unpushed_commits(repo, target.revs) + start_number = o.number + if same_run: + start_number = max(start_number, prior["next_number"]) + if resume_staged: + start_number = max(start_number, entry["number"] + 1) + + from rich.panel import Panel + from rich.text import Text + + from commitrocket.io.ui import print_resume, print_run_info + + print_run_info( + console, + repo, + branch, + target.label, + o.limit_mib, + o.max_mib, + start_number, + ) + + status = run_git(repo, "status", "--short").stdout.strip() + console.print( + Panel(Text(status or "(no pending changes)"), title="Pending Changes") + ) + + if resume_staged or unpushed: + logger.info( + "Resuming: %d staged file(s), %d unpushed commit(s)", + len(resume_staged), + len(unpushed), + ) + print_resume(console, resume_staged, entry, unpushed) + report.resumed = { + "staged_files": len(resume_staged), + "unpushed_commits": len(unpushed), + } + + limit_bytes = o.limit_mib * MIB + max_bytes = o.max_mib * MIB + lfs_limit_bytes = (o.lfs_batch_mib or o.limit_mib) * MIB + + all_pending = raw_pending() + pending_files = list_pending() + if file_filter.active: + left_out = len(all_pending) - len(pending_files) + console.print( + f"[dim]Filters: {len(pending_files)} file(s) selected, " + f"{left_out} left out.[/dim]" + ) + logger.info("Filters kept %d, left out %d", len(pending_files), left_out) + + if not o.use_lfs: + over_host_limit = find_lfs_candidates( + repo, pending_files, HOST_LIMIT_MIB * MIB, max_bytes + ) + if over_host_limit: + # The host would reject the push, so stop before committing anything. + from commitrocket.io.ui import print_lfs_required + + logger.warning( + "Files over the limit need --use-lfs: %s", over_host_limit + ) + print_lfs_required(console, repo, over_host_limit, HOST_LIMIT_MIB) + report.abort( + f"{len(over_host_limit)} file(s) over {HOST_LIMIT_MIB} MiB " + "need --use-lfs" + ) + return 2 + + lfs_paths, lfs_scope = plan_lfs(o, report, repo, pending_files, max_bytes) + + if o.dry_run: + from commitrocket.core.runner.dry_run import run_dry + + return run_dry( + console, + o, + report, + repo, + pending_files, + lfs_paths, + lfs_scope, + limit_bytes, + max_bytes, + lfs_limit_bytes, + start_number, + ) + + if lfs_scope: + console.print(f"[cyan]{lfs_scope}[/cyan]") + + if not o.force: + answer = ( + console.input( + "[yellow]Proceed with staging, committing, and " + f"{'finishing' if o.no_push else 'pushing'}? [y/N][/yellow] " + ) + .strip() + .lower() + ) + if answer not in {"y", "yes"}: + console.print("[yellow]Cancelled.[/yellow]") + logger.info("Cancelled by user at the confirmation prompt") + report.status = CANCELLED + return 1 + + # Unpushed LFS pointers need the LFS hooks, or a push would publish + # pointers whose files were never uploaded. + from commitrocket.core.verify import unpushed_has_lfs_pointers + + resume_needs_lfs = ( + not o.no_push + and bool(unpushed) + and unpushed_has_lfs_pointers(repo, target.revs) + ) + if lfs_paths or resume_needs_lfs: + from commitrocket.git.lfs import ensure_git_lfs + + ensure_git_lfs(console, o.force) + + def verify(): + from commitrocket.core.verify import verify_remote_head + + verify_remote_head(repo, target.remote, target.ref, o.retries) + + def check_lfs(selected): + from commitrocket.core.verify import expected_lfs_paths, find_non_pointers + + bad = find_non_pointers(repo, expected_lfs_paths(selected, lfs_paths)) + if bad: + raise CommitRocketError( + f"{len(bad)} file(s) were committed as ordinary files instead of " + f"LFS pointers (first: {bad[0]}). Nothing was pushed. Drop the " + f"commit with 'git reset --mixed {target.label}' and report this." + ) + + acting = True + try: + if same_run: + journal.note("resumed", staged_files=len(resume_staged)) + else: + journal.start( + o.params, + branch, + target.label, + run_git(repo, "rev-parse", "HEAD").stdout.strip(), + ) + # Repository-local settings only; the previous values are restored below. + from commitrocket.core.runner.setup import apply_local_config, configure_lfs + from commitrocket.git.git import LocalConfig + + config = LocalConfig(repo) + apply_local_config(console, o, repo, target, config) + + if lfs_paths or resume_needs_lfs: + from commitrocket.git.lfs import LfsSession + + lfs = LfsSession(repo) + configure_lfs(lfs, o, lfs_paths) + + from commitrocket.core.eta import EtaEstimator + from commitrocket.core.runner.batches import process_batches + from commitrocket.core.runner.resume import resume_previous + from commitrocket.io.ui import make_progress + + with make_progress(console) as progress: + estimator = EtaEstimator() + task = progress.add_task( + "Preparing batches", total=1, estimator=estimator + ) + push_task = progress.add_task("Git push", total=100, visible=False) + + resume_previous( + console, + repo, + progress, + push_task, + o, + target, + journal, + entry, + resume_staged, + unpushed, + verify, + ) + + if o.lfs_commit_rules and lfs_paths: + from commitrocket.core.runner.resume import commit_lfs_rules + + commit_lfs_rules( + console, + repo, + progress, + push_task, + o, + target, + lfs, + lfs_paths, + report, + verify, + ) + + batch_count = process_batches( + console, + repo, + progress, + task, + push_task, + o, + target, + start_number, + limit_bytes, + max_bytes, + list_pending, + frozenset(lfs_paths), + lfs_limit_bytes, + estimator, + journal, + check_lfs if lfs_paths else None, + verify, + report, + ) + completed = True + finally: + if lfs: + from commitrocket.core.runner.setup import release_lfs + + release_lfs(console, repo, target, lfs, completed) + if config: + config.restore() + logger.info("Local git config restored") + + journal.delete() + + from commitrocket.io.ui import print_final_summary + + code = print_final_summary( + console, + repo, + batch_count, + started_at, + o.max_mib, + pending_files=list_pending, + pushed=not o.no_push, + ) + from commitrocket.git.git import get_file_size + + report.set_deferred( + (path, size) + for path, size in ((p, get_file_size(repo, p)) for p in list_pending()) + if size > max_bytes + ) + report.status = SUCCESS if code == 0 else DEFERRED + logger.info( + "Finished: %d batch(es) in %.1f s, exit code %d", + batch_count, + time.monotonic() - started_at, + code, + ) + return code + + except KeyboardInterrupt: + from commitrocket.io.report import INTERRUPTED + + console.print("\n[yellow]Interrupted by user.[/yellow]") + report.status = INTERRUPTED + report.error = "Interrupted by user" + if acting and journal: + journal.note("interrupted") + if acting: + console.print( + "[dim]Run the same command again to resume from where it stopped.[/dim]" + ) + logger.warning("Interrupted by user") + return 130 + except (RuntimeError, OSError) as exc: + from rich.markup import escape + + from commitrocket.io.report import ABORTED, FAILED + from commitrocket.support.security import redact + + message = redact(str(exc)) + console.print(f"\n[bold red]Error:[/bold red] {escape(message)}") + report.status = ABORTED if not acting else FAILED + report.error = message + if acting and journal: + journal.note("failed", error=message) + if acting: + console.print( + "[dim]Run the same command again to resume from where it stopped.[/dim]" + ) + logger.error("Run failed: %s", exc, exc_info=True) + return 1 diff --git a/src/commitrocket/core/runner/helpers.py b/src/commitrocket/core/runner/helpers.py new file mode 100644 index 0000000..27a9933 --- /dev/null +++ b/src/commitrocket/core/runner/helpers.py @@ -0,0 +1,31 @@ +from pathlib import Path + + +def own_output_files(repo, options): + """Paths (relative to the repo) of the log and report files this run writes.""" + found = set() + for raw in (options.log_file, options.report): + if not raw: + continue + path = Path(raw).expanduser().resolve() + try: + found.add(path.relative_to(repo).as_posix()) + except ValueError: + pass # outside the repository + return found + + +def push_target(repo, progress, push_task, console, options, target, **kwargs): + """Push HEAD to the run's remote branch, retrying transient failures.""" + from commitrocket.git.push import push_with_retries + + push_with_retries( + repo, + progress, + push_task, + console, + retries=options.retries, + remote=target.remote, + refspec=target.refspec, + **kwargs, + ) diff --git a/src/commitrocket/core/runner/resume.py b/src/commitrocket/core/runner/resume.py new file mode 100644 index 0000000..58b6176 --- /dev/null +++ b/src/commitrocket/core/runner/resume.py @@ -0,0 +1,141 @@ +import logging + +logger = logging.getLogger(__name__) + + +def check_resume(repo, prior, options, branch, target_label): + """Make sure --resume can safely continue the journal's run.""" + from commitrocket.git.git import run_git + from commitrocket.support.errors import CommitRocketError + + if prior is None: + raise CommitRocketError( + "--resume: no interrupted run found in this repository. " + "Run without --resume to start a new run." + ) + if prior["params"] != options.params: + raise CommitRocketError( + "--resume: the parameters differ from the interrupted run. " + "Run without --resume to start a new run." + ) + if prior["branch"] != branch or prior["target"] != target_label: + raise CommitRocketError( + f"--resume: the interrupted run was on {prior['branch']} -> " + f"{prior['target']}, but this is {branch} -> {target_label}. " + "Run without --resume to start a new run." + ) + anchor = prior["commits"][-1][1] if prior["commits"] else prior["head"] + if anchor: + reachable = run_git( + repo, "merge-base", "--is-ancestor", anchor, "HEAD", check=False + ) + if reachable.returncode != 0: + raise CommitRocketError( + "--resume: the repository changed since the interrupted run " + f"(commit {anchor[:10]} is no longer in the history of {branch}). " + "Run without --resume to start a new run." + ) + + +def read_resume_state(console, repo, options, branch, target_label): + """Return (journal, prior state, same_run, journal entry, resumed staged files). + + The journal of an interrupted run holds its parameters. The same parameters + continue that run; different ones start a new run. + """ + from commitrocket.git.git import get_staged_files + from commitrocket.git.journal import Journal, JournalError + from commitrocket.support.errors import CommitRocketError + + journal = Journal(repo) + try: + prior = journal.state() + except JournalError: + if options.resume: + raise + logger.warning("Ignoring an incompatible journal: %s", journal.path) + prior = None + if options.resume: + check_resume(repo, prior, options, branch, target_label) + same_run = prior is not None and prior["params"] == options.params + if prior is not None and not same_run: + console.print( + "[yellow]The parameters differ from the interrupted run; " + "starting a new run.[/yellow]" + ) + logger.info("Journal parameters differ; starting a new run") + entry = journal.read() if same_run else None + + # Files left staged by an interrupted run are ours; anything else is not. + staged = get_staged_files(repo) + resume_staged = [] + if staged: + if entry and set(staged) <= set(entry["files"]): + resume_staged = staged + else: + raise CommitRocketError( + f"{len(staged)} file(s) already staged. Commit or unstage " + "them before running this tool." + ) + return journal, prior, same_run, entry, resume_staged + + +def resume_previous( + console, + repo, + progress, + push_task, + options, + target, + journal, + entry, + resume_staged, + unpushed, + verify, +): + """Commit the batch an interrupted run left staged and push earlier commits.""" + from commitrocket.core.batching import MIB + from commitrocket.core.runner.helpers import push_target + from commitrocket.git.git import find_large_unpushed_blobs, run_git + from commitrocket.git.lfs import HOST_LIMIT_MIB + from commitrocket.support.errors import CommitRocketError + + if resume_staged: + run_git(repo, "commit", "-m", entry["message"]) + journal.committed( + entry["number"], run_git(repo, "rev-parse", "HEAD").stdout.strip() + ) + logger.info("Committed resumed batch: %s", entry["message"]) + if find_large_unpushed_blobs(repo, HOST_LIMIT_MIB * MIB, target.revs): + raise CommitRocketError( + "The resumed commit contains files over " + f"{HOST_LIMIT_MIB} MiB. Drop it with " + f"'git reset --mixed {target.label}' and run again." + ) + + if (resume_staged or unpushed) and not options.no_push: + push_target(repo, progress, push_task, console, options, target) + verify() + journal.pushed(run_git(repo, "rev-parse", "HEAD").stdout.strip()) + console.print("[green]Resumed commits pushed.[/green]") + + +def commit_lfs_rules( + console, repo, progress, push_task, options, target, lfs, lfs_paths, report, verify +): + """Commit the .gitattributes LFS rules before the first batch.""" + from commitrocket.core.runner.helpers import push_target + from commitrocket.core.template import add_attribution + from commitrocket.git.git import run_git + + if lfs.write_committed_rules(lfs_paths): + run_git(repo, "add", "--", ".gitattributes") + rules_message = add_attribution( + f"{options.message.rstrip()} (LFS rules)", options.attribution + ) + run_git(repo, "commit", "-m", rules_message) + logger.info("Committed LFS rules: %s", rules_message) + report.lfs["rules_commit"] = run_git(repo, "rev-parse", "HEAD").stdout.strip() + console.print("[cyan]Committed LFS rules.[/cyan]") + push_target(repo, progress, push_task, console, options, target) + verify() diff --git a/src/commitrocket/core/runner/setup.py b/src/commitrocket/core/runner/setup.py new file mode 100644 index 0000000..a2cadbe --- /dev/null +++ b/src/commitrocket/core/runner/setup.py @@ -0,0 +1,109 @@ +import logging + +from commitrocket.core.batching import MIB + +logger = logging.getLogger(__name__) + + +def plan_lfs(options, report, repo, pending_files, max_bytes): + """Return (LFS candidate paths, scope message) for --use-lfs, or ([], "").""" + from commitrocket.git.lfs import ( + committed_rule_lines, + find_lfs_candidates, + is_lfs_available, + ) + + o = options + lfs_paths = [] + lfs_scope = "" + if o.use_lfs: + lfs_paths = find_lfs_candidates( + repo, pending_files, o.lfs_threshold_mib * MIB, max_bytes + ) + report.lfs["files"] = len(lfs_paths) + if not lfs_paths: + lfs_scope = ( + f"--use-lfs: no files above {o.lfs_threshold_mib} MiB; LFS not needed." + ) + else: + which = ( + f"All {len(lfs_paths)} file(s)" + if o.lfs_threshold_mib == 0 + else f"{len(lfs_paths)} file(s) above {o.lfs_threshold_mib} MiB" + ) + if o.lfs_commit_rules: + rule_count = len(committed_rule_lines(lfs_paths)) + lfs_scope = ( + f"{which} will be stored with Git LFS. {rule_count} rule(s) " + "will be committed to .gitattributes first, so they also " + "cover files of the same type added later." + ) + else: + lfs_scope = ( + f"{which} will be stored with Git LFS for this run only; " + "no LFS config is committed, so checkouts and clones will " + "contain LFS pointer files instead of the real files." + ) + if o.dry_run and not is_lfs_available(): + lfs_scope += " git-lfs is not installed and would be installed." + return lfs_paths, lfs_scope + + +def apply_local_config(console, options, repo, target, config): + """Set repository-local tuning options; the caller restores them afterwards.""" + o = options + if o.compression_threads is not None: + config.set("pack.threads", o.compression_threads) + logger.info("Set local pack.threads=%d", o.compression_threads) + if o.lfs_threads is not None: + config.set("lfs.concurrenttransfers", o.lfs_threads) + logger.info("Set local lfs.concurrenttransfers=%d", o.lfs_threads) + if o.post_buffer_mib is not None: + from commitrocket.git.git import get_remote_url + + url = get_remote_url(repo, target.remote).lower() + if url.startswith(("http://", "https://")): + config.set("http.postBuffer", o.post_buffer_mib * MIB) + logger.info("Set local http.postBuffer=%d MiB", o.post_buffer_mib) + else: + console.print( + "[dim]--post-buffer-mib ignored: remote is not HTTP(S).[/dim]" + ) + logger.info("--post-buffer-mib ignored for non-HTTP remote") + + +def configure_lfs(lfs, options, lfs_paths): + """Enable LFS for this run, or only install its hooks when rules are committed.""" + if lfs_paths and not options.lfs_commit_rules: + lfs.enable(lfs_paths, all_files=options.lfs_threshold_mib == 0) + logger.info( + "LFS enabled locally for %d file(s) (threshold %d MiB)", + len(lfs_paths), + options.lfs_threshold_mib, + ) + logger.debug("LFS files: %s", lfs_paths) + else: + lfs.install_hooks() + + +def release_lfs(console, repo, target, lfs, completed): + """Close the LFS session, keeping hooks while unpushed LFS commits remain.""" + from commitrocket.core.verify import unpushed_has_lfs_pointers + + keep_hooks = False + if not completed: + try: + keep_hooks = unpushed_has_lfs_pointers(repo, target.revs) + except (RuntimeError, OSError): + keep_hooks = True + lfs.close(uninstall_hooks=not keep_hooks) + if keep_hooks: + console.print( + "[yellow]Git LFS hooks were left installed because unpushed " + "commits contain LFS files. Run CommitRocket again to push " + "them; a plain 'git push' only works while the hooks " + "stay.[/yellow]" + ) + logger.warning("LFS hooks kept: unpushed LFS commits remain") + else: + logger.info("Local LFS setup removed") diff --git a/src/commitrocket/template.py b/src/commitrocket/core/template.py similarity index 67% rename from src/commitrocket/template.py rename to src/commitrocket/core/template.py index d52e810..81462ba 100644 --- a/src/commitrocket/template.py +++ b/src/commitrocket/core/template.py @@ -1,7 +1,10 @@ -from datetime import date - DEFAULT_TEMPLATE = "{message} #{n}" +ATTRIBUTION = ( + "Prepared and Committed By: 🚀 CommitRocket " + "(https://github.com/coldsofttech/CommitRocket)" +) + PLACEHOLDERS = ("message", "n", "batch", "files", "size", "first", "date") @@ -12,6 +15,8 @@ def render_message(template, message, n, batch, files, size_mib, first): in this run, {files} the file count, {size} the size in MiB, {first} the first file's path and {date} today's date (YYYY-MM-DD). """ + from datetime import date + return template.format( message=message.rstrip(), n=n, @@ -23,6 +28,17 @@ def render_message(template, message, n, batch, files, size_mib, first): ).strip() +def add_attribution(message, enabled=True): + """Append the CommitRocket attribution trailer to a commit message. + + The trailer goes after a blank line at the end. It is never added twice and + the message is returned untouched when attribution is switched off. + """ + if not enabled or ATTRIBUTION in message.splitlines(): + return message + return f"{message.rstrip()}\n\n{ATTRIBUTION}" + + def validate_template(template): """Return an error string if the template can't be rendered, else None.""" try: diff --git a/src/commitrocket/verify.py b/src/commitrocket/core/verify.py similarity index 89% rename from src/commitrocket/verify.py rename to src/commitrocket/core/verify.py index 0a72bb5..48e91cc 100644 --- a/src/commitrocket/verify.py +++ b/src/commitrocket/core/verify.py @@ -1,20 +1,21 @@ import logging -import subprocess -import time from pathlib import PurePosixPath -from commitrocket.errors import CommitRocketError, GitError -from commitrocket.git import get_remote_head, run_git -from commitrocket.lfs import LFS_EXCLUDED - logger = logging.getLogger(__name__) POINTER_PREFIX = b"version https://git-lfs.github.com/spec/v1" MAX_POINTER_BYTES = 1024 -def verify_remote_head(repo, remote, ref, retries=0, sleep=time.sleep): +def verify_remote_head(repo, remote, ref, retries=0, sleep=None): """Raise unless the remote's branch points at the local HEAD.""" + import time + + from commitrocket.git.git import get_remote_head, run_git + from commitrocket.support.errors import CommitRocketError, GitError + + if sleep is None: + sleep = time.sleep local = run_git(repo, "rev-parse", "HEAD").stdout.strip() attempt = 0 @@ -38,6 +39,8 @@ def verify_remote_head(repo, remote, ref, retries=0, sleep=time.sleep): def expected_lfs_paths(selected, lfs_paths): """Files in a batch that should have been stored as LFS pointers.""" + from commitrocket.git.lfs import LFS_EXCLUDED + wanted = set(lfs_paths) return [ path @@ -47,6 +50,10 @@ def expected_lfs_paths(selected, lfs_paths): def _git_cat_file(repo, mode, specs): + import subprocess + + from commitrocket.support.errors import GitError + result = subprocess.run( ["git", "-C", str(repo), "cat-file", mode], input="".join(f"{spec}\n" for spec in specs).encode("utf-8"), @@ -68,6 +75,8 @@ def unpushed_has_lfs_pointers(repo, revs): Pushing those without the LFS hooks installed would publish pointers whose data was never uploaded. """ + from commitrocket.git.git import run_git + objects = run_git(repo, "rev-list", "--objects", *revs).stdout if not objects.strip(): return False diff --git a/src/commitrocket/git/__init__.py b/src/commitrocket/git/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/commitrocket/git.py b/src/commitrocket/git/git.py similarity index 91% rename from src/commitrocket/git.py rename to src/commitrocket/git/git.py index 85e98cd..13b30f1 100644 --- a/src/commitrocket/git.py +++ b/src/commitrocket/git/git.py @@ -1,11 +1,5 @@ import logging -import os -import subprocess from dataclasses import dataclass -from pathlib import Path - -from commitrocket.errors import CommitRocketError, GitError -from commitrocket.security import redact, validate_ref_part logger = logging.getLogger(__name__) @@ -23,9 +17,19 @@ def _logged_output(result): def run_git(repo, *args, check=True): + import os + import subprocess + + from commitrocket.support.errors import GitError + from commitrocket.support.security import redact + result = subprocess.run( ["git", "-C", str(repo), *args], + # Git writes UTF-8; the system code page (cp1252 on Windows) would garble + # file names and commit messages that are not plain ASCII. text=True, + encoding="utf-8", + errors="replace", capture_output=True, # File names are literal: "[ab].txt" must not also match a.txt and b.txt. env={**os.environ, "GIT_LITERAL_PATHSPECS": "1"}, @@ -135,11 +139,16 @@ def refspec(self): @property def label(self): """Display name for the target; safe to show, log, report and send.""" + from commitrocket.support.security import redact + return redact(f"{self.remote}/{self.branch}") def resolve_target(repo, local_branch, remote=None, branch=None): """The remote branch to push to: explicit values first, then the upstream.""" + from commitrocket.support.errors import CommitRocketError + from commitrocket.support.security import validate_ref_part + configured_remote = run_git( repo, "config", "--get", f"branch.{local_branch}.remote", check=False ).stdout.strip() @@ -191,6 +200,10 @@ def get_unpushed_commits(repo, revs): def find_large_unpushed_blobs(repo, threshold_bytes, revs): """(path, size) of blobs above the threshold in commits not yet pushed.""" + import subprocess + + from commitrocket.support.errors import GitError + objects = run_git(repo, "rev-list", "--objects", *revs).stdout if not objects.strip(): return [] @@ -221,6 +234,8 @@ def find_large_unpushed_blobs(repo, threshold_bytes, revs): def get_file_size(repo, relative_path): + from pathlib import Path + try: path = Path(repo) / relative_path return path.stat().st_size if path.is_file() else 0 diff --git a/src/commitrocket/git/journal.py b/src/commitrocket/git/journal.py new file mode 100644 index 0000000..3e502c0 --- /dev/null +++ b/src/commitrocket/git/journal.py @@ -0,0 +1,175 @@ +from commitrocket.support.errors import CommitRocketError + +JOURNAL_NAME = "commitrocket-journal.jsonl" +LEGACY_NAME = "commitrocket-journal.json" +JOURNAL_VERSION = 1 + + +class JournalError(CommitRocketError): + """The journal cannot be used (for example it is from another version).""" + + +class Journal: + """An append-only log of a run, kept in .git so it is never committed. + + Each line is one JSON event: `run` (the parameters of the run, written once), + `staged` (before `git add`), `committed`, `pushed`, `resumed` and finally + `interrupted` or `failed`. The state of the run is rebuilt by replaying the + lines, and a line cut short by a crash is ignored. The file is removed when a + run finishes. Staged files that match the in-flight batch are ours; any other + staged file is not. + """ + + def __init__(self, repo): + self.path = self._git_path(repo, JOURNAL_NAME) + self._legacy = self._git_path(repo, LEGACY_NAME) + + @staticmethod + def _git_path(repo, name): + from pathlib import Path + + from commitrocket.git.git import run_git + + relative = run_git(repo, "rev-parse", "--git-path", name).stdout.strip() + return Path(repo) / relative + + # -- writing ----------------------------------------------------------- + + def start(self, params, branch, target, head): + """Begin a new journal for a run, replacing any earlier one.""" + self._legacy.unlink(missing_ok=True) + self.path.unlink(missing_ok=True) + self.append( + { + "event": "run", + "version": JOURNAL_VERSION, + "params": params, + "branch": branch, + "target": target, + "head": head, + } + ) + + def append(self, event): + import json + import os + from datetime import UTC, datetime + + from commitrocket.support.security import restrict_permissions + + event = {**event, "at": datetime.now(UTC).isoformat(timespec="seconds")} + created = not self.path.exists() + with open(self.path, "a", encoding="utf-8") as handle: + handle.write(json.dumps(event) + "\n") + handle.flush() + os.fsync(handle.fileno()) + if created: + restrict_permissions(self.path) + + def write(self, files, message, number): + """Record the batch about to be staged.""" + self.append( + { + "event": "staged", + "files": list(files), + "message": message, + "number": number, + } + ) + + def committed(self, number, sha): + self.append({"event": "committed", "number": number, "sha": sha}) + + def pushed(self, sha): + self.append({"event": "pushed", "sha": sha}) + + def note(self, event, **details): + """Append a status event, ignoring a journal that cannot be written.""" + try: + self.append({"event": event, **details}) + except OSError: + pass + + def delete(self): + self.path.unlink(missing_ok=True) + self._legacy.unlink(missing_ok=True) + + # -- reading ----------------------------------------------------------- + + def events(self): + import json + + try: + text = self.path.read_text(encoding="utf-8") + except OSError: + return [] + events = [] + for line in text.splitlines(): + try: + event = json.loads(line) + except ValueError: + continue # a line cut short by a crash + if isinstance(event, dict): + events.append(event) + return events + + def state(self): + """Replay the journal. Returns None when there is no usable run in it. + + Raises JournalError if the journal was written by another version. + """ + run = None + inflight = None + commits = [] + pushed = None + status = "running" + for event in self.events(): + kind = event.get("event") + if kind == "run": + run = event + elif kind == "staged": + inflight = event + elif kind == "committed": + commits.append((event.get("number"), event.get("sha"))) + if inflight and inflight.get("number") == event.get("number"): + inflight = None + elif kind == "pushed": + pushed = event.get("sha") + elif kind in ("interrupted", "failed"): + status = kind + if run is None: + return None + if run.get("version") != JOURNAL_VERSION or not isinstance( + run.get("params"), dict + ): + raise JournalError( + f"{self.path} was written by an incompatible CommitRocket version " + "or is damaged. Delete it and run without --resume to start over." + ) + numbers = [n for n, _ in commits if isinstance(n, int)] + return { + "params": run["params"], + "branch": run.get("branch"), + "target": run.get("target"), + "head": run.get("head"), + "commits": commits, + "pushed": pushed, + "inflight": inflight, + "status": status, + "next_number": max(numbers) + 1 if numbers else 0, + } + + def read(self): + """The batch that was being staged when the run stopped, or None.""" + try: + state = self.state() + except JournalError: + return None + inflight = state and state["inflight"] + if not inflight: + return None + return { + "files": inflight.get("files", []), + "message": inflight.get("message", ""), + "number": inflight.get("number"), + } diff --git a/src/commitrocket/lfs.py b/src/commitrocket/git/lfs.py similarity index 90% rename from src/commitrocket/lfs.py rename to src/commitrocket/git/lfs.py index 36efe3c..da9a7e0 100644 --- a/src/commitrocket/lfs.py +++ b/src/commitrocket/git/lfs.py @@ -1,14 +1,3 @@ -import os -import re -import shutil -import subprocess -import sys -from pathlib import Path, PurePosixPath - -from commitrocket.errors import CommitRocketError -from commitrocket.git import get_file_size, run_git -from commitrocket.security import has_control_chars - # Git hosts reject pushes containing files larger than this. HOST_LIMIT_MIB = 100 @@ -21,6 +10,8 @@ def find_lfs_candidates(repo, files, threshold_bytes, max_bytes): """Files above the LFS threshold that are still within the max file size.""" + from commitrocket.git.git import get_file_size + return [ path for path in files @@ -30,6 +21,11 @@ def find_lfs_candidates(repo, files, threshold_bytes, max_bytes): def attribute_line(path): """A .gitattributes-style rule that sends exactly this file through LFS.""" + import re + + from commitrocket.support.errors import CommitRocketError + from commitrocket.support.security import has_control_chars + if has_control_chars(path): # A newline here would let a file name add rules of its own. raise CommitRocketError( @@ -46,6 +42,9 @@ def committed_rule_lines(paths): Extension rules also cover future files of the same type. """ + import re + from pathlib import PurePosixPath + lines = set() for path in paths: pure = PurePosixPath(path) @@ -67,12 +66,18 @@ def all_files_rules(): def is_lfs_available(): + import subprocess + result = subprocess.run(["git", "lfs", "version"], capture_output=True) return result.returncode == 0 def install_command(): """Package-manager command that installs git-lfs, or None if unsupported.""" + import os + import shutil + import sys + if sys.platform == "win32" and shutil.which("winget"): return [ "winget", @@ -95,6 +100,10 @@ def install_command(): def ensure_git_lfs(console, force): """Make sure the git-lfs binary is available, installing it if needed.""" + import subprocess + + from commitrocket.support.errors import CommitRocketError + if is_lfs_available(): return @@ -143,6 +152,10 @@ def __init__(self, repo): def enable(self, paths, all_files=False): """Route paths through LFS, or every file when all_files is set.""" + from pathlib import Path + + from commitrocket.git.git import run_git + info_path = run_git( self.repo, "rev-parse", "--git-path", "info/attributes" ).stdout.strip() @@ -164,6 +177,8 @@ def enable(self, paths, all_files=False): def install_hooks(self): """Install LFS in this repository only, so pushes upload LFS files.""" + from commitrocket.git.git import run_git + run_git(self.repo, "lfs", "install", "--local") self.installed = True @@ -172,6 +187,11 @@ def write_committed_rules(self, paths): Returns True if the file changed. """ + from pathlib import Path + + from commitrocket.git.git import run_git + from commitrocket.support.errors import CommitRocketError + dirty = run_git( self.repo, "status", "--porcelain", "--", ".gitattributes" ).stdout.strip() @@ -200,6 +220,8 @@ def close(self, uninstall_hooks=True): Pass uninstall_hooks=False to keep the hooks, which unpushed commits containing LFS files still need to upload their data. """ + from commitrocket.git.git import run_git + if self.attributes_path is not None: if self.original is None: self.attributes_path.unlink(missing_ok=True) diff --git a/src/commitrocket/push.py b/src/commitrocket/git/push.py similarity index 95% rename from src/commitrocket/push.py rename to src/commitrocket/git/push.py index 01fceb4..ea264d8 100644 --- a/src/commitrocket/push.py +++ b/src/commitrocket/git/push.py @@ -1,13 +1,5 @@ import logging -import os import re -import subprocess -import time - -from rich.markup import escape - -from commitrocket.errors import PushError -from commitrocket.security import redact logger = logging.getLogger(__name__) @@ -78,9 +70,15 @@ def parse_lfs_bytes(line): def push_with_retries( - repo, progress, push_task, console, retries=0, sleep=time.sleep, **kwargs + repo, progress, push_task, console, retries=0, sleep=None, **kwargs ): """push_with_progress, retried with growing waits on transient errors.""" + import time + + from commitrocket.support.errors import PushError + + if sleep is None: + sleep = time.sleep attempt = 0 while True: try: @@ -121,6 +119,14 @@ def push_with_progress( covering both the git-lfs upload and the pack transfer. batch_bytes is the size of the batch being pushed and lets LFS byte counts become a percent. """ + import os + import subprocess + + from rich.markup import escape + + from commitrocket.support.errors import PushError + from commitrocket.support.security import redact + console.print("\n[bold cyan]Pushing commit...[/bold cyan]") logger.info("Pushing %s", repo) diff --git a/src/commitrocket/io/__init__.py b/src/commitrocket/io/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/commitrocket/logs.py b/src/commitrocket/io/logs.py similarity index 88% rename from src/commitrocket/logs.py rename to src/commitrocket/io/logs.py index 25faca4..67d7196 100644 --- a/src/commitrocket/logs.py +++ b/src/commitrocket/io/logs.py @@ -1,10 +1,4 @@ import logging -import os -import sys -from datetime import datetime -from pathlib import Path - -from commitrocket.security import redact, restrict_permissions LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR") DEFAULT_LEVEL = "INFO" @@ -15,11 +9,17 @@ class RedactingFormatter(logging.Formatter): """Hides credentials embedded in URLs, including in tracebacks.""" def format(self, record): + from commitrocket.support.security import redact + return redact(super().format(record)) def default_log_dir(): """The conventional per-user log folder for the current OS.""" + import os + import sys + from pathlib import Path + home = Path.home() if sys.platform == "win32": @@ -34,6 +34,11 @@ def default_log_dir(): def setup_logging(level=DEFAULT_LEVEL, log_file=None): """Log to a file for this run. Returns its path, or None if it can't be opened.""" + from datetime import datetime + from pathlib import Path + + from commitrocket.support.security import restrict_permissions + logger = logging.getLogger(LOGGER_NAME) logger.setLevel(getattr(logging, level.upper())) logger.propagate = False diff --git a/src/commitrocket/notify.py b/src/commitrocket/io/notify.py similarity index 69% rename from src/commitrocket/notify.py rename to src/commitrocket/io/notify.py index 988ddb2..31403ed 100644 --- a/src/commitrocket/notify.py +++ b/src/commitrocket/io/notify.py @@ -1,60 +1,33 @@ -import json import logging -import os -import shutil -import subprocess -import sys -import urllib.error -import urllib.request -from urllib.parse import urlparse - -from commitrocket.eta import format_duration -from commitrocket.report import ( - ABORTED, - CANCELLED, - DEFERRED, - FAILED, - INTERRUPTED, - SUCCESS, -) -from commitrocket.security import redact logger = logging.getLogger(__name__) -# Windows PowerShell's own AppUserModelID, which Windows already trusts to show toasts. -WINDOWS_APP_ID = ( - "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe" -) -WINDOWS_SCRIPT = f""" -[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null -$xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) -$text = $xml.GetElementsByTagName('text') -$text.Item(0).AppendChild($xml.CreateTextNode($env:CR_TITLE)) | Out-Null -$text.Item(1).AppendChild($xml.CreateTextNode($env:CR_BODY)) | Out-Null -$toast = [Windows.UI.Notifications.ToastNotification]::new($xml) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('{WINDOWS_APP_ID}').Show($toast) -""" # noqa: E501 -MACOS_SCRIPT = ( - 'display notification (system attribute "CR_BODY") ' - 'with title (system attribute "CR_TITLE")' -) - DESKTOP_TIMEOUT = 15 WEBHOOK_TIMEOUT = 10 -HEADLINES = { - SUCCESS: "finished", - DEFERRED: "finished, some files were skipped", - CANCELLED: "cancelled", - ABORTED: "stopped before starting", - INTERRUPTED: "interrupted", - FAILED: "failed", -} - def build_message(report): """(title, body) describing how the run ended.""" - title = f"CommitRocket {HEADLINES.get(report.status, report.status)}" + from commitrocket.core.eta import format_duration + from commitrocket.io.report import ( + ABORTED, + CANCELLED, + DEFERRED, + FAILED, + INTERRUPTED, + SUCCESS, + ) + from commitrocket.support.security import redact + + headlines = { + SUCCESS: "finished", + DEFERRED: "finished, some files were skipped", + CANCELLED: "cancelled", + ABORTED: "stopped before starting", + INTERRUPTED: "interrupted", + FAILED: "failed", + } + title = f"CommitRocket {headlines.get(report.status, report.status)}" parts = [] if report.batches: @@ -76,7 +49,17 @@ def build_message(report): return title, redact("; ".join(parts) or "No changes were made.") +def _read_script(name): + """Text of a notification script shipped in the io/scripts folder.""" + from importlib.resources import files + + return (files("commitrocket.io") / "scripts" / name).read_text(encoding="utf-8") + + def _run_quietly(command, env): + import os + import subprocess + result = subprocess.run( command, env={**os.environ, **env}, @@ -89,14 +72,20 @@ def _run_quietly(command, env): def notify_desktop(title, body): """Show a native notification. Returns the method used; 'bell' if none worked.""" + import shutil + import subprocess + import sys + env = {"CR_TITLE": title, "CR_BODY": body} try: if sys.platform == "win32" and shutil.which("powershell"): command = ["powershell", "-NoProfile", "-NonInteractive", "-Command"] - if _run_quietly(command + [WINDOWS_SCRIPT], env): + if _run_quietly(command + [_read_script("toast.ps1")], env): return "windows-toast" elif sys.platform == "darwin" and shutil.which("osascript"): - if _run_quietly(["osascript", "-e", MACOS_SCRIPT], env): + if _run_quietly( + ["osascript", "-e", _read_script("notification.applescript")], env + ): return "macos-notification" elif shutil.which("notify-send"): command = ["notify-send", "--app-name=CommitRocket", title, body] @@ -111,12 +100,19 @@ def notify_desktop(title, body): def is_valid_webhook(url): + from urllib.parse import urlparse + parsed = urlparse(url) return parsed.scheme in ("http", "https") and bool(parsed.netloc) def notify_webhook(url, title, body, report): """POST a JSON summary. 'text' and 'content' suit Slack/Teams and Discord.""" + import json + import urllib.request + + from commitrocket.support.security import redact + payload = { "text": f"{title}: {body}", "content": f"{title}: {body}", @@ -147,6 +143,8 @@ def notify_webhook(url, title, body, report): def send_notifications(console, report, desktop=False, webhook=None): """Notify about the finished run. Failures are reported but never raised.""" + import urllib.error + title, body = build_message(report) if desktop: diff --git a/src/commitrocket/report.py b/src/commitrocket/io/report.py similarity index 90% rename from src/commitrocket/report.py rename to src/commitrocket/io/report.py index 592b49d..79b1a68 100644 --- a/src/commitrocket/report.py +++ b/src/commitrocket/io/report.py @@ -1,14 +1,3 @@ -import json -import os -import tempfile -import time -from dataclasses import asdict -from datetime import UTC, datetime -from pathlib import Path - -from commitrocket import __version__ -from commitrocket.security import redact_value, restrict_permissions - SCHEMA_VERSION = 1 SUCCESS = "success" @@ -24,6 +13,12 @@ class RunReport: """Collects what a run did, for --report and for notifications.""" def __init__(self, options=None): + import time + from dataclasses import asdict + from datetime import UTC, datetime + + from commitrocket.support.security import redact_value + self.started_at = datetime.now(UTC) self._started = time.monotonic() self.finished_at = None @@ -65,6 +60,9 @@ def set_deferred(self, items): self.deferred = [{"path": path, "size_bytes": size} for path, size in items] def finish(self, exit_code, log_file=None): + import time + from datetime import UTC, datetime + self.exit_code = exit_code self.log_file = str(log_file) if log_file else None self.finished_at = datetime.now(UTC) @@ -79,6 +77,8 @@ def total_bytes(self): return sum(batch["size_bytes"] for batch in self.batches) def to_dict(self): + from commitrocket import __version__ + return { "schema_version": SCHEMA_VERSION, "tool": "commitrocket", @@ -110,6 +110,13 @@ def to_dict(self): def write(self, path): """Write the report as JSON, replacing any file there in one step.""" + import json + import os + import tempfile + from pathlib import Path + + from commitrocket.support.security import restrict_permissions + path = Path(path).expanduser() path.parent.mkdir(parents=True, exist_ok=True) text = json.dumps(self.to_dict(), indent=2, ensure_ascii=False) + "\n" diff --git a/src/commitrocket/io/scripts/notification.applescript b/src/commitrocket/io/scripts/notification.applescript new file mode 100644 index 0000000..d9bbad7 --- /dev/null +++ b/src/commitrocket/io/scripts/notification.applescript @@ -0,0 +1,2 @@ +-- Shows a macOS notification. Title and body arrive in CR_TITLE and CR_BODY, never in the script text. +display notification (system attribute "CR_BODY") with title (system attribute "CR_TITLE") diff --git a/src/commitrocket/io/scripts/toast.ps1 b/src/commitrocket/io/scripts/toast.ps1 new file mode 100644 index 0000000..10d8e60 --- /dev/null +++ b/src/commitrocket/io/scripts/toast.ps1 @@ -0,0 +1,9 @@ +# Shows a Windows toast. Title and body arrive in CR_TITLE and CR_BODY, never in the script text. +# The app ID is Windows PowerShell's own, which Windows already trusts to show toasts. +[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null +$xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) +$text = $xml.GetElementsByTagName('text') +$text.Item(0).AppendChild($xml.CreateTextNode($env:CR_TITLE)) | Out-Null +$text.Item(1).AppendChild($xml.CreateTextNode($env:CR_BODY)) | Out-Null +$toast = [Windows.UI.Notifications.ToastNotification]::new($xml) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe').Show($toast) diff --git a/src/commitrocket/ui.py b/src/commitrocket/io/ui.py similarity index 79% rename from src/commitrocket/ui.py rename to src/commitrocket/io/ui.py index fdf541c..a319295 100644 --- a/src/commitrocket/ui.py +++ b/src/commitrocket/io/ui.py @@ -1,39 +1,30 @@ -import time - -from rich.markup import escape -from rich.panel import Panel -from rich.progress import ( - BarColumn, - Progress, - ProgressColumn, - SpinnerColumn, - TaskProgressColumn, - TextColumn, - TimeElapsedColumn, -) -from rich.table import Table -from rich.text import Text - -from commitrocket.batching import MIB -from commitrocket.eta import format_duration -from commitrocket.git import get_file_size, get_pending_files - +def make_progress(console): + from rich.progress import ( + BarColumn, + Progress, + ProgressColumn, + SpinnerColumn, + TaskProgressColumn, + TextColumn, + TimeElapsedColumn, + ) + from rich.text import Text -class EtaColumn(ProgressColumn): - """Shows the run's own ETA for tasks created with an `estimator` field.""" + from commitrocket.core.eta import format_duration - def render(self, task): - estimator = task.fields.get("estimator") - if estimator is None: - return Text("") + class EtaColumn(ProgressColumn): + """Shows the run's own ETA for tasks created with an `estimator` field.""" - remaining = estimator.estimate(task.completed, task.total or 0) - if remaining is None: - return Text("ETA estimating…", style="dim") - return Text(f"ETA {format_duration(remaining)}", style="progress.remaining") + def render(self, task): + estimator = task.fields.get("estimator") + if estimator is None: + return Text("") + remaining = estimator.estimate(task.completed, task.total or 0) + if remaining is None: + return Text("ETA estimating…", style="dim") + return Text(f"ETA {format_duration(remaining)}", style="progress.remaining") -def make_progress(console): return Progress( SpinnerColumn(), TextColumn("[bold cyan]{task.description}"), @@ -46,6 +37,10 @@ def make_progress(console): def print_run_info(console, repo, branch, upstream, limit_mib, max_mib, number): + from rich.panel import Panel + from rich.table import Table + from rich.text import Text + info = Table.grid(padding=(0, 2)) info.add_column(style="bold cyan") info.add_column() @@ -60,6 +55,12 @@ def print_run_info(console, repo, branch, upstream, limit_mib, max_mib, number): def print_lfs_required(console, repo, paths, threshold_mib): + from rich.table import Table + from rich.text import Text + + from commitrocket.core.batching import MIB + from commitrocket.git.git import get_file_size + table = Table(title=f"Files over {threshold_mib} MiB", show_lines=True) table.add_column("File", overflow="fold") table.add_column("Size (MiB)", justify="right") @@ -77,6 +78,9 @@ def print_lfs_required(console, repo, paths, threshold_mib): def print_resume(console, staged, entry, unpushed): + from rich.panel import Panel + from rich.text import Text + lines = [] if staged: lines.append( @@ -96,6 +100,11 @@ def print_resume(console, staged, entry, unpushed): def print_dry_run( console, batches, deferred, messages, lfs_files, lfs_scope, no_push=False ): + from rich.table import Table + from rich.text import Text + + from commitrocket.core.batching import MIB + table = Table(title="Dry run: planned batches", show_lines=True) table.add_column("Batch", justify="right") table.add_column("Commit message") @@ -143,6 +152,12 @@ def print_dry_run( def print_stuck_commits(console, commits, blobs, upstream, threshold_mib): + from rich.markup import escape + from rich.table import Table + from rich.text import Text + + from commitrocket.core.batching import MIB + table = Table(title=f"Unpushed files over {threshold_mib} MiB", show_lines=True) table.add_column("File", overflow="fold") table.add_column("Size (MiB)", justify="right") @@ -170,6 +185,15 @@ def print_final_summary( console, repo, batch_count, started_at, max_mib, pending_files=None, pushed=True ): """Report files still deferred after all eligible batches finish.""" + import time + + from rich.panel import Panel + from rich.table import Table + from rich.text import Text + + from commitrocket.core.batching import MIB + from commitrocket.git.git import get_file_size, get_pending_files + elapsed = time.monotonic() - started_at pending = pending_files() if pending_files else get_pending_files(repo) diff --git a/src/commitrocket/journal.py b/src/commitrocket/journal.py deleted file mode 100644 index fc78056..0000000 --- a/src/commitrocket/journal.py +++ /dev/null @@ -1,31 +0,0 @@ -import json -from pathlib import Path - -from commitrocket.git import run_git - - -class Journal: - """Remembers the batch being staged so an interrupted run can be resumed. - - It lives inside .git, is written before `git add` and removed once the commit - exists. Staged files that match it are ours; any other staged file is not. - """ - - def __init__(self, repo): - relative = run_git( - repo, "rev-parse", "--git-path", "commitrocket-journal.json" - ).stdout.strip() - self.path = Path(repo) / relative - - def read(self): - try: - return json.loads(self.path.read_text(encoding="utf-8")) - except (OSError, ValueError): - return None - - def write(self, files, message, number): - entry = {"files": list(files), "message": message, "number": number} - self.path.write_text(json.dumps(entry), encoding="utf-8") - - def clear(self): - self.path.unlink(missing_ok=True) diff --git a/src/commitrocket/runner.py b/src/commitrocket/runner.py deleted file mode 100644 index 7e67c11..0000000 --- a/src/commitrocket/runner.py +++ /dev/null @@ -1,681 +0,0 @@ -import logging -import time -from pathlib import Path - -from rich.markup import escape -from rich.panel import Panel -from rich.text import Text - -from commitrocket.batching import ( - MIB, - estimate_batch_count, - plan_batches, - select_batch, -) -from commitrocket.errors import CommitRocketError -from commitrocket.eta import EtaEstimator -from commitrocket.filters import FileFilter -from commitrocket.git import ( - LocalConfig, - add_files, - find_large_unpushed_blobs, - get_file_size, - get_pending_files, - get_remote_url, - get_staged_files, - get_unpushed_commits, - resolve_target, - run_git, -) -from commitrocket.journal import Journal -from commitrocket.lfs import ( - HOST_LIMIT_MIB, - LfsSession, - committed_rule_lines, - ensure_git_lfs, - find_lfs_candidates, - is_lfs_available, -) -from commitrocket.push import push_with_retries -from commitrocket.report import ( - ABORTED, - CANCELLED, - DEFERRED, - DRY_RUN, - FAILED, - INTERRUPTED, - SUCCESS, - RunReport, -) -from commitrocket.security import redact -from commitrocket.template import render_message -from commitrocket.ui import ( - make_progress, - print_dry_run, - print_final_summary, - print_lfs_required, - print_resume, - print_run_info, - print_stuck_commits, -) -from commitrocket.verify import ( - expected_lfs_paths, - find_non_pointers, - unpushed_has_lfs_pointers, - verify_remote_head, -) - -logger = logging.getLogger(__name__) - - -def own_output_files(repo, options): - """Paths (relative to the repo) of the log and report files this run writes.""" - found = set() - for raw in (options.log_file, options.report): - if not raw: - continue - path = Path(raw).expanduser().resolve() - try: - found.add(path.relative_to(repo).as_posix()) - except ValueError: - pass # outside the repository - return found - - -def push_target(repo, progress, push_task, console, options, target, **kwargs): - """Push HEAD to the run's remote branch, retrying transient failures.""" - push_with_retries( - repo, - progress, - push_task, - console, - retries=options.retries, - remote=target.remote, - refspec=target.refspec, - **kwargs, - ) - - -def process_batches( - console, - repo, - progress, - task, - push_task, - options, - target, - number, - limit_bytes, - max_bytes, - list_pending, - lfs_files=frozenset(), - lfs_limit_bytes=0, - estimator=None, - journal=None, - check_lfs=None, - verify=None, - report=None, -): - """Commit (and push) batches until only deferred files remain.""" - batch_count = 0 - commit_number = number - - # Progress is measured in bytes so the ETA reflects the real amount of work. - total_work = sum( - size - for size in (get_file_size(repo, path) for path in list_pending()) - if size <= max_bytes - ) - done_bytes = 0 - progress.update(task, total=max(total_work, 1), completed=0) - if estimator: - estimator.start() - - selection = ( - limit_bytes, - max_bytes, - lfs_files, - lfs_limit_bytes, - options.batch_type, - ) - - while True: - pending = list_pending() - if not pending: - break - - selected, _, total_bytes = select_batch(repo, pending, *selection) - - if not selected: - # Only oversized files remain; report them at the end. - break - - remaining_estimate = estimate_batch_count(repo, pending, *selection) - estimated_total = max(batch_count + remaining_estimate, batch_count + 1) - - progress.update( - task, - description=( - f"Batch {batch_count + 1}/{estimated_total}: " - f"commit #{commit_number}" - ), - ) - - console.rule(f"[bold cyan]Batch {batch_count + 1}[/bold cyan]") - console.print( - f"Selected: {len(selected)} file(s), {total_bytes / MIB:.2f} MiB" - ) - logger.info( - "Batch %d/%d: %d file(s), %.2f MiB, commit #%d", - batch_count + 1, - estimated_total, - len(selected), - total_bytes / MIB, - commit_number, - ) - logger.debug("Batch %d files: %s", batch_count + 1, selected) - - commit_message = render_message( - options.message_template, - options.message, - commit_number, - batch_count + 1, - len(selected), - total_bytes / MIB, - selected[0], - ) - - # Lets an interrupted run recognise the files it left staged. - if journal: - journal.write(selected, commit_message, commit_number) - - add_files(repo, selected) - - if not get_staged_files(repo): - raise CommitRocketError("No staged changes to commit.") - - run_git(repo, "commit", "-m", commit_message) - if journal: - journal.clear() - - entry = None - if report: - entry = report.add_batch( - commit_number, - commit_message, - selected, - total_bytes, - lfs_files=len(lfs_files.intersection(selected)), - commit=run_git(repo, "rev-parse", "HEAD").stdout.strip(), - ) - - # Catch files that did not become LFS pointers before uploading them. - if check_lfs: - check_lfs(selected) - - if not options.no_push: - push_target( - repo, - progress, - push_task, - console, - options, - target, - on_upload=lambda percent, base=done_bytes, size=total_bytes: ( - progress.update(task, completed=base + size * percent / 100) - ), - batch_bytes=total_bytes, - ) - - if entry: - entry["pushed"] = True - - if verify: - verify() - if entry: - entry["verified"] = True - - batch_count += 1 - commit_number += 1 - done_bytes += total_bytes - progress.update(task, completed=done_bytes) - - outcome = "committed" if options.no_push else "committed and pushed" - console.print(f"[green]Batch {batch_count} {outcome}.[/green]") - logger.info("Batch %d %s", batch_count, outcome) - - return batch_count - - -def run(console, options, report=None): - """Batch, commit and push pending changes. Returns a process exit code. - - The outcome is recorded in report (a RunReport) for --report and notifications. - """ - o = options - report = report or RunReport(options) - repo = Path(o.repo).expanduser().resolve() - - if not repo.is_dir(): - console.print(f"[red]Repository directory not found: {repo}[/red]") - report.abort(f"Repository directory not found: {repo}") - return 2 - - started_at = time.monotonic() - lfs = None - config = None - acting = False - completed = False - - try: - root = run_git(repo, "rev-parse", "--show-toplevel") - repo = Path(root.stdout.strip()).resolve() - - branch = run_git(repo, "branch", "--show-current").stdout.strip() - if not branch: - raise CommitRocketError( - "Detached HEAD. Check out a branch before continuing." - ) - - target = resolve_target(repo, branch, o.remote, o.branch) - report.repo = str(repo) - report.branch = branch - report.target = target.label - file_filter = FileFilter.from_options( - repo, o.include, o.exclude, o.include_from, o.exclude_from - ) - - # The run's own log and report must never be committed, or writing them - # would create a new batch forever. - own_files = own_output_files(repo, o) - - def raw_pending(): - return [p for p in get_pending_files(repo) if p not in own_files] - - def list_pending(): - return file_filter.apply(raw_pending()) - - logger.info( - "Run started: repo=%s branch=%s target=%s limit=%d MiB max=%d MiB " - "batch_type=%s use_lfs=%s dry_run=%s no_push=%s retries=%d", - repo, - branch, - target.label, - o.limit_mib, - o.max_mib, - o.batch_type, - o.use_lfs, - o.dry_run, - o.no_push, - o.retries, - ) - - # Files left staged by an interrupted run are ours; anything else is not. - journal = Journal(repo) - entry = journal.read() - staged = get_staged_files(repo) - resume_staged = [] - if staged: - if entry and set(staged) <= set(entry["files"]): - resume_staged = staged - else: - raise CommitRocketError( - f"{len(staged)} file(s) already staged. Commit or unstage " - "them before running this tool." - ) - elif entry and not o.dry_run: - journal.clear() - - # Earlier failed runs can leave commits that the host will reject. - stuck = find_large_unpushed_blobs(repo, HOST_LIMIT_MIB * MIB, target.revs) - if stuck: - logger.warning("Unpushed commits contain large files: %s", stuck) - print_stuck_commits( - console, - get_unpushed_commits(repo, target.revs), - stuck, - target.label, - HOST_LIMIT_MIB, - ) - report.abort( - f"Unpushed commits contain files over {HOST_LIMIT_MIB} MiB: " - + ", ".join(path for path, _ in stuck[:5]) - ) - return 2 - - unpushed = get_unpushed_commits(repo, target.revs) - start_number = ( - max(o.number, entry["number"] + 1) if resume_staged else o.number - ) - - print_run_info( - console, - repo, - branch, - target.label, - o.limit_mib, - o.max_mib, - start_number, - ) - - status = run_git(repo, "status", "--short").stdout.strip() - console.print( - Panel(Text(status or "(no pending changes)"), title="Pending Changes") - ) - - if resume_staged or unpushed: - logger.info( - "Resuming: %d staged file(s), %d unpushed commit(s)", - len(resume_staged), - len(unpushed), - ) - print_resume(console, resume_staged, entry, unpushed) - report.resumed = { - "staged_files": len(resume_staged), - "unpushed_commits": len(unpushed), - } - - limit_bytes = o.limit_mib * MIB - max_bytes = o.max_mib * MIB - lfs_limit_bytes = (o.lfs_batch_mib or o.limit_mib) * MIB - - all_pending = raw_pending() - pending_files = list_pending() - if file_filter.active: - left_out = len(all_pending) - len(pending_files) - console.print( - f"[dim]Filters: {len(pending_files)} file(s) selected, " - f"{left_out} left out.[/dim]" - ) - logger.info("Filters kept %d, left out %d", len(pending_files), left_out) - - if not o.use_lfs: - over_host_limit = find_lfs_candidates( - repo, pending_files, HOST_LIMIT_MIB * MIB, max_bytes - ) - if over_host_limit: - # The host would reject the push, so stop before committing anything. - logger.warning( - "Files over the limit need --use-lfs: %s", over_host_limit - ) - print_lfs_required(console, repo, over_host_limit, HOST_LIMIT_MIB) - report.abort( - f"{len(over_host_limit)} file(s) over {HOST_LIMIT_MIB} MiB " - "need --use-lfs" - ) - return 2 - - lfs_paths = [] - lfs_scope = "" - if o.use_lfs: - lfs_paths = find_lfs_candidates( - repo, pending_files, o.lfs_threshold_mib * MIB, max_bytes - ) - report.lfs["files"] = len(lfs_paths) - if not lfs_paths: - lfs_scope = ( - f"--use-lfs: no files above {o.lfs_threshold_mib} MiB; " - "LFS not needed." - ) - else: - which = ( - f"All {len(lfs_paths)} file(s)" - if o.lfs_threshold_mib == 0 - else f"{len(lfs_paths)} file(s) above {o.lfs_threshold_mib} MiB" - ) - if o.lfs_commit_rules: - rule_count = len(committed_rule_lines(lfs_paths)) - lfs_scope = ( - f"{which} will be stored with Git LFS. {rule_count} rule(s) " - "will be committed to .gitattributes first, so they also " - "cover files of the same type added later." - ) - else: - lfs_scope = ( - f"{which} will be stored with Git LFS for this run only; " - "no LFS config is committed, so checkouts and clones will " - "contain LFS pointer files instead of the real files." - ) - if o.dry_run and not is_lfs_available(): - lfs_scope += " git-lfs is not installed and would be installed." - - if o.dry_run: - batches, deferred = plan_batches( - repo, - pending_files, - limit_bytes, - max_bytes, - frozenset(lfs_paths), - lfs_limit_bytes, - o.batch_type, - ) - messages = [ - render_message( - o.message_template, - o.message, - start_number + index, - index + 1, - len(paths), - size / MIB, - paths[0], - ) - for index, (paths, size) in enumerate(batches) - ] - logger.info("Dry run: %d batch(es) planned", len(batches)) - for index, (paths, size) in enumerate(batches): - report.add_batch( - start_number + index, - messages[index], - paths, - size, - lfs_files=len(set(paths).intersection(lfs_paths)), - ) - report.set_deferred(deferred) - report.status = DRY_RUN - print_dry_run( - console, batches, deferred, messages, lfs_paths, lfs_scope, o.no_push - ) - return 0 - - if lfs_scope: - console.print(f"[cyan]{lfs_scope}[/cyan]") - - if not o.force: - answer = ( - console.input( - "[yellow]Proceed with staging, committing, and " - f"{'finishing' if o.no_push else 'pushing'}? [y/N][/yellow] " - ) - .strip() - .lower() - ) - if answer not in {"y", "yes"}: - console.print("[yellow]Cancelled.[/yellow]") - logger.info("Cancelled by user at the confirmation prompt") - report.status = CANCELLED - return 1 - - # Unpushed LFS pointers need the LFS hooks, or a push would publish - # pointers whose files were never uploaded. - resume_needs_lfs = ( - not o.no_push - and bool(unpushed) - and unpushed_has_lfs_pointers(repo, target.revs) - ) - if lfs_paths or resume_needs_lfs: - ensure_git_lfs(console, o.force) - - def verify(): - verify_remote_head(repo, target.remote, target.ref, o.retries) - - def check_lfs(selected): - bad = find_non_pointers(repo, expected_lfs_paths(selected, lfs_paths)) - if bad: - raise CommitRocketError( - f"{len(bad)} file(s) were committed as ordinary files instead of " - f"LFS pointers (first: {bad[0]}). Nothing was pushed. Drop the " - f"commit with 'git reset --mixed {target.label}' and report this." - ) - - acting = True - try: - # Repository-local settings only; the previous values are restored below. - config = LocalConfig(repo) - if o.compression_threads is not None: - config.set("pack.threads", o.compression_threads) - logger.info("Set local pack.threads=%d", o.compression_threads) - if o.lfs_threads is not None: - config.set("lfs.concurrenttransfers", o.lfs_threads) - logger.info("Set local lfs.concurrenttransfers=%d", o.lfs_threads) - if o.post_buffer_mib is not None: - url = get_remote_url(repo, target.remote).lower() - if url.startswith(("http://", "https://")): - config.set("http.postBuffer", o.post_buffer_mib * MIB) - logger.info("Set local http.postBuffer=%d MiB", o.post_buffer_mib) - else: - console.print( - "[dim]--post-buffer-mib ignored: remote is not HTTP(S).[/dim]" - ) - logger.info("--post-buffer-mib ignored for non-HTTP remote") - - if lfs_paths or resume_needs_lfs: - lfs = LfsSession(repo) - if lfs_paths and not o.lfs_commit_rules: - lfs.enable(lfs_paths, all_files=o.lfs_threshold_mib == 0) - logger.info( - "LFS enabled locally for %d file(s) (threshold %d MiB)", - len(lfs_paths), - o.lfs_threshold_mib, - ) - logger.debug("LFS files: %s", lfs_paths) - else: - lfs.install_hooks() - - with make_progress(console) as progress: - estimator = EtaEstimator() - task = progress.add_task( - "Preparing batches", total=1, estimator=estimator - ) - push_task = progress.add_task("Git push", total=100, visible=False) - - if resume_staged: - run_git(repo, "commit", "-m", entry["message"]) - journal.clear() - logger.info("Committed resumed batch: %s", entry["message"]) - if find_large_unpushed_blobs( - repo, HOST_LIMIT_MIB * MIB, target.revs - ): - raise CommitRocketError( - "The resumed commit contains files over " - f"{HOST_LIMIT_MIB} MiB. Drop it with " - f"'git reset --mixed {target.label}' and run again." - ) - - if (resume_staged or unpushed) and not o.no_push: - push_target(repo, progress, push_task, console, o, target) - verify() - console.print("[green]Resumed commits pushed.[/green]") - - if o.lfs_commit_rules and lfs_paths: - if lfs.write_committed_rules(lfs_paths): - run_git(repo, "add", "--", ".gitattributes") - rules_message = f"{o.message.rstrip()} (LFS rules)" - run_git(repo, "commit", "-m", rules_message) - logger.info("Committed LFS rules: %s", rules_message) - report.lfs["rules_commit"] = run_git( - repo, "rev-parse", "HEAD" - ).stdout.strip() - console.print("[cyan]Committed LFS rules.[/cyan]") - push_target(repo, progress, push_task, console, o, target) - verify() - - batch_count = process_batches( - console, - repo, - progress, - task, - push_task, - o, - target, - start_number, - limit_bytes, - max_bytes, - list_pending, - frozenset(lfs_paths), - lfs_limit_bytes, - estimator, - journal, - check_lfs if lfs_paths else None, - verify, - report, - ) - completed = True - finally: - if lfs: - keep_hooks = False - if not completed: - try: - keep_hooks = unpushed_has_lfs_pointers(repo, target.revs) - except (RuntimeError, OSError): - keep_hooks = True - lfs.close(uninstall_hooks=not keep_hooks) - if keep_hooks: - console.print( - "[yellow]Git LFS hooks were left installed because unpushed " - "commits contain LFS files. Run CommitRocket again to push " - "them; a plain 'git push' only works while the hooks " - "stay.[/yellow]" - ) - logger.warning("LFS hooks kept: unpushed LFS commits remain") - else: - logger.info("Local LFS setup removed") - if config: - config.restore() - logger.info("Local git config restored") - - code = print_final_summary( - console, - repo, - batch_count, - started_at, - o.max_mib, - pending_files=list_pending, - pushed=not o.no_push, - ) - report.set_deferred( - (path, size) - for path, size in ((p, get_file_size(repo, p)) for p in list_pending()) - if size > max_bytes - ) - report.status = SUCCESS if code == 0 else DEFERRED - logger.info( - "Finished: %d batch(es) in %.1f s, exit code %d", - batch_count, - time.monotonic() - started_at, - code, - ) - return code - - except KeyboardInterrupt: - console.print("\n[yellow]Interrupted by user.[/yellow]") - report.status = INTERRUPTED - report.error = "Interrupted by user" - if acting: - console.print( - "[dim]Run the same command again to resume from where it " - "stopped.[/dim]" - ) - logger.warning("Interrupted by user") - return 130 - except (RuntimeError, OSError) as exc: - message = redact(str(exc)) - console.print(f"\n[bold red]Error:[/bold red] {escape(message)}") - report.status = ABORTED if not acting else FAILED - report.error = message - if acting: - console.print( - "[dim]Run the same command again to resume from where it " - "stopped.[/dim]" - ) - logger.error("Run failed: %s", exc, exc_info=True) - return 1 diff --git a/src/commitrocket/support/__init__.py b/src/commitrocket/support/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/commitrocket/config.py b/src/commitrocket/support/config.py similarity index 97% rename from src/commitrocket/config.py rename to src/commitrocket/support/config.py index cd99b53..df4c502 100644 --- a/src/commitrocket/config.py +++ b/src/commitrocket/support/config.py @@ -1,7 +1,4 @@ -import tomllib -from pathlib import Path - -from commitrocket.errors import CommitRocketError +from commitrocket.support.errors import CommitRocketError CONFIG_NAME = "commitrocket.toml" PYPROJECT_NAME = "pyproject.toml" @@ -34,6 +31,8 @@ def find_config(repo, explicit=None): Looked up in the repository folder: commitrocket.toml first, then the [tool.commitrocket] table of pyproject.toml. --config overrides the lookup. """ + from pathlib import Path + if explicit: path = Path(explicit).expanduser() if not path.is_file(): @@ -55,6 +54,8 @@ def find_config(repo, explicit=None): def _load(path): + import tomllib + try: with open(path, "rb") as handle: data = tomllib.load(handle) diff --git a/src/commitrocket/doctor.py b/src/commitrocket/support/doctor.py similarity index 87% rename from src/commitrocket/doctor.py rename to src/commitrocket/support/doctor.py index 9e8f6c3..d4112ae 100644 --- a/src/commitrocket/doctor.py +++ b/src/commitrocket/support/doctor.py @@ -1,28 +1,4 @@ import logging -import subprocess -import sys -from pathlib import Path - -from rich.table import Table -from rich.text import Text - -from commitrocket.batching import MIB -from commitrocket.config import ConfigError, find_config -from commitrocket.errors import CommitRocketError, GitError -from commitrocket.filters import IGNORE_FILE -from commitrocket.git import ( - find_large_unpushed_blobs, - get_file_size, - get_pending_files, - get_staged_files, - get_unpushed_commits, - resolve_target, - run_git, -) -from commitrocket.journal import Journal -from commitrocket.lfs import HOST_LIMIT_MIB, is_lfs_available -from commitrocket.logs import default_log_dir -from commitrocket.security import redact logger = logging.getLogger(__name__) @@ -32,11 +8,15 @@ def _first_line(text): + from commitrocket.support.security import redact + lines = [line for line in text.strip().splitlines() if line.strip()] return redact(lines[0]) if lines else "no details" def _remote_check(repo, args, label): + import subprocess + try: result = subprocess.run( ["git", "-C", str(repo), *args], @@ -52,6 +32,8 @@ def _remote_check(repo, args, label): def _check_log_dir(): + from commitrocket.io.logs import default_log_dir + folder = default_log_dir() try: folder.mkdir(parents=True, exist_ok=True) @@ -65,6 +47,26 @@ def _check_log_dir(): def collect_checks(repo, remote=None, branch=None, offline=False, config_path=None): """Run every check and return [(status, name, detail), ...].""" + import subprocess + import sys + from pathlib import Path + + from commitrocket.core.batching import MIB + from commitrocket.core.filters import IGNORE_FILE + from commitrocket.git.git import ( + find_large_unpushed_blobs, + get_file_size, + get_pending_files, + get_staged_files, + get_unpushed_commits, + resolve_target, + run_git, + ) + from commitrocket.git.journal import Journal + from commitrocket.git.lfs import HOST_LIMIT_MIB, is_lfs_available + from commitrocket.support.config import ConfigError, find_config + from commitrocket.support.errors import CommitRocketError, GitError + results = [] def add(status, name, detail): @@ -179,6 +181,9 @@ def run_doctor( console, repo, remote=None, branch=None, offline=False, config_path=None ): """Print a health report. Returns 1 if any check failed, else 0.""" + from rich.table import Table + from rich.text import Text + results = collect_checks(repo, remote, branch, offline, config_path) table = Table(title="CommitRocket doctor", show_lines=False) diff --git a/src/commitrocket/errors.py b/src/commitrocket/support/errors.py similarity index 100% rename from src/commitrocket/errors.py rename to src/commitrocket/support/errors.py diff --git a/src/commitrocket/security.py b/src/commitrocket/support/security.py similarity index 85% rename from src/commitrocket/security.py rename to src/commitrocket/support/security.py index 853a534..053a026 100644 --- a/src/commitrocket/security.py +++ b/src/commitrocket/support/security.py @@ -1,10 +1,7 @@ """Small helpers that keep untrusted text from doing harm.""" -import os import re -from commitrocket.errors import CommitRocketError - # user:password@ inside a URL, e.g. https://name:token@host/path _CREDENTIALS = re.compile(r"(?i)\b([a-z][a-z0-9+.\-]*://)[^/\s@]+@") _CONTROL = re.compile(r"[\x00-\x1f\x7f]") @@ -32,8 +29,13 @@ def has_control_chars(text): def validate_ref_part(value, label): """Reject remote and branch names that Git could read as options.""" - if not value or value.startswith("-") or has_control_chars(value) or any( - char.isspace() for char in value + from commitrocket.support.errors import CommitRocketError + + if ( + not value + or value.startswith("-") + or has_control_chars(value) + or any(char.isspace() for char in value) ): raise CommitRocketError( f"Invalid {label} {value!r}: it must not be empty, start with '-', " @@ -44,6 +46,8 @@ def validate_ref_part(value, label): def restrict_permissions(path): """Make a file readable and writable by its owner only (best effort).""" + import os + try: os.chmod(path, 0o600) except OSError: diff --git a/sweepito.toml b/sweepito.toml new file mode 100644 index 0000000..229a6d7 --- /dev/null +++ b/sweepito.toml @@ -0,0 +1,13 @@ +[defaults] +profiles = ["python"] +risk = "safe" + +[clean] +# Wheel and sdist output from `uv build`; it is rebuilt on demand. Build output is opt-in +# because it is slow to rebuild for some projects. +enable = ["python.build", "python.dist"] +# Exclusions always win over cleanup rules. Keep the uv environment between commits. +exclude = [".venv/"] + +[hook] +quiet = true diff --git a/tests/integration/test_e2e.py b/tests/integration/test_e2e.py index eeb3ea3..7cf8f7e 100644 --- a/tests/integration/test_e2e.py +++ b/tests/integration/test_e2e.py @@ -6,7 +6,8 @@ import pytest from commitrocket.cli import main -from commitrocket.git import run_git +from commitrocket.core.template import ATTRIBUTION +from commitrocket.git.git import run_git pytestmark = pytest.mark.integration @@ -59,9 +60,9 @@ def test_full_run_pushes_every_batch_and_writes_a_report(project, tmp_path): report = json.loads(report_path.read_text(encoding="utf-8")) assert report["status"] == "success" assert [b["message"] for b in report["batches"]] == [ - "Data #1", - "Data #2", - "Data #3", + f"Data #1\n\n{ATTRIBUTION}", + f"Data #2\n\n{ATTRIBUTION}", + f"Data #3\n\n{ATTRIBUTION}", ] assert all(b["pushed"] and b["verified"] for b in report["batches"]) @@ -164,3 +165,207 @@ def get_staged(repo): def untracked(repo): out = run_git(repo, "ls-files", "--others", "--exclude-standard").stdout return out.split() + + +def commit_bodies(repo, count): + out = run_git(repo, "log", f"-{count}", "--format=%B%x00").stdout + return [body.strip() for body in out.split("\0") if body.strip()] + + +def test_commits_end_with_the_attribution(project, tmp_path): + repo, _, _ = project + add_files(repo, 2) + + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 0 + + bodies = commit_bodies(repo, 2) + assert all(body.endswith(f"\n\n{ATTRIBUTION}") for body in bodies) + assert all(body.count(ATTRIBUTION) == 1 for body in bodies) + + +def test_no_attribution_flag_leaves_messages_untouched(project, tmp_path): + repo, _, _ = project + add_files(repo, 2) + + code = run_cli(repo, tmp_path, "--force", "--limit-mib", "1", "--no-attribution") + + assert code == 0 + assert commit_bodies(repo, 2) == ["Data #2", "Data #1"] + + +def test_ignore_attribution_alias_and_dry_run_report(project, tmp_path): + repo, _, _ = project + add_files(repo, 1) + plain = tmp_path / "plain.json" + full = tmp_path / "full.json" + + run_cli(repo, tmp_path, "--dry-run", "--ignore-attribution", "--report", str(plain)) + run_cli(repo, tmp_path, "--dry-run", "--report", str(full)) + + plain_msg = json.loads(plain.read_text(encoding="utf-8"))["batches"][0]["message"] + full_msg = json.loads(full.read_text(encoding="utf-8"))["batches"][0]["message"] + assert plain_msg == "Data #1" + assert full_msg == f"Data #1\n\n{ATTRIBUTION}" + + +def test_resumed_commit_keeps_the_attribution(project, tmp_path): + """Commits made by an earlier run keep their attribution when pushed later.""" + repo, _, _ = project + add_files(repo, 2) + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1", "--no-push") == 0 + assert run_cli(repo, tmp_path, "--force") == 0 + assert all(ATTRIBUTION in body for body in commit_bodies(repo, 2)) + + +def interrupt_second_push(monkeypatch): + """Make Ctrl+C hit while the second batch is being pushed.""" + from commitrocket.core.runner import helpers as runner + + real = runner.push_target + calls = [] + + def push(*args, **kwargs): + calls.append(1) + if len(calls) == 2: + raise KeyboardInterrupt + return real(*args, **kwargs) + + monkeypatch.setattr(runner, "push_target", push) + return lambda: monkeypatch.setattr(runner, "push_target", real) + + +def resume_cli(repo, tmp_path, *extra): + return main(["--repo", str(repo), "--log-file", str(tmp_path / "run.log"), *extra]) + + +def test_resume_continues_with_the_stored_parameters(project, tmp_path, monkeypatch): + from commitrocket.git.journal import Journal + + repo, remote, branch = project + add_files(repo, 4) + restore = interrupt_second_push(monkeypatch) + + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 130 + journal = Journal(repo) + assert journal.path.exists() + assert journal.state()["params"]["limit_mib"] == 1 + assert journal.state()["status"] == "interrupted" + restore() + + # No parameters needed: they come from the journal. + assert resume_cli(repo, tmp_path, "--resume", "--force") == 0 + + assert not journal.path.exists() + bodies = commit_bodies(repo, 4) + assert bodies[0].startswith("Data #4") + assert [b.split("\n")[0] for b in reversed(bodies)] == [ + "Data #1", + "Data #2", + "Data #3", + "Data #4", + ] + local = run_git(repo, "rev-parse", "HEAD").stdout.strip() + assert run_git(remote, "rev-parse", f"refs/heads/{branch}").stdout.strip() == local + + +def test_resume_accepts_identical_parameters(project, tmp_path, monkeypatch): + repo, _, _ = project + add_files(repo, 3) + restore = interrupt_second_push(monkeypatch) + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 130 + restore() + + code = resume_cli( + repo, tmp_path, "--resume", "--force", "--message", "Data", "--limit-mib", "1" + ) + + assert code == 0 + + +def test_resume_rejects_different_parameters(project, tmp_path, monkeypatch, capsys): + from commitrocket.git.journal import Journal + + repo, _, _ = project + add_files(repo, 3) + interrupt_second_push(monkeypatch) + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 130 + + with pytest.raises(SystemExit) as exc: + resume_cli(repo, tmp_path, "--resume", "--force", "--limit-mib", "5") + + assert exc.value.code == 2 + assert "--limit-mib" in capsys.readouterr().err + assert Journal(repo).path.exists() + + +def test_resume_without_a_journal_is_a_clear_error(project, tmp_path, capsys): + repo, _, _ = project + + with pytest.raises(SystemExit) as exc: + resume_cli(repo, tmp_path, "--resume") + + assert exc.value.code == 2 + assert "no interrupted run" in capsys.readouterr().err + + +def test_resume_refuses_a_repository_that_changed(project, tmp_path, monkeypatch): + repo, _, _ = project + add_files(repo, 3) + interrupt_second_push(monkeypatch) + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 130 + run_git(repo, "reset", "--hard", "HEAD~1") # drops a recorded commit + + assert resume_cli(repo, tmp_path, "--resume", "--force") == 1 + + +def test_plain_rerun_with_other_parameters_starts_a_new_run( + project, tmp_path, monkeypatch +): + from commitrocket.git.journal import Journal + + repo, _, _ = project + add_files(repo, 3) + restore = interrupt_second_push(monkeypatch) + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 130 + restore() + + code = main( + [ + "--repo", + str(repo), + "--message", + "Other", + "--limit-mib", + "1", + "--force", + "--log-file", + str(tmp_path / "run.log"), + ] + ) + + assert code == 0 + assert not Journal(repo).path.exists() + assert commit_bodies(repo, 1)[0].startswith("Other #1") + + +def test_plain_rerun_with_the_same_parameters_continues(project, tmp_path, monkeypatch): + repo, _, _ = project + add_files(repo, 3) + restore = interrupt_second_push(monkeypatch) + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 130 + restore() + + assert run_cli(repo, tmp_path, "--force", "--limit-mib", "1") == 0 + + assert commit_bodies(repo, 1)[0].startswith("Data #3") + + +def test_dry_run_leaves_no_journal(project, tmp_path): + from commitrocket.git.journal import Journal + + repo, _, _ = project + add_files(repo, 2) + + assert run_cli(repo, tmp_path, "--dry-run", "--limit-mib", "1") == 0 + + assert not Journal(repo).path.exists() diff --git a/tests/test_cli.py b/tests/test_cli.py deleted file mode 100644 index 78db7d2..0000000 --- a/tests/test_cli.py +++ /dev/null @@ -1,38 +0,0 @@ -import pytest - -from commitrocket.cli import main -from commitrocket.options import RunOptions -from commitrocket.runner import own_output_files - - -def test_own_output_files_are_found_only_inside_the_repo(tmp_path): - repo = tmp_path / "repo" - repo.mkdir() - options = RunOptions( - log_file=str(repo / "logs" / "run.log"), - report=str(tmp_path / "elsewhere" / "report.json"), - ) - assert own_output_files(repo.resolve(), options) == {"logs/run.log"} - - options = RunOptions(report=str(repo / "report.json")) - assert own_output_files(repo.resolve(), options) == {"report.json"} - assert own_output_files(repo.resolve(), RunOptions()) == set() - - -@pytest.mark.parametrize( - "argv", - [ - ["--message", "m", "--no-push", "--use-lfs"], - ["--message", "m", "--message-template", "{nope}"], - ["--message", "m", "--lfs-threshold-mib", "150"], - ["--message", "m", "--retries", "-1"], - ["--message", "m", "--remote", "--receive-pack=x"], - ["--message", "m", "--remote", "origin", "--branch", "-d"], - [], - ], -) -def test_invalid_combinations_exit_with_usage_error(argv, tmp_path, capsys): - with pytest.raises(SystemExit) as exit_info: - main(["--repo", str(tmp_path), *argv]) - assert exit_info.value.code == 2 - assert "error" in capsys.readouterr().err diff --git a/tests/test_journal.py b/tests/test_journal.py deleted file mode 100644 index 5566466..0000000 --- a/tests/test_journal.py +++ /dev/null @@ -1,17 +0,0 @@ -from commitrocket.journal import Journal - - -def test_journal_round_trip(git_repo): - journal = Journal(git_repo) - assert journal.read() is None - - journal.write(["a.txt", "b c.txt"], "Videos #22", 22) - assert journal.read() == { - "files": ["a.txt", "b c.txt"], - "message": "Videos #22", - "number": 22, - } - - journal.clear() - assert journal.read() is None - journal.clear() # clearing twice is fine diff --git a/tests/test_push_parsing.py b/tests/test_push_parsing.py deleted file mode 100644 index 9ef6ced..0000000 --- a/tests/test_push_parsing.py +++ /dev/null @@ -1,31 +0,0 @@ -import pytest - -from commitrocket.push import parse_lfs_bytes, parse_progress_line - - -@pytest.mark.parametrize( - ("line", "expected"), - [ - ("Uploading LFS objects: 50% (1/2), 52 MB | 3.2 MB/s", 52_000_000), - ("Uploading LFS objects: 100% (1/1), 1.5 GB | 12 MB/s", 1_500_000_000), - ("Uploading LFS objects: 0% (0/1), 0 B | 0 B/s", 0), - ("Writing objects: 100% (6/6), 235.76 MiB | 846.00 KiB/s, done.", None), - ], -) -def test_parse_lfs_bytes(line, expected): - assert parse_lfs_bytes(line) == expected - - -@pytest.mark.parametrize( - ("line", "expected"), - [ - ("Enumerating objects: 5, done.", ("Enumerating objects", None)), - ("Counting objects: 40% (2/5)", ("Counting objects", 40)), - ("Compressing objects: 100% (3/3)", ("Compressing objects", 100)), - ("Writing objects: 50% (1/2)", ("Uploading objects", 50)), - ("Resolving deltas: 100% (1/1)", ("Resolving deltas", 100)), - ("To github.com:user/repo.git", ("Git push", None)), - ], -) -def test_parse_progress_line(line, expected): - assert parse_progress_line(line) == expected diff --git a/tests/test_retries.py b/tests/test_retries.py deleted file mode 100644 index b6dfd54..0000000 --- a/tests/test_retries.py +++ /dev/null @@ -1,70 +0,0 @@ -import pytest -from rich.console import Console - -from commitrocket import push -from commitrocket.errors import PushError - - -@pytest.mark.parametrize( - "output", - [ - "remote: error: GH001: Large files detected.", - "! [remote rejected] main -> main (pre-receive hook declined)", - "! [rejected] main -> main (fetch first)", - "fatal: Authentication failed for 'https://example.com/r.git'", - ], -) -def test_rejections_are_not_retryable(output): - assert push.is_retryable(output) is False - - -@pytest.mark.parametrize( - "output", - [ - "error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500", - "fatal: the remote end hung up unexpectedly", - "LFS: Put https://example.com/object: connection reset by peer", - ], -) -def test_transient_failures_are_retryable(output): - assert push.is_retryable(output) is True - - -def fake_push(failures): - calls = [] - - def _push(*args, **kwargs): - calls.append(1) - if len(calls) <= len(failures): - raise failures[len(calls) - 1] - - return _push, calls - - -def run_retries(monkeypatch, failures, retries): - fake, calls = fake_push(failures) - monkeypatch.setattr(push, "push_with_progress", fake) - waits = [] - push.push_with_retries( - ".", None, None, Console(quiet=True), retries=retries, sleep=waits.append - ) - return calls, waits - - -def test_retries_transient_failures_with_backoff(monkeypatch): - failures = [PushError("RPC failed"), PushError("RPC failed")] - calls, waits = run_retries(monkeypatch, failures, retries=3) - assert len(calls) == 3 - assert waits == [5, 15] - - -def test_gives_up_after_retries(monkeypatch): - failures = [PushError("RPC failed")] * 3 - with pytest.raises(PushError): - run_retries(monkeypatch, failures, retries=2) - - -def test_does_not_retry_rejections(monkeypatch): - failures = [PushError("rejected", retryable=False)] - with pytest.raises(PushError): - run_retries(monkeypatch, failures, retries=3) diff --git a/tests/unit/cli/test_doctor.py b/tests/unit/cli/test_doctor.py new file mode 100644 index 0000000..603c8d5 --- /dev/null +++ b/tests/unit/cli/test_doctor.py @@ -0,0 +1,43 @@ +import pytest + +from commitrocket.cli.doctor import doctor_main + + +@pytest.fixture +def doctor(monkeypatch): + seen = {} + + def fake_run_doctor(console, repo, **kwargs): + seen["repo"] = repo + seen.update(kwargs) + return 3 + + monkeypatch.setattr("commitrocket.support.doctor.run_doctor", fake_run_doctor) + monkeypatch.setattr("commitrocket.io.logs.setup_logging", lambda *a: None) + return seen + + +def test_arguments_are_passed_to_the_checks(doctor): + code = doctor_main( + ["--repo", "r", "--remote", "origin", "--branch", "main", "--offline"] + ) + assert code == 3 + assert doctor == { + "repo": "r", + "remote": "origin", + "branch": "main", + "offline": True, + "config_path": None, + } + + +def test_defaults(doctor): + doctor_main([]) + assert doctor["repo"] == "." + assert doctor["offline"] is False + + +def test_unknown_option_is_a_usage_error(doctor): + with pytest.raises(SystemExit) as exit_info: + doctor_main(["--nope"]) + assert exit_info.value.code == 2 diff --git a/tests/unit/cli/test_entry.py b/tests/unit/cli/test_entry.py new file mode 100644 index 0000000..5ae34b7 --- /dev/null +++ b/tests/unit/cli/test_entry.py @@ -0,0 +1,38 @@ +from commitrocket.cli import main + + +def test_doctor_goes_to_the_doctor_command(monkeypatch): + seen = {} + + def fake_doctor(argv): + seen["argv"] = argv + return 4 + + monkeypatch.setattr("commitrocket.cli.doctor.doctor_main", fake_doctor) + assert main(["doctor", "--offline"]) == 4 + assert seen["argv"] == ["--offline"] + + +def test_anything_else_is_a_run(monkeypatch): + seen = {} + + def fake_run_main(argv): + seen["argv"] = argv + return 0 + + monkeypatch.setattr("commitrocket.cli.execute.run_main", fake_run_main) + assert main(["--message", "m"]) == 0 + assert seen["argv"] == ["--message", "m"] + + +def test_arguments_default_to_the_command_line(monkeypatch): + seen = {} + + def fake_run_main(argv): + seen["argv"] = argv + return 0 + + monkeypatch.setattr("commitrocket.cli.execute.run_main", fake_run_main) + monkeypatch.setattr("sys.argv", ["commitrocket", "--dry-run"]) + main() + assert seen["argv"] == ["--dry-run"] diff --git a/tests/unit/cli/test_execute.py b/tests/unit/cli/test_execute.py new file mode 100644 index 0000000..c02e495 --- /dev/null +++ b/tests/unit/cli/test_execute.py @@ -0,0 +1,85 @@ +import pytest + +from commitrocket.cli import main + + +def base_argv(tmp_path, *extra): + return [ + "--repo", + str(tmp_path), + "--message", + "m", + "--log-file", + str(tmp_path / "l"), + *extra, + ] + + +def captured_options(monkeypatch, argv, code=0): + seen = {} + + def fake_run(console, options, report): + seen["options"] = options + return code + + monkeypatch.setattr("commitrocket.core.runner.run", fake_run) + seen["code"] = main(argv) + return seen + + +def test_attribution_is_on_by_default(monkeypatch, tmp_path): + seen = captured_options(monkeypatch, base_argv(tmp_path)) + assert seen["options"].attribution is True + + +@pytest.mark.parametrize("flag", ["--no-attribution", "--ignore-attribution"]) +def test_attribution_flag_turns_it_off(flag, monkeypatch, tmp_path): + seen = captured_options(monkeypatch, base_argv(tmp_path, flag)) + assert seen["options"].attribution is False + + +def test_attribution_can_be_turned_off_in_the_config_file(monkeypatch, tmp_path): + (tmp_path / "commitrocket.toml").write_text("no-attribution = true\n") + seen = captured_options(monkeypatch, base_argv(tmp_path)) + assert seen["options"].attribution is False + + +def test_the_exit_code_of_the_run_is_returned(monkeypatch, tmp_path): + seen = captured_options(monkeypatch, base_argv(tmp_path), code=2) + assert seen["code"] == 2 + + +def test_run_parameters_are_handed_to_the_run(monkeypatch, tmp_path): + seen = captured_options(monkeypatch, base_argv(tmp_path, "--limit-mib", "5")) + options = seen["options"] + assert options.resume is False + assert options.max_mib == 15 + assert options.params["message"] == "m" + assert options.params["limit_mib"] == 5 + assert "repo" not in options.params + + +def test_command_line_overrides_the_config_file(monkeypatch, tmp_path): + (tmp_path / "commitrocket.toml").write_text("limit-mib = 9\n") + seen = captured_options(monkeypatch, base_argv(tmp_path, "--limit-mib", "4")) + assert seen["options"].limit_mib == 4 + + +def test_report_is_written_when_requested(monkeypatch, tmp_path): + report = tmp_path / "report.json" + captured_options(monkeypatch, base_argv(tmp_path, "--report", str(report))) + assert report.is_file() + + +def test_resume_without_an_interrupted_run_is_a_usage_error(git_repo, capsys): + with pytest.raises(SystemExit) as exit_info: + main(["--repo", str(git_repo), "--resume"]) + assert exit_info.value.code == 2 + assert "no interrupted run" in capsys.readouterr().err + + +def test_missing_message_is_a_usage_error(tmp_path, capsys): + with pytest.raises(SystemExit) as exit_info: + main(["--repo", str(tmp_path)]) + assert exit_info.value.code == 2 + assert "error" in capsys.readouterr().err diff --git a/tests/unit/cli/test_parser.py b/tests/unit/cli/test_parser.py new file mode 100644 index 0000000..dc1b2ca --- /dev/null +++ b/tests/unit/cli/test_parser.py @@ -0,0 +1,63 @@ +import pytest + +from commitrocket.cli import main +from commitrocket.cli.parser import DEFAULT_LIMIT_MIB, DEFAULT_RETRIES, build_parser + + +def test_defaults(): + args = build_parser().parse_args([]) + assert args.message is None + assert args.repo == "." + assert args.limit_mib == DEFAULT_LIMIT_MIB + assert args.retries == DEFAULT_RETRIES + assert args.resume is False + assert args.no_attribution is False + assert args.no_push is False + assert args.dry_run is False + + +def test_resume_flag(): + assert build_parser().parse_args(["--resume"]).resume is True + + +@pytest.mark.parametrize("flag", ["--no-attribution", "--ignore-attribution"]) +def test_attribution_flag_has_an_alias(flag): + assert build_parser().parse_args([flag]).no_attribution is True + + +def test_include_and_exclude_can_be_repeated(): + args = build_parser().parse_args( + ["--include", "a/*", "--include", "b/*", "--exclude", "*.log"] + ) + assert args.include == ["a/*", "b/*"] + assert args.exclude == ["*.log"] + + +def test_unknown_batch_type_is_rejected(capsys): + with pytest.raises(SystemExit) as exit_info: + build_parser().parse_args(["--batch-type", "nope"]) + assert exit_info.value.code == 2 + assert "invalid choice" in capsys.readouterr().err + + +def test_option_without_its_value_is_rejected(capsys): + with pytest.raises(SystemExit): + build_parser().parse_args(["--limit-mib"]) + assert "expected one argument" in capsys.readouterr().err + + +def test_version_is_printed(capsys): + from commitrocket import __version__ + + with pytest.raises(SystemExit) as exit_info: + main(["--version"]) + assert exit_info.value.code == 0 + assert __version__ in capsys.readouterr().out + + +def test_help_lists_the_resume_and_attribution_flags(capsys): + with pytest.raises(SystemExit): + main(["--help"]) + out = capsys.readouterr().out + assert "--resume" in out + assert "--no-attribution" in out diff --git a/tests/unit/cli/test_resume.py b/tests/unit/cli/test_resume.py new file mode 100644 index 0000000..db9c3b2 --- /dev/null +++ b/tests/unit/cli/test_resume.py @@ -0,0 +1,86 @@ +import pytest + +from commitrocket.cli.parser import build_parser +from commitrocket.cli.resume import ( + NOT_RUN_PARAMS, + apply_resume, + explicit_arguments, + run_params, +) +from commitrocket.git.journal import Journal + + +def stored_run(repo, *argv): + """Write a journal for a run started with argv.""" + parser = build_parser() + params = run_params(parser, parser.parse_args(list(argv))) + Journal(repo).start(params, "main", "origin/main", "abc123") + return params + + +def resume_args(repo, *extra): + parser = build_parser() + argv = ["--repo", str(repo), "--resume", *extra] + return parser, argv, parser.parse_args(argv) + + +def test_run_params_leave_out_settings_that_are_not_part_of_the_run(): + parser = build_parser() + params = run_params(parser, parser.parse_args(["--message", "m"])) + assert params["message"] == "m" + assert params["limit_mib"] == 100 + assert not NOT_RUN_PARAMS & params.keys() + + +def test_explicit_arguments_only_hold_what_was_given(): + given = explicit_arguments(["--message", "m", "--no-push"]) + assert given == {"message": "m", "no_push": True} + + +def test_apply_resume_without_a_journal_is_a_usage_error(git_repo, capsys): + parser, argv, args = resume_args(git_repo) + with pytest.raises(SystemExit) as exit_info: + apply_resume(parser, argv, args, str(git_repo)) + assert exit_info.value.code == 2 + assert "no interrupted run" in capsys.readouterr().err + + +def test_apply_resume_restores_the_stored_parameters(git_repo): + stored_run(git_repo, "--message", "stored", "--limit-mib", "7", "--no-push") + parser, argv, args = resume_args(git_repo) + + apply_resume(parser, argv, args, str(git_repo)) + + assert args.message == "stored" + assert args.limit_mib == 7 + assert args.no_push is True + + +def test_apply_resume_accepts_identical_parameters(git_repo): + stored_run(git_repo, "--message", "stored") + parser, argv, args = resume_args(git_repo, "--message", "stored") + + apply_resume(parser, argv, args, str(git_repo)) + + assert args.message == "stored" + + +def test_apply_resume_rejects_different_parameters(git_repo, capsys): + stored_run(git_repo, "--message", "stored", "--limit-mib", "7") + parser, argv, args = resume_args(git_repo, "--message", "other") + with pytest.raises(SystemExit) as exit_info: + apply_resume(parser, argv, args, str(git_repo)) + assert exit_info.value.code == 2 + message = capsys.readouterr().err.splitlines()[-2:] + assert "differ from it: --message." in " ".join(message) + + +def test_apply_resume_reports_an_incompatible_journal(git_repo, capsys): + Journal(git_repo).path.write_text( + '{"event": "run", "version": 999}\n', encoding="utf-8" + ) + parser, argv, args = resume_args(git_repo) + with pytest.raises(SystemExit) as exit_info: + apply_resume(parser, argv, args, str(git_repo)) + assert exit_info.value.code == 2 + assert "incompatible" in capsys.readouterr().err diff --git a/tests/unit/cli/test_validate.py b/tests/unit/cli/test_validate.py new file mode 100644 index 0000000..2e37e82 --- /dev/null +++ b/tests/unit/cli/test_validate.py @@ -0,0 +1,50 @@ +import pytest + +from commitrocket.cli.parser import build_parser +from commitrocket.cli.validate import validate + + +def check(*argv): + parser = build_parser() + return validate(parser, parser.parse_args(list(argv))) + + +@pytest.mark.parametrize( + "argv", + [ + ["--message", "m", "--no-push", "--use-lfs"], + ["--message", "m", "--message-template", "{nope}"], + ["--message", "m", "--lfs-threshold-mib", "150"], + ["--message", "m", "--lfs-threshold-mib", "-1"], + ["--message", "m", "--retries", "-1"], + ["--message", "m", "--limit-mib", "0"], + ["--message", "m", "--number", "-1"], + ["--message", "m", "--compression-threads", "-1"], + ["--message", "m", "--lfs-threads", "0"], + ["--message", "m", "--post-buffer-mib", "0"], + ["--message", "m", "--lfs-batch-mib", "0"], + ["--message", "m", "--remote", "--receive-pack=x"], + ["--message", "m", "--remote", "origin", "--branch", "-d"], + ["--message", "m", "--notify-webhook", "ftp://example.com"], + ["--message", "m", "--limit-mib", "50", "--max-mib", "10"], + ["--message", " "], + [], + ], +) +def test_invalid_combinations_exit_with_usage_error(argv, capsys): + with pytest.raises(SystemExit) as exit_info: + check(*argv) + assert exit_info.value.code == 2 + assert "error" in capsys.readouterr().err + + +def test_max_mib_defaults_to_three_times_the_limit(): + assert check("--message", "m", "--limit-mib", "40") == 120 + + +def test_explicit_max_mib_is_kept(): + assert check("--message", "m", "--limit-mib", "40", "--max-mib", "60") == 60 + + +def test_max_mib_equal_to_the_limit_is_allowed(): + assert check("--message", "m", "--limit-mib", "40", "--max-mib", "40") == 40 diff --git a/tests/unit/core/runner/test_batches.py b/tests/unit/core/runner/test_batches.py new file mode 100644 index 0000000..ee7db20 --- /dev/null +++ b/tests/unit/core/runner/test_batches.py @@ -0,0 +1,183 @@ +import subprocess + +import pytest +from rich.console import Console + +from commitrocket.core.options import RunOptions +from commitrocket.core.runner.batches import process_batches +from commitrocket.git.git import PushTarget, get_pending_files +from commitrocket.git.journal import Journal +from commitrocket.io.report import RunReport +from commitrocket.support.errors import CommitRocketError + + +class FakeProgress: + def __init__(self): + self.updates = [] + + def update(self, task, **fields): + self.updates.append(fields) + + +def git(repo, *args): + return subprocess.run( + ["git", "-C", str(repo), *args], check=True, capture_output=True, text=True + ).stdout.strip() + + +def add_files(repo, count, size=1000): + for number in range(count): + (repo / f"f{number}.txt").write_bytes(bytes([65 + number]) * size) + + +@pytest.fixture +def pushes(monkeypatch): + calls = [] + monkeypatch.setattr( + "commitrocket.core.runner.helpers.push_target", + lambda *args, **kwargs: calls.append(kwargs), + ) + return calls + + +def run_batches(repo, *, limit=1500, maximum=5000, journal=None, **kwargs): + options = RunOptions( + message="m", attribution=False, no_push=kwargs.pop("no_push", True) + ) + report = RunReport(options) + progress = FakeProgress() + count = process_batches( + Console(quiet=True), + repo, + progress, + "task", + "push", + options, + PushTarget("origin", "main", []), + kwargs.pop("number", 1), + limit, + maximum, + lambda: get_pending_files(repo), + journal=journal, + report=report, + **kwargs, + ) + return count, report, progress + + +def subjects(repo): + return git(repo, "log", "--format=%s", "--reverse").splitlines() + + +def test_files_are_committed_in_numbered_batches(git_repo): + add_files(git_repo, 3) + + count, report, _ = run_batches(git_repo) + + assert count == 3 + assert subjects(git_repo) == ["m #1", "m #2", "m #3"] + assert [batch["message"] for batch in report.batches] == ["m #1", "m #2", "m #3"] + assert get_pending_files(git_repo) == [] + + +def test_numbering_starts_from_the_given_number(git_repo): + add_files(git_repo, 2) + + run_batches(git_repo, number=7) + + assert subjects(git_repo) == ["m #7", "m #8"] + + +def test_files_that_fit_together_share_a_batch(git_repo): + add_files(git_repo, 3, size=100) + + count, _, _ = run_batches(git_repo, limit=10_000) + + assert count == 1 + assert git(git_repo, "rev-list", "--count", "HEAD") == "1" + + +def test_oversized_files_are_left_uncommitted(git_repo): + add_files(git_repo, 1, size=9000) + + count, _, _ = run_batches(git_repo, limit=1500, maximum=5000) + + assert count == 0 + assert get_pending_files(git_repo) == ["f0.txt"] + + +def test_nothing_pending_means_no_batches(git_repo): + count, _, _ = run_batches(git_repo) + assert count == 0 + + +def test_the_journal_follows_each_commit(git_repo): + add_files(git_repo, 2) + journal = Journal(git_repo) + journal.start({}, "main", "origin/main", "abc") + + run_batches(git_repo, journal=journal) + + state = journal.state() + assert [number for number, _ in state["commits"]] == [1, 2] + assert state["commits"][-1][1] == git(git_repo, "rev-parse", "HEAD") + assert state["inflight"] is None + assert state["pushed"] is None + + +def test_each_batch_is_pushed_and_verified(git_repo, pushes): + add_files(git_repo, 2) + journal = Journal(git_repo) + journal.start({}, "main", "origin/main", "abc") + verified = [] + + _, report, _ = run_batches( + git_repo, journal=journal, no_push=False, verify=lambda: verified.append(1) + ) + + assert len(pushes) == 2 + assert verified == [1, 1] + assert journal.state()["pushed"] == git(git_repo, "rev-parse", "HEAD") + assert all(batch["pushed"] and batch["verified"] for batch in report.batches) + + +def test_no_push_does_not_push(git_repo, pushes): + add_files(git_repo, 1) + + _, report, _ = run_batches(git_repo, no_push=True) + + assert pushes == [] + assert not report.batches[0].get("pushed") + + +def test_lfs_check_runs_before_pushing(git_repo, pushes): + add_files(git_repo, 1) + seen = [] + + def check_lfs(selected): + seen.append((list(selected), len(pushes))) + + run_batches(git_repo, no_push=False, check_lfs=check_lfs) + + assert seen == [(["f0.txt"], 0)] + + +def test_a_failed_lfs_check_stops_before_pushing(git_repo, pushes): + add_files(git_repo, 1) + + def check_lfs(selected): + raise CommitRocketError("not pointers") + + with pytest.raises(CommitRocketError, match="not pointers"): + run_batches(git_repo, no_push=False, check_lfs=check_lfs) + + assert pushes == [] + + +def test_progress_is_measured_in_bytes(git_repo): + add_files(git_repo, 2, size=1000) + + _, _, progress = run_batches(git_repo) + + assert progress.updates[0] == {"total": 2000, "completed": 0} + assert progress.updates[-1]["completed"] == 2000 diff --git a/tests/unit/core/runner/test_dry_run.py b/tests/unit/core/runner/test_dry_run.py new file mode 100644 index 0000000..fd153a0 --- /dev/null +++ b/tests/unit/core/runner/test_dry_run.py @@ -0,0 +1,89 @@ +from rich.console import Console + +from commitrocket.core.options import RunOptions +from commitrocket.core.runner.dry_run import run_dry +from commitrocket.io.report import DRY_RUN, RunReport + +MIB = 1024 * 1024 + + +def plan(repo, files, *, limit, maximum, start_number=5, **option_values): + options = RunOptions( + message="m", attribution=False, limit_mib=1, max_mib=3, **option_values + ) + report = RunReport(options) + console = Console(record=True, width=120) + code = run_dry( + console, + options, + report, + repo, + files, + [], + "", + limit, + maximum, + limit, + start_number, + ) + return code, report, console.export_text() + + +def write(repo, name, size): + (repo / name).write_bytes(b"x" * size) + return name + + +def test_dry_run_records_the_planned_batches(git_repo): + files = [write(git_repo, "a.txt", 600), write(git_repo, "b.txt", 600)] + + code, report, text = plan(git_repo, files, limit=1000, maximum=5000) + + assert code == 0 + assert report.status == DRY_RUN + assert len(report.batches) == 2 + assert report.total_files == 2 + assert "m #5" in text + assert "m #6" in text + assert "Dry run only" in text + + +def test_dry_run_numbers_batches_from_the_start_number(git_repo): + files = [write(git_repo, "a.txt", 10)] + + _, report, _ = plan(git_repo, files, limit=1000, maximum=5000, start_number=42) + + assert report.batches[0]["message"] == "m #42" + + +def test_dry_run_reports_files_over_the_maximum_as_deferred(git_repo): + files = [write(git_repo, "small.txt", 10), write(git_repo, "huge.bin", 9000)] + + _, report, text = plan(git_repo, files, limit=1000, maximum=5000) + + assert [item["path"] for item in report.deferred] == ["huge.bin"] + assert "Would be deferred" in text + + +def test_dry_run_does_not_touch_the_repository(git_repo): + import subprocess + + files = [write(git_repo, "a.txt", 10)] + + plan(git_repo, files, limit=1000, maximum=5000) + + staged = subprocess.run( + ["git", "-C", str(git_repo), "diff", "--cached", "--name-only"], + check=True, + capture_output=True, + text=True, + ).stdout + assert staged == "" + + +def test_dry_run_mentions_no_push(git_repo): + files = [write(git_repo, "a.txt", 10)] + + _, _, text = plan(git_repo, files, limit=1000, maximum=5000, no_push=True) + + assert "--no-push" in text diff --git a/tests/unit/core/runner/test_flow.py b/tests/unit/core/runner/test_flow.py new file mode 100644 index 0000000..3f6cd43 --- /dev/null +++ b/tests/unit/core/runner/test_flow.py @@ -0,0 +1,257 @@ +import subprocess + +import pytest +from rich.console import Console + +from commitrocket.core.options import RunOptions +from commitrocket.core.runner import run +from commitrocket.git.journal import Journal +from commitrocket.io.report import ( + ABORTED, + CANCELLED, + DRY_RUN, + FAILED, + INTERRUPTED, + SUCCESS, + RunReport, +) +from commitrocket.support.errors import CommitRocketError + + +def git(repo, *args): + return subprocess.run( + ["git", "-C", str(repo), *args], check=True, capture_output=True, text=True + ).stdout.strip() + + +@pytest.fixture +def repo(git_repo, tmp_path): + """A repository on main with an upstream, ready for new files.""" + remote = tmp_path / "remote.git" + subprocess.run(["git", "init", "-q", "--bare", str(remote)], check=True) + (git_repo / "base.txt").write_text("base") + git(git_repo, "add", "base.txt") + git(git_repo, "commit", "-q", "-m", "base") + git(git_repo, "branch", "-M", "main") + git(git_repo, "remote", "add", "origin", str(remote)) + git(git_repo, "push", "-q", "-u", "origin", "main") + return git_repo + + +def options_for(repo, **values): + values = { + "message": "m", + "attribution": False, + "force": True, + "no_push": True, + **values, + } + return RunOptions(repo=str(repo), **values) + + +def start(repo, **values): + options = options_for(repo, **values) + report = RunReport(options) + console = Console(record=True, width=120) + code = run(console, options, report) + return code, report, console.export_text() + + +def add_files(repo, count): + for number in range(count): + (repo / f"new{number}.txt").write_text(f"data {number}") + + +def commit_count(repo): + return int(git(repo, "rev-list", "--count", "HEAD")) + + +def test_a_missing_repository_is_an_abort(tmp_path): + code, report, text = start(tmp_path / "missing") + assert code == 2 + assert report.status == ABORTED + assert "not found" in text + + +def test_a_detached_head_is_an_abort(repo): + git(repo, "checkout", "-q", "--detach") + + code, report, text = start(repo) + + assert code == 1 + assert report.status == ABORTED + assert "Detached HEAD" in text + + +def test_a_branch_without_an_upstream_is_an_abort(repo): + git(repo, "checkout", "-q", "-b", "local-only") + + code, report, text = start(repo) + + assert code == 1 + assert report.status == ABORTED + assert "No upstream" in text + + +def test_pending_files_are_committed_in_batches(repo): + add_files(repo, 2) + + code, report, _ = start(repo, limit_mib=1) + + assert code == 0 + assert report.status == SUCCESS + assert report.total_files == 2 + assert git(repo, "log", "-1", "--format=%s") == "m #1" + assert not Journal(repo).path.exists() + + +def test_the_run_pushes_unless_told_not_to(repo): + add_files(repo, 1) + + code, _, _ = start(repo, no_push=False) + + assert code == 0 + assert git(repo, "rev-parse", "origin/main") == git(repo, "rev-parse", "HEAD") + + +def test_a_dry_run_changes_nothing(repo): + add_files(repo, 2) + before = commit_count(repo) + + code, report, text = start(repo, dry_run=True) + + assert code == 0 + assert report.status == DRY_RUN + assert commit_count(repo) == before + assert "Dry run only" in text + assert not Journal(repo).path.exists() + + +def test_declining_the_confirmation_cancels_the_run(repo, monkeypatch): + add_files(repo, 1) + options = options_for(repo, force=False) + report = RunReport(options) + console = Console(quiet=True) + monkeypatch.setattr(console, "input", lambda *args, **kwargs: "n") + before = commit_count(repo) + + code = run(console, options, report) + + assert code == 1 + assert report.status == CANCELLED + assert commit_count(repo) == before + + +def test_confirming_lets_the_run_proceed(repo, monkeypatch): + add_files(repo, 1) + options = options_for(repo, force=False) + console = Console(quiet=True) + monkeypatch.setattr(console, "input", lambda *args, **kwargs: "y") + + assert run(console, options, RunReport(options)) == 0 + + +def test_files_the_run_writes_itself_are_not_committed(repo): + add_files(repo, 1) + + code, _, _ = start(repo, log_file=str(repo / "run.log")) + + assert code == 0 + assert "run.log" not in git(repo, "ls-files") + + +def test_a_failure_is_reported_and_journaled(repo, monkeypatch): + add_files(repo, 1) + + def fail(*args, **kwargs): + raise CommitRocketError("boom") + + monkeypatch.setattr("commitrocket.core.runner.batches.process_batches", fail) + + code, report, text = start(repo, params={"message": "m"}) + + assert code == 1 + assert report.status == FAILED + assert report.error == "boom" + assert "Run the same command again" in text + state = Journal(repo).state() + assert state["status"] == "failed" + assert state["params"] == {"message": "m"} + + +def test_an_interruption_is_reported_and_journaled(repo, monkeypatch): + add_files(repo, 1) + + def interrupt(*args, **kwargs): + raise KeyboardInterrupt + + monkeypatch.setattr("commitrocket.core.runner.batches.process_batches", interrupt) + + code, report, text = start(repo) + + assert code == 130 + assert report.status == INTERRUPTED + assert "Interrupted by user" in text + assert Journal(repo).state()["status"] == "interrupted" + + +def test_running_again_with_the_same_parameters_continues_the_run(repo, monkeypatch): + add_files(repo, 2) + real = __import__( + "commitrocket.core.runner.batches", fromlist=["process_batches"] + ).process_batches + calls = [] + + def fail_once(*args, **kwargs): + calls.append(1) + if len(calls) == 1: + raise CommitRocketError("boom") + return real(*args, **kwargs) + + monkeypatch.setattr("commitrocket.core.runner.batches.process_batches", fail_once) + + assert start(repo, params={"message": "m"})[0] == 1 + code, report, _ = start(repo, params={"message": "m"}) + + assert code == 0 + assert report.status == SUCCESS + assert not Journal(repo).path.exists() + + +def test_running_again_with_other_parameters_starts_a_new_run(repo, monkeypatch): + add_files(repo, 1) + + def fail(*args, **kwargs): + raise CommitRocketError("boom") + + monkeypatch.setattr("commitrocket.core.runner.batches.process_batches", fail) + start(repo, params={"message": "old"}) + monkeypatch.undo() + + code, _, text = start(repo, params={"message": "new"}) + + assert code == 0 + assert "starting a new run" in text + + +def test_resume_without_an_interrupted_run_is_an_abort(repo): + add_files(repo, 1) + + code, report, text = start(repo, resume=True) + + assert code == 1 + assert report.status == ABORTED + assert "no interrupted run" in text + + +def test_files_over_the_host_limit_need_lfs(repo): + big = repo / "big.bin" + with open(big, "wb") as handle: + handle.truncate(101 * 1024 * 1024) + + code, report, text = start(repo, max_mib=500) + + assert code == 2 + assert report.status == ABORTED + assert "--use-lfs" in text + assert git(repo, "status", "--porcelain").startswith("??") diff --git a/tests/unit/core/runner/test_helpers.py b/tests/unit/core/runner/test_helpers.py new file mode 100644 index 0000000..2fe443c --- /dev/null +++ b/tests/unit/core/runner/test_helpers.py @@ -0,0 +1,16 @@ +from commitrocket.core.options import RunOptions +from commitrocket.core.runner import own_output_files + + +def test_own_output_files_are_found_only_inside_the_repo(tmp_path): + repo = tmp_path / "repo" + repo.mkdir() + options = RunOptions( + log_file=str(repo / "logs" / "run.log"), + report=str(tmp_path / "elsewhere" / "report.json"), + ) + assert own_output_files(repo.resolve(), options) == {"logs/run.log"} + + options = RunOptions(report=str(repo / "report.json")) + assert own_output_files(repo.resolve(), options) == {"report.json"} + assert own_output_files(repo.resolve(), RunOptions()) == set() diff --git a/tests/unit/core/runner/test_resume.py b/tests/unit/core/runner/test_resume.py new file mode 100644 index 0000000..f458b19 --- /dev/null +++ b/tests/unit/core/runner/test_resume.py @@ -0,0 +1,312 @@ +import subprocess + +import pytest +from rich.console import Console + +from commitrocket.core.options import RunOptions +from commitrocket.core.runner import resume +from commitrocket.git.git import PushTarget +from commitrocket.git.journal import Journal +from commitrocket.io.report import RunReport +from commitrocket.support.errors import CommitRocketError + + +def git(repo, *args): + return subprocess.run( + ["git", "-C", str(repo), *args], check=True, capture_output=True, text=True + ).stdout.strip() + + +@pytest.fixture +def repo(git_repo): + (git_repo / "first.txt").write_text("first") + git(git_repo, "add", "first.txt") + git(git_repo, "commit", "-q", "-m", "first") + return git_repo + + +def prior_run(repo, **changes): + head = git(repo, "rev-parse", "HEAD") + prior = { + "params": {}, + "branch": "main", + "target": "origin/main", + "head": head, + "commits": [], + } + return {**prior, **changes} + + +# -- check_resume ----------------------------------------------------------- + + +def test_check_resume_needs_an_interrupted_run(repo): + with pytest.raises(CommitRocketError, match="no interrupted run"): + resume.check_resume(repo, None, RunOptions(), "main", "origin/main") + + +def test_check_resume_rejects_different_parameters(repo): + options = RunOptions(params={"message": "other"}) + with pytest.raises(CommitRocketError, match="parameters differ"): + resume.check_resume(repo, prior_run(repo), options, "main", "origin/main") + + +def test_check_resume_rejects_another_branch_or_target(repo): + with pytest.raises(CommitRocketError, match="interrupted run was on"): + resume.check_resume(repo, prior_run(repo), RunOptions(), "dev", "origin/main") + with pytest.raises(CommitRocketError, match="interrupted run was on"): + resume.check_resume(repo, prior_run(repo), RunOptions(), "main", "origin/dev") + + +def test_check_resume_rejects_a_changed_history(repo): + prior = prior_run(repo, head="0" * 40) + with pytest.raises(CommitRocketError, match="repository changed"): + resume.check_resume(repo, prior, RunOptions(), "main", "origin/main") + + +def test_check_resume_follows_the_last_recorded_commit(repo): + head = git(repo, "rev-parse", "HEAD") + prior = prior_run(repo, head="0" * 40, commits=[(1, head)]) + resume.check_resume(repo, prior, RunOptions(), "main", "origin/main") + + +def test_check_resume_accepts_a_matching_run(repo): + resume.check_resume(repo, prior_run(repo), RunOptions(), "main", "origin/main") + + +# -- read_resume_state ------------------------------------------------------ + + +def read_state(repo, options=None): + console = Console(record=True, width=120) + state = resume.read_resume_state( + console, repo, options or RunOptions(), "main", "origin/main" + ) + return state, console.export_text() + + +def test_no_journal_means_a_fresh_run(repo): + (_, prior, same_run, entry, staged), _ = read_state(repo) + assert prior is None + assert same_run is False + assert entry is None + assert staged == [] + + +def test_a_journal_with_the_same_parameters_continues_the_run(repo): + Journal(repo).start({"message": "m"}, "main", "origin/main", "abc") + + (_, prior, same_run, _, _), text = read_state( + repo, RunOptions(params={"message": "m"}) + ) + + assert prior is not None + assert same_run is True + assert "starting a new run" not in text + + +def test_a_journal_with_other_parameters_starts_a_new_run(repo): + Journal(repo).start({"message": "old"}, "main", "origin/main", "abc") + + (_, prior, same_run, entry, _), text = read_state( + repo, RunOptions(params={"message": "new"}) + ) + + assert prior is not None + assert same_run is False + assert entry is None + assert "starting a new run" in text + + +def test_an_incompatible_journal_is_ignored_without_resume(repo): + Journal(repo).path.write_text('{"event": "run", "version": 999}\n') + + (_, prior, same_run, _, _), _ = read_state(repo) + + assert prior is None + assert same_run is False + + +def test_an_incompatible_journal_stops_a_resume(repo): + Journal(repo).path.write_text('{"event": "run", "version": 999}\n') + + with pytest.raises(CommitRocketError, match="incompatible"): + read_state(repo, RunOptions(resume=True)) + + +def test_files_staged_by_the_interrupted_run_are_picked_up(repo): + journal = Journal(repo) + journal.start({}, "main", "origin/main", "abc") + (repo / "a.txt").write_text("a") + journal.write(["a.txt"], "m #2", 2) + git(repo, "add", "a.txt") + + (_, _, _, entry, staged), _ = read_state(repo) + + assert staged == ["a.txt"] + assert entry["message"] == "m #2" + + +def test_files_staged_by_someone_else_stop_the_run(repo): + (repo / "mine.txt").write_text("x") + git(repo, "add", "mine.txt") + + with pytest.raises(CommitRocketError, match="already staged"): + read_state(repo) + + +# -- resume_previous -------------------------------------------------------- + + +@pytest.fixture +def pushes(monkeypatch): + calls = [] + monkeypatch.setattr( + "commitrocket.core.runner.helpers.push_target", + lambda *args, **kwargs: calls.append(args), + ) + monkeypatch.setattr( + "commitrocket.git.git.find_large_unpushed_blobs", lambda *args: [] + ) + return calls + + +def staged_by_interrupted_run(repo): + journal = Journal(repo) + journal.start({}, "main", "origin/main", "abc") + (repo / "a.txt").write_text("a") + journal.write(["a.txt"], "m #4", 4) + git(repo, "add", "a.txt") + return journal, journal.read() + + +def call_resume_previous(repo, journal, entry, staged, unpushed, verify, **options): + resume.resume_previous( + Console(quiet=True), + repo, + None, + None, + RunOptions(**options), + PushTarget("origin", "main", []), + journal, + entry, + staged, + unpushed, + verify, + ) + + +def test_resume_previous_commits_and_pushes_the_staged_batch(repo, pushes): + journal, entry = staged_by_interrupted_run(repo) + verified = [] + + call_resume_previous( + repo, journal, entry, ["a.txt"], [], lambda: verified.append(1) + ) + + assert git(repo, "log", "-1", "--format=%s") == "m #4" + state = journal.state() + assert state["commits"] == [(4, git(repo, "rev-parse", "HEAD"))] + assert state["pushed"] == git(repo, "rev-parse", "HEAD") + assert len(pushes) == 1 + assert verified == [1] + + +def test_resume_previous_does_not_push_with_no_push(repo, pushes): + journal, entry = staged_by_interrupted_run(repo) + + call_resume_previous( + repo, journal, entry, ["a.txt"], [], lambda: None, no_push=True + ) + + assert git(repo, "log", "-1", "--format=%s") == "m #4" + assert pushes == [] + assert journal.state()["pushed"] is None + + +def test_resume_previous_pushes_unpushed_commits_only(repo, pushes): + journal = Journal(repo) + journal.start({}, "main", "origin/main", "abc") + verified = [] + + call_resume_previous(repo, journal, None, [], ["abc"], lambda: verified.append(1)) + + assert len(pushes) == 1 + assert verified == [1] + assert git(repo, "rev-list", "--count", "HEAD") == "1" + + +def test_resume_previous_does_nothing_when_there_is_nothing_to_resume(repo, pushes): + journal = Journal(repo) + journal.start({}, "main", "origin/main", "abc") + + call_resume_previous(repo, journal, None, [], [], lambda: None) + + assert pushes == [] + + +def test_resume_previous_refuses_a_commit_with_oversized_files( + repo, pushes, monkeypatch +): + journal, entry = staged_by_interrupted_run(repo) + monkeypatch.setattr( + "commitrocket.git.git.find_large_unpushed_blobs", + lambda *args: [("a.txt", 1)], + ) + + with pytest.raises(CommitRocketError, match="over 100 MiB"): + call_resume_previous(repo, journal, entry, ["a.txt"], [], lambda: None) + + assert pushes == [] + + +# -- commit_lfs_rules ------------------------------------------------------- + + +class FakeLfs: + def __init__(self, changed): + self.changed = changed + + def write_committed_rules(self, paths): + if self.changed: + (self.repo / ".gitattributes").write_text("*.bin filter=lfs\n") + return self.changed + + +def run_commit_lfs_rules(repo, changed, **options): + lfs = FakeLfs(changed) + lfs.repo = repo + options = RunOptions(message="m", attribution=False, **options) + report = RunReport(options) + verified = [] + resume.commit_lfs_rules( + Console(quiet=True), + repo, + None, + None, + options, + PushTarget("origin", "main", []), + lfs, + ["a.bin"], + report, + lambda: verified.append(1), + ) + return report, verified + + +def test_commit_lfs_rules_commits_and_pushes_the_rules(repo, pushes): + report, verified = run_commit_lfs_rules(repo, True) + + assert git(repo, "log", "-1", "--format=%s") == "m (LFS rules)" + assert report.lfs["rules_commit"] == git(repo, "rev-parse", "HEAD") + assert len(pushes) == 1 + assert verified == [1] + + +def test_commit_lfs_rules_does_nothing_when_the_rules_are_unchanged(repo, pushes): + report, verified = run_commit_lfs_rules(repo, False) + + assert git(repo, "rev-list", "--count", "HEAD") == "1" + assert report.lfs["rules_commit"] is None + assert pushes == [] + assert verified == [] diff --git a/tests/unit/core/runner/test_setup.py b/tests/unit/core/runner/test_setup.py new file mode 100644 index 0000000..c4e7db5 --- /dev/null +++ b/tests/unit/core/runner/test_setup.py @@ -0,0 +1,204 @@ +import subprocess + +from rich.console import Console + +from commitrocket.core.batching import MIB +from commitrocket.core.options import RunOptions +from commitrocket.core.runner import setup +from commitrocket.git.git import LocalConfig, PushTarget +from commitrocket.io.report import RunReport + + +def local_config(repo, key): + result = subprocess.run( + ["git", "-C", str(repo), "config", "--local", "--get", key], + capture_output=True, + text=True, + ) + return result.stdout.strip() if result.returncode == 0 else None + + +def plan(repo, files, **option_values): + option_values.setdefault("lfs_threshold_mib", 1) + options = RunOptions(use_lfs=True, **option_values) + report = RunReport(options) + paths, scope = setup.plan_lfs(options, report, repo, files, 50 * MIB) + return paths, scope, report + + +def test_plan_lfs_does_nothing_without_use_lfs(git_repo): + options = RunOptions() + report = RunReport(options) + assert setup.plan_lfs(options, report, git_repo, ["a"], MIB) == ([], "") + + +def test_plan_lfs_picks_files_above_the_threshold(git_repo): + (git_repo / "big.bin").write_bytes(b"x" * (2 * MIB)) + (git_repo / "small.txt").write_text("x") + + paths, scope, report = plan(git_repo, ["big.bin", "small.txt"]) + + assert paths == ["big.bin"] + assert report.lfs["files"] == 1 + assert "1 file(s) above 1 MiB" in scope + assert ".gitattributes" in scope + + +def test_plan_lfs_without_committed_rules_says_so(git_repo): + (git_repo / "big.bin").write_bytes(b"x" * (2 * MIB)) + + _, scope, _ = plan(git_repo, ["big.bin"], lfs_commit_rules=False) + + assert "this run only" in scope + assert "LFS pointer files" in scope + + +def test_plan_lfs_threshold_zero_means_every_file(git_repo): + (git_repo / "a.txt").write_text("x") + + paths, scope, _ = plan(git_repo, ["a.txt"], lfs_threshold_mib=0) + + assert paths == ["a.txt"] + assert scope.startswith("All 1 file(s)") + + +def test_plan_lfs_reports_when_no_file_needs_it(git_repo): + (git_repo / "small.txt").write_text("x") + + paths, scope, report = plan(git_repo, ["small.txt"]) + + assert paths == [] + assert report.lfs["files"] == 0 + assert "LFS not needed" in scope + + +def test_apply_local_config_sets_and_restores_thread_options(git_repo): + options = RunOptions(compression_threads=2, lfs_threads=3) + config = LocalConfig(git_repo) + + setup.apply_local_config( + Console(quiet=True), options, git_repo, PushTarget("origin", "main", []), config + ) + + assert local_config(git_repo, "pack.threads") == "2" + assert local_config(git_repo, "lfs.concurrenttransfers") == "3" + config.restore() + assert local_config(git_repo, "pack.threads") is None + assert local_config(git_repo, "lfs.concurrenttransfers") is None + + +def test_apply_local_config_sets_the_post_buffer_for_http_remotes(git_repo): + subprocess.run( + ["git", "-C", str(git_repo), "remote", "add", "origin", "https://x.test/r.git"], + check=True, + ) + config = LocalConfig(git_repo) + + setup.apply_local_config( + Console(quiet=True), + RunOptions(post_buffer_mib=5), + git_repo, + PushTarget("origin", "main", []), + config, + ) + + assert local_config(git_repo, "http.postBuffer") == str(5 * MIB) + + +def test_apply_local_config_ignores_the_post_buffer_for_other_remotes(git_repo): + subprocess.run( + ["git", "-C", str(git_repo), "remote", "add", "origin", "/some/where.git"], + check=True, + ) + console = Console(record=True, width=120) + + setup.apply_local_config( + console, + RunOptions(post_buffer_mib=5), + git_repo, + PushTarget("origin", "main", []), + LocalConfig(git_repo), + ) + + assert local_config(git_repo, "http.postBuffer") is None + assert "ignored" in console.export_text() + + +class FakeLfs: + def __init__(self): + self.calls = [] + + def enable(self, paths, all_files=False): + self.calls.append(("enable", paths, all_files)) + + def install_hooks(self): + self.calls.append(("install_hooks",)) + + def close(self, uninstall_hooks=True): + self.calls.append(("close", uninstall_hooks)) + + +def test_configure_lfs_enables_lfs_for_the_run(): + lfs = FakeLfs() + setup.configure_lfs(lfs, RunOptions(lfs_commit_rules=False), ["a"]) + assert lfs.calls == [("enable", ["a"], False)] + + +def test_configure_lfs_covers_every_file_with_threshold_zero(): + lfs = FakeLfs() + options = RunOptions(lfs_commit_rules=False, lfs_threshold_mib=0) + setup.configure_lfs(lfs, options, ["a"]) + assert lfs.calls == [("enable", ["a"], True)] + + +def test_configure_lfs_only_installs_hooks_when_rules_are_committed(): + lfs = FakeLfs() + setup.configure_lfs(lfs, RunOptions(lfs_commit_rules=True), ["a"]) + assert lfs.calls == [("install_hooks",)] + + +def test_configure_lfs_installs_hooks_when_there_are_no_lfs_files(): + lfs = FakeLfs() + setup.configure_lfs(lfs, RunOptions(lfs_commit_rules=False), []) + assert lfs.calls == [("install_hooks",)] + + +def release(monkeypatch, completed, pointers): + def has_pointers(repo, revs): + if isinstance(pointers, Exception): + raise pointers + return pointers + + monkeypatch.setattr( + "commitrocket.core.verify.unpushed_has_lfs_pointers", has_pointers + ) + lfs = FakeLfs() + console = Console(record=True, width=120) + setup.release_lfs( + console, ".", PushTarget("origin", "main", []), lfs, completed=completed + ) + return lfs, console.export_text() + + +def test_release_lfs_removes_hooks_after_a_completed_run(monkeypatch): + lfs, text = release(monkeypatch, completed=True, pointers=True) + assert lfs.calls == [("close", True)] + assert "left installed" not in text + + +def test_release_lfs_keeps_hooks_while_unpushed_lfs_commits_remain(monkeypatch): + lfs, text = release(monkeypatch, completed=False, pointers=True) + assert lfs.calls == [("close", False)] + assert "left installed" in text + + +def test_release_lfs_removes_hooks_after_a_stopped_run_with_nothing_unpushed( + monkeypatch, +): + lfs, _ = release(monkeypatch, completed=False, pointers=False) + assert lfs.calls == [("close", True)] + + +def test_release_lfs_keeps_hooks_when_unpushed_commits_cannot_be_checked(monkeypatch): + lfs, _ = release(monkeypatch, completed=False, pointers=OSError("boom")) + assert lfs.calls == [("close", False)] diff --git a/tests/test_batching.py b/tests/unit/core/test_batching.py similarity index 98% rename from tests/test_batching.py rename to tests/unit/core/test_batching.py index f4317df..260ec46 100644 --- a/tests/test_batching.py +++ b/tests/unit/core/test_batching.py @@ -1,4 +1,4 @@ -from commitrocket.batching import ( +from commitrocket.core.batching import ( MIB, estimate_batch_count, plan_batches, diff --git a/tests/test_eta.py b/tests/unit/core/test_eta.py similarity index 93% rename from tests/test_eta.py rename to tests/unit/core/test_eta.py index bfff491..3506cdd 100644 --- a/tests/test_eta.py +++ b/tests/unit/core/test_eta.py @@ -1,4 +1,4 @@ -from commitrocket.eta import EtaEstimator, format_duration +from commitrocket.core.eta import EtaEstimator, format_duration class FakeClock: diff --git a/tests/test_filters.py b/tests/unit/core/test_filters.py similarity index 92% rename from tests/test_filters.py rename to tests/unit/core/test_filters.py index d4a98b7..0c04fb1 100644 --- a/tests/test_filters.py +++ b/tests/unit/core/test_filters.py @@ -1,7 +1,7 @@ import pytest -from commitrocket.errors import CommitRocketError -from commitrocket.filters import FileFilter, read_patterns +from commitrocket.core.filters import FileFilter, read_patterns +from commitrocket.support.errors import CommitRocketError FILES = ["a.mp4", "notes.txt", "raw/b.mp4", "raw/c.zip", "docs/readme.md"] diff --git a/tests/test_template.py b/tests/unit/core/test_template.py similarity index 51% rename from tests/test_template.py rename to tests/unit/core/test_template.py index e0a713b..7b071bb 100644 --- a/tests/test_template.py +++ b/tests/unit/core/test_template.py @@ -1,6 +1,12 @@ import pytest -from commitrocket.template import DEFAULT_TEMPLATE, render_message, validate_template +from commitrocket.core.template import ( + ATTRIBUTION, + DEFAULT_TEMPLATE, + add_attribution, + render_message, + validate_template, +) def render(template, **overrides): @@ -37,3 +43,25 @@ def test_invalid_templates_are_rejected(template): def test_valid_and_empty_templates(): assert validate_template(DEFAULT_TEMPLATE) is None assert validate_template(" ") is not None + + +def test_attribution_is_appended_after_a_blank_line(): + assert add_attribution("Videos #1") == f"Videos #1\n\n{ATTRIBUTION}" + + +def test_attribution_keeps_multiline_bodies_and_trims_trailing_space(): + assert add_attribution("Title\n\nBody\n\n") == f"Title\n\nBody\n\n{ATTRIBUTION}" + + +def test_attribution_is_never_added_twice(): + once = add_attribution("Videos #1") + assert add_attribution(once) == once + + +def test_attribution_can_be_switched_off(): + assert add_attribution("Videos #1", enabled=False) == "Videos #1" + + +def test_attribution_names_commitrocket_and_links_to_the_repo(): + assert ATTRIBUTION.startswith("Prepared and Committed By: 🚀 CommitRocket (") + assert "https://github.com/coldsofttech/CommitRocket" in ATTRIBUTION diff --git a/tests/test_verify.py b/tests/unit/core/test_verify.py similarity index 94% rename from tests/test_verify.py rename to tests/unit/core/test_verify.py index 222b223..da51f9d 100644 --- a/tests/test_verify.py +++ b/tests/unit/core/test_verify.py @@ -2,14 +2,14 @@ import pytest -from commitrocket.errors import CommitRocketError -from commitrocket.git import run_git -from commitrocket.verify import ( +from commitrocket.core.verify import ( expected_lfs_paths, find_non_pointers, unpushed_has_lfs_pointers, verify_remote_head, ) +from commitrocket.git.git import run_git +from commitrocket.support.errors import CommitRocketError POINTER = ( "version https://git-lfs.github.com/spec/v1\n" diff --git a/tests/test_git.py b/tests/unit/git/test_git.py similarity index 97% rename from tests/test_git.py rename to tests/unit/git/test_git.py index b09ff40..474832f 100644 --- a/tests/test_git.py +++ b/tests/unit/git/test_git.py @@ -1,7 +1,6 @@ import pytest -from commitrocket.errors import CommitRocketError, GitError -from commitrocket.git import ( +from commitrocket.git.git import ( LocalConfig, add_files, chunk_paths, @@ -10,6 +9,7 @@ resolve_target, run_git, ) +from commitrocket.support.errors import CommitRocketError, GitError def test_pending_includes_untracked_and_modified(git_repo): diff --git a/tests/unit/git/test_journal.py b/tests/unit/git/test_journal.py new file mode 100644 index 0000000..f3b097c --- /dev/null +++ b/tests/unit/git/test_journal.py @@ -0,0 +1,102 @@ +import pytest + +from commitrocket.git.journal import JOURNAL_VERSION, Journal, JournalError + + +def start(journal, **params): + journal.start(params or {"message": "m"}, "main", "origin/main", "abc123") + + +def test_no_journal_means_no_state(git_repo): + journal = Journal(git_repo) + assert journal.state() is None + assert journal.read() is None + + +def test_journal_lives_in_git_as_jsonl(git_repo): + journal = Journal(git_repo) + start(journal) + assert journal.path.name == "commitrocket-journal.jsonl" + assert ".git" in journal.path.parts + assert journal.path.read_text(encoding="utf-8").count("\n") == 1 + + +def test_in_flight_batch_round_trip(git_repo): + journal = Journal(git_repo) + start(journal) + journal.write(["a.txt", "b c.txt"], "Videos #22", 22) + assert journal.read() == { + "files": ["a.txt", "b c.txt"], + "message": "Videos #22", + "number": 22, + } + + journal.committed(22, "deadbeef") + assert journal.read() is None + + +def test_state_replays_progress(git_repo): + journal = Journal(git_repo) + start(journal, message="Videos", number=1) + journal.write(["a"], "Videos #1", 1) + journal.committed(1, "sha1") + journal.pushed("sha1") + journal.write(["b"], "Videos #2", 2) + journal.committed(2, "sha2") + journal.note("interrupted") + + state = journal.state() + assert state["params"] == {"message": "Videos", "number": 1} + assert state["branch"] == "main" + assert state["target"] == "origin/main" + assert state["head"] == "abc123" + assert state["commits"] == [(1, "sha1"), (2, "sha2")] + assert state["pushed"] == "sha1" + assert state["next_number"] == 3 + assert state["status"] == "interrupted" + assert state["inflight"] is None + + +def test_a_line_cut_short_by_a_crash_is_ignored(git_repo): + journal = Journal(git_repo) + start(journal) + journal.committed(1, "sha1") + with open(journal.path, "a", encoding="utf-8") as handle: + handle.write('{"event": "committed", "num') + + state = journal.state() + assert state["commits"] == [(1, "sha1")] + + +def test_incompatible_version_is_reported(git_repo): + journal = Journal(git_repo) + start(journal) + text = journal.path.read_text(encoding="utf-8") + journal.path.write_text( + text.replace(f'"version": {JOURNAL_VERSION}', '"version": 999'), + encoding="utf-8", + ) + with pytest.raises(JournalError): + journal.state() + assert journal.read() is None + + +def test_start_replaces_an_earlier_journal_and_the_legacy_file(git_repo): + journal = Journal(git_repo) + start(journal, message="old") + journal.committed(1, "sha1") + journal._legacy.write_text("{}", encoding="utf-8") + + start(journal, message="new") + + assert journal.state()["params"] == {"message": "new"} + assert journal.state()["commits"] == [] + assert not journal._legacy.exists() + + +def test_delete_removes_the_journal(git_repo): + journal = Journal(git_repo) + start(journal) + journal.delete() + assert journal.state() is None + journal.delete() # deleting twice is fine diff --git a/tests/test_lfs.py b/tests/unit/git/test_lfs.py similarity index 94% rename from tests/test_lfs.py rename to tests/unit/git/test_lfs.py index dc5f699..9b1b5bd 100644 --- a/tests/test_lfs.py +++ b/tests/unit/git/test_lfs.py @@ -1,15 +1,15 @@ import pytest -from commitrocket.batching import MIB -from commitrocket.errors import CommitRocketError -from commitrocket.git import run_git -from commitrocket.lfs import ( +from commitrocket.core.batching import MIB +from commitrocket.git.git import run_git +from commitrocket.git.lfs import ( LfsSession, all_files_rules, attribute_line, committed_rule_lines, find_lfs_candidates, ) +from commitrocket.support.errors import CommitRocketError def test_attribute_line_quotes_spaces_and_escapes_globs(): diff --git a/tests/unit/git/test_push.py b/tests/unit/git/test_push.py new file mode 100644 index 0000000..1749d3e --- /dev/null +++ b/tests/unit/git/test_push.py @@ -0,0 +1,181 @@ +import subprocess + +import pytest +from rich.console import Console + +from commitrocket.git import push +from commitrocket.git.push import parse_lfs_bytes, parse_progress_line +from commitrocket.support.errors import PushError + + +@pytest.mark.parametrize( + "output", + [ + "remote: error: GH001: Large files detected.", + "! [remote rejected] main -> main (pre-receive hook declined)", + "! [rejected] main -> main (fetch first)", + "fatal: Authentication failed for 'https://example.com/r.git'", + ], +) +def test_rejections_are_not_retryable(output): + assert push.is_retryable(output) is False + + +@pytest.mark.parametrize( + "output", + [ + "error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500", + "fatal: the remote end hung up unexpectedly", + "LFS: Put https://example.com/object: connection reset by peer", + ], +) +def test_transient_failures_are_retryable(output): + assert push.is_retryable(output) is True + + +def fake_push(failures): + calls = [] + + def _push(*args, **kwargs): + calls.append(1) + if len(calls) <= len(failures): + raise failures[len(calls) - 1] + + return _push, calls + + +def run_retries(monkeypatch, failures, retries): + fake, calls = fake_push(failures) + monkeypatch.setattr(push, "push_with_progress", fake) + waits = [] + push.push_with_retries( + ".", None, None, Console(quiet=True), retries=retries, sleep=waits.append + ) + return calls, waits + + +def test_retries_transient_failures_with_backoff(monkeypatch): + failures = [PushError("RPC failed"), PushError("RPC failed")] + calls, waits = run_retries(monkeypatch, failures, retries=3) + assert len(calls) == 3 + assert waits == [5, 15] + + +def test_gives_up_after_retries(monkeypatch): + failures = [PushError("RPC failed")] * 3 + with pytest.raises(PushError): + run_retries(monkeypatch, failures, retries=2) + + +def test_does_not_retry_rejections(monkeypatch): + failures = [PushError("rejected", retryable=False)] + with pytest.raises(PushError): + run_retries(monkeypatch, failures, retries=3) + + +@pytest.mark.parametrize( + ("line", "expected"), + [ + ("Uploading LFS objects: 50% (1/2), 52 MB | 3.2 MB/s", 52_000_000), + ("Uploading LFS objects: 100% (1/1), 1.5 GB | 12 MB/s", 1_500_000_000), + ("Uploading LFS objects: 0% (0/1), 0 B | 0 B/s", 0), + ("Writing objects: 100% (6/6), 235.76 MiB | 846.00 KiB/s, done.", None), + ], +) +def test_parse_lfs_bytes(line, expected): + assert parse_lfs_bytes(line) == expected + + +@pytest.mark.parametrize( + ("line", "expected"), + [ + ("Enumerating objects: 5, done.", ("Enumerating objects", None)), + ("Counting objects: 40% (2/5)", ("Counting objects", 40)), + ("Compressing objects: 100% (3/3)", ("Compressing objects", 100)), + ("Writing objects: 50% (1/2)", ("Uploading objects", 50)), + ("Resolving deltas: 100% (1/1)", ("Resolving deltas", 100)), + ("To github.com:user/repo.git", ("Git push", None)), + ], +) +def test_parse_progress_line(line, expected): + assert parse_progress_line(line) == expected + + +class FakeProgress: + def __init__(self): + self.updates = [] + + def update(self, task, **fields): + self.updates.append(fields) + + +def git(repo, *args): + subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True) + + +@pytest.fixture +def pushable(git_repo, tmp_path): + """A repository with one commit and an empty bare repository as origin.""" + remote = tmp_path / "remote.git" + subprocess.run(["git", "init", "-q", "--bare", str(remote)], check=True) + (git_repo / "a.txt").write_text("a", encoding="utf-8") + git(git_repo, "add", "a.txt") + git(git_repo, "commit", "-q", "-m", "first") + git(git_repo, "remote", "add", "origin", str(remote)) + return git_repo, remote + + +def test_push_with_progress_pushes_and_reports_progress(pushable): + repo, remote = pushable + progress = FakeProgress() + uploads = [] + + push.push_with_progress( + repo, + progress, + "task", + Console(quiet=True), + on_upload=uploads.append, + remote="origin", + refspec="HEAD:refs/heads/main", + ) + + head = subprocess.run( + ["git", "-C", str(repo), "rev-parse", "HEAD"], + check=True, + capture_output=True, + text=True, + ).stdout.strip() + pushed = subprocess.run( + ["git", "-C", str(remote), "rev-parse", "refs/heads/main"], + check=True, + capture_output=True, + text=True, + ).stdout.strip() + assert pushed == head + assert progress.updates[-1] == {"visible": False} + assert { + "description": "Git push complete", + "completed": 100, + "total": 100, + "visible": True, + } in progress.updates + assert uploads == sorted(uploads) + + +def test_push_with_progress_raises_when_git_push_fails(pushable): + repo, _ = pushable + progress = FakeProgress() + + with pytest.raises(PushError) as exc_info: + push.push_with_progress( + repo, + progress, + "task", + Console(quiet=True), + remote="missing", + refspec="HEAD:refs/heads/main", + ) + + assert "git push failed" in str(exc_info.value) + assert any(u.get("description") == "Git push failed" for u in progress.updates) diff --git a/tests/test_logs.py b/tests/unit/io/test_logs.py similarity index 85% rename from tests/test_logs.py rename to tests/unit/io/test_logs.py index 552948e..382fb9c 100644 --- a/tests/test_logs.py +++ b/tests/unit/io/test_logs.py @@ -1,23 +1,24 @@ import logging +import sys from pathlib import Path -from commitrocket import logs +from commitrocket.io import logs def test_default_dir_windows(monkeypatch, tmp_path): - monkeypatch.setattr(logs.sys, "platform", "win32") + monkeypatch.setattr(sys, "platform", "win32") monkeypatch.setenv("LOCALAPPDATA", str(tmp_path)) assert logs.default_log_dir() == tmp_path / "CommitRocket" / "Logs" def test_default_dir_macos(monkeypatch): - monkeypatch.setattr(logs.sys, "platform", "darwin") + monkeypatch.setattr(sys, "platform", "darwin") expected = Path.home() / "Library" / "Logs" / "CommitRocket" assert logs.default_log_dir() == expected def test_default_dir_linux_uses_xdg_state(monkeypatch, tmp_path): - monkeypatch.setattr(logs.sys, "platform", "linux") + monkeypatch.setattr(sys, "platform", "linux") monkeypatch.setenv("XDG_STATE_HOME", str(tmp_path)) assert logs.default_log_dir() == tmp_path / "commitrocket" diff --git a/tests/test_notify.py b/tests/unit/io/test_notify.py similarity index 89% rename from tests/test_notify.py rename to tests/unit/io/test_notify.py index b130581..48a40fc 100644 --- a/tests/test_notify.py +++ b/tests/unit/io/test_notify.py @@ -1,13 +1,15 @@ import json +import shutil +import sys import threading from http.server import BaseHTTPRequestHandler, HTTPServer import pytest from rich.console import Console -from commitrocket import notify -from commitrocket.options import RunOptions -from commitrocket.report import FAILED, SUCCESS, RunReport +from commitrocket.core.options import RunOptions +from commitrocket.io import notify +from commitrocket.io.report import FAILED, SUCCESS, RunReport def make_report(status=SUCCESS, error=None, **settings): @@ -55,8 +57,8 @@ def test_webhook_url_validation(url, valid): def test_desktop_falls_back_to_the_bell(monkeypatch, capsys): - monkeypatch.setattr(notify.sys, "platform", "linux") - monkeypatch.setattr(notify.shutil, "which", lambda name: None) + monkeypatch.setattr(sys, "platform", "linux") + monkeypatch.setattr(shutil, "which", lambda name: None) assert notify.notify_desktop("t", "b") == "bell" assert "\a" in capsys.readouterr().out @@ -64,8 +66,8 @@ def test_desktop_falls_back_to_the_bell(monkeypatch, capsys): def test_desktop_uses_notify_send_on_linux(monkeypatch): calls = [] - monkeypatch.setattr(notify.sys, "platform", "linux") - monkeypatch.setattr(notify.shutil, "which", lambda name: "/usr/bin/" + name) + monkeypatch.setattr(sys, "platform", "linux") + monkeypatch.setattr(shutil, "which", lambda name: "/usr/bin/" + name) def fake_run(command, env): calls.append((command, env)) diff --git a/tests/test_report.py b/tests/unit/io/test_report.py similarity index 94% rename from tests/test_report.py rename to tests/unit/io/test_report.py index 3e34aa7..459c887 100644 --- a/tests/test_report.py +++ b/tests/unit/io/test_report.py @@ -1,7 +1,7 @@ import json -from commitrocket.options import RunOptions -from commitrocket.report import DEFERRED, SUCCESS, RunReport +from commitrocket.core.options import RunOptions +from commitrocket.io.report import DEFERRED, SUCCESS, RunReport def make_report(**settings): diff --git a/tests/unit/io/test_ui.py b/tests/unit/io/test_ui.py new file mode 100644 index 0000000..9568077 --- /dev/null +++ b/tests/unit/io/test_ui.py @@ -0,0 +1,145 @@ +from rich.console import Console + +from commitrocket.io import ui + + +def recording_console(): + return Console(record=True, width=120) + + +def output(console): + return console.export_text() + + +class FakeEstimator: + def __init__(self, remaining): + self.remaining = remaining + + def estimate(self, completed, total): + return self.remaining + + +def eta_text(estimator): + progress = ui.make_progress(recording_console()) + task_id = progress.add_task("work", total=10, estimator=estimator) + return progress.columns[-1].render(progress.tasks[task_id]).plain + + +def test_eta_column_is_empty_without_an_estimator(): + progress = ui.make_progress(recording_console()) + task_id = progress.add_task("work", total=10) + assert progress.columns[-1].render(progress.tasks[task_id]).plain == "" + + +def test_eta_column_shows_when_the_estimate_is_not_ready(): + assert "estimating" in eta_text(FakeEstimator(None)) + + +def test_eta_column_shows_the_remaining_time(): + assert eta_text(FakeEstimator(90)).startswith("ETA ") + + +def test_print_run_info(): + console = recording_console() + ui.print_run_info(console, "/repo", "main", "origin/main", 100, 300, 7) + text = output(console) + for expected in ("/repo", "main", "origin/main", "100 MiB", "300 MiB", "7"): + assert expected in text + + +def test_print_lfs_required_lists_the_files(tmp_path): + (tmp_path / "big.bin").write_bytes(b"x" * 1024) + console = recording_console() + ui.print_lfs_required(console, tmp_path, ["big.bin"], 100) + text = output(console) + assert "big.bin" in text + assert "--use-lfs" in text + assert "Nothing was committed" in text + + +def test_print_resume_describes_staged_files_and_unpushed_commits(): + console = recording_console() + ui.print_resume(console, ["a", "b"], {"message": "Batch #3"}, ["c1", "c2"]) + text = output(console) + assert "2 file(s) were staged" in text + assert "Batch #3" in text + assert "2 unpushed commit(s)" in text + + +def test_print_resume_truncates_a_long_commit_list(): + console = recording_console() + ui.print_resume(console, [], None, [f"c{n}" for n in range(15)]) + text = output(console) + assert "and 5 more" in text + assert "c9" in text + assert "c10" not in text + + +def test_print_dry_run(): + console = recording_console() + mib = 1024 * 1024 + ui.print_dry_run( + console, + batches=[(["a", "b"], 2 * mib), (["c"], mib)], + deferred=[("huge.bin", 500 * mib)], + messages=["m #1", "m #2"], + lfs_files={"c"}, + lfs_scope="Via LFS: 1 file", + no_push=True, + ) + text = output(console) + assert "m #1" in text + assert "m #2" in text + assert "2 batch(es), 3 file(s), 3.00 MiB in total." in text + assert "Via LFS: 1 file" in text + assert "huge.bin" in text + assert "--no-push" in text + assert "Dry run only" in text + + +def test_print_dry_run_without_extras_omits_their_sections(): + console = recording_console() + ui.print_dry_run(console, [(["a"], 1)], [], ["m #1"], set(), None) + text = output(console) + assert "Would be deferred" not in text + assert "--no-push" not in text + + +def test_print_stuck_commits_shows_how_to_drop_them(): + console = recording_console() + ui.print_stuck_commits( + console, + ["abc first", "def second"], + [("big.bin", 150 * 1024 * 1024)], + "origin/main", + 100, + ) + text = output(console) + assert "big.bin" in text + assert "2 unpushed local commit(s)" in text + assert "git reset --mixed origin/main" in text + + +def test_final_summary_with_nothing_deferred(tmp_path): + (tmp_path / "small.txt").write_text("x") + console = recording_console() + code = ui.print_final_summary( + console, tmp_path, 3, 0, 1, pending_files=lambda: ["small.txt"] + ) + text = output(console) + assert code == 0 + assert "Batches pushed" in text + assert "All eligible files processed." in text + + +def test_final_summary_reports_deferred_files(tmp_path): + (tmp_path / "huge.bin").write_bytes(b"x" * (2 * 1024 * 1024)) + console = recording_console() + code = ui.print_final_summary( + console, tmp_path, 1, 0, 1, pending_files=lambda: ["huge.bin"], pushed=False + ) + text = output(console) + assert code == 2 + assert "Batches committed" in text + assert "huge.bin" in text + assert "Exceeds --max-mib (1 MiB)" in text diff --git a/tests/test_config.py b/tests/unit/support/test_config.py similarity index 97% rename from tests/test_config.py rename to tests/unit/support/test_config.py index 90e434e..001af9a 100644 --- a/tests/test_config.py +++ b/tests/unit/support/test_config.py @@ -1,7 +1,7 @@ import pytest from commitrocket.cli import build_parser -from commitrocket.config import ConfigError, apply_config, find_config +from commitrocket.support.config import ConfigError, apply_config, find_config def parse(tmp_path, toml, argv=(), name="commitrocket.toml"): diff --git a/tests/test_doctor.py b/tests/unit/support/test_doctor.py similarity index 92% rename from tests/test_doctor.py rename to tests/unit/support/test_doctor.py index 6f91c55..661dd0c 100644 --- a/tests/test_doctor.py +++ b/tests/unit/support/test_doctor.py @@ -1,6 +1,6 @@ from rich.console import Console -from commitrocket.doctor import FAIL, PASS, collect_checks, run_doctor +from commitrocket.support.doctor import FAIL, PASS, collect_checks, run_doctor def statuses(results): diff --git a/tests/unit/support/test_errors.py b/tests/unit/support/test_errors.py new file mode 100644 index 0000000..fc5380f --- /dev/null +++ b/tests/unit/support/test_errors.py @@ -0,0 +1,24 @@ +import pytest + +from commitrocket.support.errors import CommitRocketError, GitError, PushError + + +def test_errors_share_one_base_class(): + assert issubclass(GitError, CommitRocketError) + assert issubclass(PushError, GitError) + assert issubclass(CommitRocketError, RuntimeError) + + +def test_push_errors_are_retryable_by_default(): + assert PushError("failed").retryable is True + + +def test_push_errors_can_be_marked_not_retryable(): + error = PushError("rejected", retryable=False) + assert error.retryable is False + assert str(error) == "rejected" + + +def test_push_errors_are_caught_as_the_base_class(): + with pytest.raises(CommitRocketError): + raise PushError("failed") diff --git a/tests/test_security.py b/tests/unit/support/test_security.py similarity index 91% rename from tests/test_security.py rename to tests/unit/support/test_security.py index 907f4dc..c30691e 100644 --- a/tests/test_security.py +++ b/tests/unit/support/test_security.py @@ -3,24 +3,25 @@ import os import stat import sys +import urllib.request import pytest from rich.console import Console -from commitrocket import logs, notify -from commitrocket.errors import CommitRocketError -from commitrocket.git import resolve_target, run_git -from commitrocket.lfs import attribute_line -from commitrocket.options import RunOptions -from commitrocket.report import RunReport -from commitrocket.security import ( +from commitrocket.core.options import RunOptions +from commitrocket.git.git import resolve_target, run_git +from commitrocket.git.lfs import attribute_line +from commitrocket.io import logs, notify +from commitrocket.io.report import RunReport +from commitrocket.io.ui import print_lfs_required +from commitrocket.support.errors import CommitRocketError +from commitrocket.support.security import ( has_control_chars, redact, redact_value, restrict_permissions, validate_ref_part, ) -from commitrocket.ui import print_lfs_required @pytest.mark.parametrize( @@ -116,13 +117,13 @@ def fake_urlopen(request, timeout): sent["body"] = request.data.decode("utf-8") raise OSError("stop here") - original = notify.urllib.request.urlopen - notify.urllib.request.urlopen = fake_urlopen + original = urllib.request.urlopen + urllib.request.urlopen = fake_urlopen try: with pytest.raises(OSError): notify.notify_webhook("https://hooks.example/x", title, body, report) finally: - notify.urllib.request.urlopen = original + urllib.request.urlopen = original assert "supersecret" not in sent["body"] diff --git a/uv.lock b/uv.lock index 8516fbc..2e0f835 100644 --- a/uv.lock +++ b/uv.lock @@ -1,6 +1,74 @@ version = 1 revision = 5 requires-python = ">=3.11" +resolution-markers = [ + "python_full_version >= '3.15'", + "python_full_version < '3.15'", +] + +[[package]] +name = "ast-serialize" +version = "0.13.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/21/d5/5dc1ee8a80c3b20a0b63c61b43ba6bc53517faecd1def47bcd752d22268e/ast_serialize-0.13.1.tar.gz", hash = "sha256:401cc84e8888d4d76f2c8d296fa006ed1a5ff993b6aff90dd777c03973efd025", size = 955137, upload-time = "2026-10-17T00:04:17.183Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f3/a8/fbd136b9f70c59e75f59a8e974c84102976f1201828b4f886480ba956936/ast_serialize-0.13.1-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:3e129d44b0cffbea24a7f40117ce49e30993c3d119e584d4817ebd6f87246456", size = 897306, upload-time = "2026-10-17T00:02:52.479Z" }, + { url = "https://files.pythonhosted.org/packages/50/3f/2ad51e9823a790e7a70fd781e9595ab3abeace27f3aefcaa1939457efd72/ast_serialize-0.13.1-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:523d45bab16ddaf1399c04c4fe81bbf180f81e33c2f7bcbe76be56b0f7311ab4", size = 1236082, upload-time = "2026-10-17T00:02:54.82Z" }, + { url = "https://files.pythonhosted.org/packages/c0/5c/8e959db5cc2237f9d4c560a8e2253c98f9746883fb4774651e4cda458901/ast_serialize-0.13.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:638333fb8ae72c62753f9e794fda20290883ddc65b0d85e26e08f8bb227567ad", size = 1221242, upload-time = "2026-10-17T00:02:56.395Z" }, + { url = "https://files.pythonhosted.org/packages/d6/05/ab1c56c3b7adcac88764bba609502d6b4989e449b2dd60eb478e1d20e369/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cc34c670747d85d4232834665e247009413eaebe47c69eaf60a5c439aaecaed9", size = 1282105, upload-time = "2026-10-17T00:02:58.275Z" }, + { url = "https://files.pythonhosted.org/packages/0d/f4/41981fcd2ddffe0760e5326be9dcbd2eda9478a8430a637e5123bd8fcb26/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8c8ebd419811c435812d242fb2a173e57dfede198c9ac9a0a584666ebc9b9331", size = 1287905, upload-time = "2026-10-17T00:03:00.068Z" }, + { url = "https://files.pythonhosted.org/packages/6a/43/b783addc5681153707121991b7b47892f7e9c8ba58a0d03b71a3b023ba47/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8899c038b1c15ae8b98e379057fb3ef398ceb0b21d1737a8156dd5a0923b7e51", size = 1541806, upload-time = "2026-10-17T00:03:01.503Z" }, + { url = "https://files.pythonhosted.org/packages/47/10/969db095038ee15270f65ad20d1129c5e4da605bf7e93b70ae640f1c8a9f/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e14c4de98f965647a74e6eaf37e20207124e45451ccd36e84a6f6ebab45e0372", size = 1309946, upload-time = "2026-10-17T00:03:02.971Z" }, + { url = "https://files.pythonhosted.org/packages/06/dd/7c623d2fb0b868948952d1787e629a43b866f7d4caefd5445e20aefacec4/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7f3e8a3eff69af640db985360fef35073fb46956dfc3e5c614cf00920d2746dd", size = 1302773, upload-time = "2026-10-17T00:03:04.378Z" }, + { url = "https://files.pythonhosted.org/packages/d4/c2/4d49469110a19a44fc6269f4fd59679bcf84df068f185f89b73bee4da19b/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:75d7750fe98f6f35a96c43aba8d98a2e623e22c778a0c17ab9ede92eb10f5d82", size = 1299579, upload-time = "2026-10-17T00:03:05.88Z" }, + { url = "https://files.pythonhosted.org/packages/9d/9a/2d381f1f262dda15affc8ad643fba1619eb07e7d9f8bd904deffef183006/ast_serialize-0.13.1-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:43e8ddd63e80fc280c2f790157386f27f9b9f6ccb9c4f8e803b863cbfb085769", size = 1355969, upload-time = "2026-10-17T00:03:07.321Z" }, + { url = "https://files.pythonhosted.org/packages/9d/9c/2266794e6c25fa9ce51ce04a9bf4b7e330e3ac9351ba3fa14e487678acdb/ast_serialize-0.13.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:9221e09496fb942901993c1812ee87950cc0ecbb514c7c0f1f5fa6d78f701ed8", size = 1460227, upload-time = "2026-10-17T00:03:08.733Z" }, + { url = "https://files.pythonhosted.org/packages/2b/d6/14deb28e5d8f328f626a0778ea2cf98fe908f2bbcccd804cb6f449ee1782/ast_serialize-0.13.1-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:7a5c38bdb93669c596f94fb7204dd6ebe4fadb19058ac9a2faf2948c2a175f96", size = 1562691, upload-time = "2026-10-17T00:03:10.25Z" }, + { url = "https://files.pythonhosted.org/packages/f5/19/7a28c0e5ba54f0d3e054f847a2a549b748cb179ab433321a8dc1b39e398d/ast_serialize-0.13.1-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:acf4e9f055d75058ab01536da330648746f2f82b7697a85230547f2d5ebe895c", size = 1558669, upload-time = "2026-10-17T00:03:11.799Z" }, + { url = "https://files.pythonhosted.org/packages/18/9a/f9e2690eab58217f1d395a964a78efa7eaf813a1e38be8dfd9a8d45d0840/ast_serialize-0.13.1-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:87427913c325adc811e81e7c9a757b061f47ef1e29114ac479aa0953a2687a98", size = 1665071, upload-time = "2026-10-17T00:03:13.284Z" }, + { url = "https://files.pythonhosted.org/packages/8e/f3/ef5b159a0d7161b404f05e7ec21cf7735ee7edc10c000cd2cbbc7bb6b69a/ast_serialize-0.13.1-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:ad88921f95b92bc144d9ad059a0e16f8c1ae69f5239f2d3c6536fd2774f73dfe", size = 1473364, upload-time = "2026-10-17T00:03:14.563Z" }, + { url = "https://files.pythonhosted.org/packages/1d/87/6e8ac4a865124a12cc4f915bf1bcfac3bba426cd5f58d3712a873ee61012/ast_serialize-0.13.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:f8b17e2921e56621bcb46792bd3e0b82ca3b85de78d5936e7b8174ba1758b0aa", size = 1500566, upload-time = "2026-10-17T00:03:15.917Z" }, + { url = "https://files.pythonhosted.org/packages/f5/1e/29155f1621433008013ad5c940a03d41a676be0680c41527040472d37583/ast_serialize-0.13.1-cp314-cp314t-win32.whl", hash = "sha256:2f9a9ce8b0994f757b941f7f7fe384a6666b4162b941ebc5c248081baea18e47", size = 1128674, upload-time = "2026-10-17T00:03:17.481Z" }, + { url = "https://files.pythonhosted.org/packages/bb/64/2506da65143ea138de5822e9173e0b72320a2f70e23bd723f044033175f1/ast_serialize-0.13.1-cp314-cp314t-win_amd64.whl", hash = "sha256:5d99910e6b9a9b9360bcca2ae99aee36cc912ce058df2a57d1c33099b6cb2593", size = 1163306, upload-time = "2026-10-17T00:03:19.046Z" }, + { url = "https://files.pythonhosted.org/packages/6d/8f/c7cb22638899b0cf15908809c270560e46395e65604bc59e4b623ab9f405/ast_serialize-0.13.1-cp314-cp314t-win_arm64.whl", hash = "sha256:a789cbe14d0a0e9ec9b32a456e5abc81ad8799479c3cfd88a29e3442262aebe6", size = 1133775, upload-time = "2026-10-17T00:03:20.377Z" }, + { url = "https://files.pythonhosted.org/packages/2b/e2/b0c140fe50fa39dd249e382f7733af6f816c90021fe7959a0b026f86237f/ast_serialize-0.13.1-cp315-abi3.abi3t-macosx_10_12_x86_64.whl", hash = "sha256:23d768369b89d551077dc173da6892fad00443338417523b6732f4e8ba4a7ed5", size = 1236160, upload-time = "2026-10-17T00:03:21.945Z" }, + { url = "https://files.pythonhosted.org/packages/23/c4/a8a2ca21e3943555b48221f8fba546877a7ad39efaf6505506524967d7c4/ast_serialize-0.13.1-cp315-abi3.abi3t-macosx_11_0_arm64.whl", hash = "sha256:68f8829d114dab6c9db4a8bbb8d0e342958faee1b5e15a29022678df639960f8", size = 1222214, upload-time = "2026-10-17T00:03:23.462Z" }, + { url = "https://files.pythonhosted.org/packages/15/19/2f58f2ba64e4799b39de85c140aef09a03aa6ea53be75dd292a9d9b9d8ae/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e385b17d5bde892a6184003a9aff3518387908b73f8f5ea539313c07c8c0ede", size = 1282979, upload-time = "2026-10-17T00:03:24.695Z" }, + { url = "https://files.pythonhosted.org/packages/b1/af/ca6087fe84210c1ccd43e3182917bb70649fa1e69745a90c1d59ba08fea8/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:02686b281ec9b8e9614f6f0db27e12e4cac515f336c5d05b678bc9eb73ff2af5", size = 1288596, upload-time = "2026-10-17T00:03:26.04Z" }, + { url = "https://files.pythonhosted.org/packages/b0/2c/4ef964c763329a0347125e745ec0451ba4fbaceec9efe2ac729b7cd55f17/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a8ab2c2585b2e22e48cd4aff2136fce4eab4ced569b85f150ef9a5a5d6f34d49", size = 1545540, upload-time = "2026-10-17T00:03:27.52Z" }, + { url = "https://files.pythonhosted.org/packages/bb/85/aa961dbb75813cfa94de0ce9a16a9510c226b95f604c405421e727f44bb0/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c652d9f5d52d8b81eff3ff2c95c9dd0f281de45f6ad5d3fa95527550c396454a", size = 1309374, upload-time = "2026-10-17T00:03:29.091Z" }, + { url = "https://files.pythonhosted.org/packages/b4/e6/f2b67c327d9f9533e41791804403ccc2dc457821195a2e51f0b587a90b90/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:121e1d08d58b75c15491cc3003609cbad71ac2b0016043c36d30a6b2032b6605", size = 1303466, upload-time = "2026-10-17T00:03:30.451Z" }, + { url = "https://files.pythonhosted.org/packages/73/1d/33f18b81d1bb1f5d682943ea92fda8130a6593627f12f6201668d40824fd/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_31_riscv64.whl", hash = "sha256:30cf89b6a6844542d116c758725d13de5b97b9410a51ee577715f761270d0c1c", size = 1300576, upload-time = "2026-10-17T00:03:32.102Z" }, + { url = "https://files.pythonhosted.org/packages/25/cb/64914144925f1a4abdd9217e717b122255c38fc5ebe4342f92052f3bacbc/ast_serialize-0.13.1-cp315-abi3.abi3t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:732aaae9e498c973fc63fd7f308009b57c4afa6ff59d0b674d894e57d0bca01a", size = 1355960, upload-time = "2026-10-17T00:03:33.676Z" }, + { url = "https://files.pythonhosted.org/packages/ee/80/bd29379fab2bce19adc0bf9177002b11b23dfe8d8fecf409998b458b4624/ast_serialize-0.13.1-cp315-abi3.abi3t-musllinux_1_2_aarch64.whl", hash = "sha256:d9c1a920b2aa0c1e016bed7721689717034ca0dba64ac3a3ff243b003d4e8dd8", size = 1459779, upload-time = "2026-10-17T00:03:35.09Z" }, + { url = "https://files.pythonhosted.org/packages/83/89/012dbe733de05ffdf8e40ca0f9fa5d417cb16ec93a74463c57c001914198/ast_serialize-0.13.1-cp315-abi3.abi3t-musllinux_1_2_armv7l.whl", hash = "sha256:847cad4c22953823f5e76d0b126c6f9da670cfa45b1df41b9324e22189d77611", size = 1563399, upload-time = "2026-10-17T00:03:37.285Z" }, + { url = "https://files.pythonhosted.org/packages/69/37/ee4bcb0358bee38744eb0f18560446572d095fe3bf6b63d6f739d08a839c/ast_serialize-0.13.1-cp315-abi3.abi3t-musllinux_1_2_i686.whl", hash = "sha256:aca07de3ca8e3d9f2b716c3c31f4f384fe4bd2d03e09912417cff7a3e08036f7", size = 1558808, upload-time = "2026-10-17T00:03:38.711Z" }, + { url = "https://files.pythonhosted.org/packages/54/1c/ff44c5355251d61ef22934c4430bb31a61de4781d25a992154aac9b8c82a/ast_serialize-0.13.1-cp315-abi3.abi3t-musllinux_1_2_ppc64le.whl", hash = "sha256:5db12d843d931b9d1f1519ce66b9cbfe72d8563b75c1204d255322254d1964dd", size = 1666324, upload-time = "2026-10-17T00:03:40.376Z" }, + { url = "https://files.pythonhosted.org/packages/c8/bb/6da4bfc8aa3403e6447607131bf3463acaf954d990c6c8b6787c1902ddfe/ast_serialize-0.13.1-cp315-abi3.abi3t-musllinux_1_2_riscv64.whl", hash = "sha256:fb8021f4dc3296de18737e3b8b34994411da725374d74a0b9eb32a738f2a23d0", size = 1474089, upload-time = "2026-10-17T00:03:41.715Z" }, + { url = "https://files.pythonhosted.org/packages/21/97/897e33bef2eefd880e6350e375cc66bc5bcd00a139be480fd655f5b3f095/ast_serialize-0.13.1-cp315-abi3.abi3t-musllinux_1_2_x86_64.whl", hash = "sha256:0d764913374ba21df8cd618045b371ed104ce55c6276de7c59e554a4f5ba26fd", size = 1501542, upload-time = "2026-10-17T00:03:43.08Z" }, + { url = "https://files.pythonhosted.org/packages/8d/4c/821211ac83870c27e4412381b7c7838336456b40575bf840e4680b2018d9/ast_serialize-0.13.1-cp315-abi3.abi3t-win32.whl", hash = "sha256:2bad302ae2427454ef9dab71bd5c3ad67188860c39d36daee38f72031edb39c4", size = 1126118, upload-time = "2026-10-17T00:03:44.616Z" }, + { url = "https://files.pythonhosted.org/packages/1f/86/2b2d5e6c4fa352874a80618e742ffd32d249dee6c119f4233b51afc6b8f4/ast_serialize-0.13.1-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:032b09d86c785c3984e975378b7861f2a68ac44e22ba7b07b93a536b2524eeb8", size = 1163766, upload-time = "2026-10-17T00:03:45.986Z" }, + { url = "https://files.pythonhosted.org/packages/77/a3/d610cfcdabaa44fd62a54ca1fc57a7dba120643798b089a14914973562de/ast_serialize-0.13.1-cp315-abi3.abi3t-win_arm64.whl", hash = "sha256:929eda0c419e622ab49df3a4c45f81c57dcc10874bbad55d0470a4a03324dac3", size = 1134043, upload-time = "2026-10-17T00:03:48.453Z" }, + { url = "https://files.pythonhosted.org/packages/f0/89/0e30f9eddf7d44ccf9d25979030754fd0457af61fa4279acb8c293a04f97/ast_serialize-0.13.1-cp315-cp315-pyemscripten_2026_5_wasm32.whl", hash = "sha256:bf53a3ba1cbe45399fc1e4ccd684b8f2a11cca450f89706b79122f478534c6f5", size = 897546, upload-time = "2026-10-17T00:03:50.093Z" }, + { url = "https://files.pythonhosted.org/packages/81/92/d705be88ff452b9ba0088b554a0cbd308fd01879da092b33fd2ad7d1aa60/ast_serialize-0.13.1-cp39-abi3-macosx_10_12_x86_64.whl", hash = "sha256:4bcf1d5f4eefecaa325a34ecf079b2741189e7d0821523f92cb343a389a67489", size = 1242416, upload-time = "2026-10-17T00:03:51.521Z" }, + { url = "https://files.pythonhosted.org/packages/60/c2/98370845a7f35cb8a25782e78284b48e01bf3128339881d48d613f304f8f/ast_serialize-0.13.1-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:1b158f1c9e3a0d386913924c57995d6df78224868a4d0f215bdd41587c97b34a", size = 1229729, upload-time = "2026-10-17T00:03:52.825Z" }, + { url = "https://files.pythonhosted.org/packages/d8/8b/2d7ffed76addd9d3fcf37fb171400942735c8912264c763561a85407f6a8/ast_serialize-0.13.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:77a6201b69ce42e919f2fd9a559138d5410b5d8afff7c3a6b1f500b0481ff7d8", size = 1292255, upload-time = "2026-10-17T00:03:54.148Z" }, + { url = "https://files.pythonhosted.org/packages/6b/2a/bb9e0e719d89cc950fadfcfcc9cb4bc7640419c4228c852f031ab8abf440/ast_serialize-0.13.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:6eb0be64c9b8f1ed26637eef345abe75ea90351c92c85a8aec7838b3af971011", size = 1298501, upload-time = "2026-10-17T00:03:55.559Z" }, + { url = "https://files.pythonhosted.org/packages/7a/32/13ce07dce48226f5bd9cfd8f708ec101a8be05aa430cda4918ce31ce8c82/ast_serialize-0.13.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7f2427bddfca208e84de700044fadf9aef2769a70bae740a1bdabb89ee9e1117", size = 1553758, upload-time = "2026-10-17T00:03:56.952Z" }, + { url = "https://files.pythonhosted.org/packages/e2/fb/9b51d186db0c20ca28cbaaefd50f03b573c89327b9a2627820cbce22196b/ast_serialize-0.13.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:88df960e67184a71874e5b2ee014f87d1254a0dbc1f903c7bd7b1ab7733ecaef", size = 1318258, upload-time = "2026-10-17T00:03:58.418Z" }, + { url = "https://files.pythonhosted.org/packages/c5/fa/da311559dd3dae9af5825cf21660775a929b970f72e3786af3f2cd667944/ast_serialize-0.13.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9f99786e0d62082a5b121b3437f3167562133711df22128de1e9886f57f0b226", size = 1313260, upload-time = "2026-10-17T00:04:00.194Z" }, + { url = "https://files.pythonhosted.org/packages/2b/11/97a4b9e5b4776d72f47fcd9a09a497bbf68ec8c1ae074307a2c51e410d85/ast_serialize-0.13.1-cp39-abi3-manylinux_2_31_riscv64.whl", hash = "sha256:a01b515b25a03184eff4acef25b981ae007916379682e908fc8785b342a0bf3e", size = 1309992, upload-time = "2026-10-17T00:04:01.575Z" }, + { url = "https://files.pythonhosted.org/packages/2e/c4/62f85121a80cd451ef04f550cf0f7ea0ad9ff46cc4e9a5b9ae439b6527b1/ast_serialize-0.13.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:29422d7bcd9e7f39411571c36cec45ce8a7a9b3ad4b2e7aa64497c15a9e397f6", size = 1362715, upload-time = "2026-10-17T00:04:02.881Z" }, + { url = "https://files.pythonhosted.org/packages/c1/fa/c5f4a545f72a7681e3295bab6e3600ee0862ec4391bed961fe9f735b67e0/ast_serialize-0.13.1-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:6ffb0f548a7dc126067fdfb7b2325ab5dfcdeecc29faf5e0f0461c96d6ebfa3d", size = 1469931, upload-time = "2026-10-17T00:04:04.181Z" }, + { url = "https://files.pythonhosted.org/packages/38/a9/65aed4f8fa7a001a7cfdc03e68e844517ab041ba6fb614b7d78a1d6ac056/ast_serialize-0.13.1-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:2876444a5f87a7c76f371af3c07c2fda563a08bc8af52568df812e8aba4bf568", size = 1570945, upload-time = "2026-10-17T00:04:05.778Z" }, + { url = "https://files.pythonhosted.org/packages/fb/8c/44b2da991cede79bfbf52089f33a5f0168945466b3d9cd38b5dcf08e7130/ast_serialize-0.13.1-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:885a62ec6481ce58ab24c6357360d7a82023b62dd7e5e7ceccf59e9662a3272b", size = 1569978, upload-time = "2026-10-17T00:04:07.347Z" }, + { url = "https://files.pythonhosted.org/packages/46/e4/109b2a5beca700237767d5add920c2f8e1ba9bd5799b0faf143d0e9cf4ef/ast_serialize-0.13.1-cp39-abi3-musllinux_1_2_ppc64le.whl", hash = "sha256:2015fd0165e463aac3b1aadc6a1fa1e5820c14ca950821f4fe02f8a3f6a388d6", size = 1676082, upload-time = "2026-10-17T00:04:08.7Z" }, + { url = "https://files.pythonhosted.org/packages/73/e0/7df70f6dbb11b5762da5416318f08316a1c51348e0d69ec79ca5f98f836a/ast_serialize-0.13.1-cp39-abi3-musllinux_1_2_riscv64.whl", hash = "sha256:eb41e1906502ac80d24ff343f45008552a3f5b5158607959fe6a07dbfc6eb037", size = 1483207, upload-time = "2026-10-17T00:04:10.162Z" }, + { url = "https://files.pythonhosted.org/packages/1f/bc/523aa1c08bd69b5654621beb3dc1a9035715a4a63762fb8d219d6fb3eb81/ast_serialize-0.13.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:ca9acc67f796aa2554fa3037dccc022a4b08b38b2ad153edfac9c9bb7cb1f3c6", size = 1512140, upload-time = "2026-10-17T00:04:11.589Z" }, + { url = "https://files.pythonhosted.org/packages/66/83/6607060659998f00afdea0d8375c1e6e2b7d515ab905090d9a5a02f48851/ast_serialize-0.13.1-cp39-abi3-win32.whl", hash = "sha256:4f98da562e5901d69c7dd30885594c5438f859edf354e9ac7517d188fb026c3a", size = 1131889, upload-time = "2026-10-17T00:04:12.953Z" }, + { url = "https://files.pythonhosted.org/packages/9f/6f/bafd6490fe7b355627fabe95f4417e3d02da93102c8552550eb9a0774e1e/ast_serialize-0.13.1-cp39-abi3-win_amd64.whl", hash = "sha256:ddf7cbc9c8abf70102c4a088efe154bb86bfb825b0a10e556d2b15972cf99bd7", size = 1171153, upload-time = "2026-10-17T00:04:14.362Z" }, + { url = "https://files.pythonhosted.org/packages/11/25/4235f4b375a67a37ac595bf478a5407a744eaf7b64113c1c3a5432b8d954/ast_serialize-0.13.1-cp39-abi3-win_arm64.whl", hash = "sha256:48f11d96c9ec71119612f8e79a8c55c12f2b136716d68347433c561d27a25f43", size = 1139035, upload-time = "2026-10-17T00:04:15.767Z" }, +] [[package]] name = "cfgv" @@ -22,7 +90,7 @@ wheels = [ [[package]] name = "commitrocket" -version = "0.1.2" +version = "0.1.3" source = { editable = "." } dependencies = [ { name = "pathspec" }, @@ -31,6 +99,7 @@ dependencies = [ [package.dev-dependencies] dev = [ + { name = "mypy" }, { name = "pre-commit" }, { name = "pytest" }, { name = "pytest-xdist" }, @@ -45,6 +114,7 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ + { name = "mypy", specifier = ">=1.10" }, { name = "pre-commit", specifier = ">=3" }, { name = "pytest", specifier = ">=8" }, { name = "pytest-xdist", specifier = ">=3" }, @@ -96,6 +166,122 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" }, ] +[[package]] +name = "librt" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/04/f5/9dc696772d241814bacac7880bac32f2930b5a6ebc1f85317b83161a011c/librt-0.16.0.tar.gz", hash = "sha256:ac38d6d8d66bf3d744148dbbc0b8e193e195a51e364ed55e224631f5721891fc", size = 219839, upload-time = "2026-09-29T00:55:32.891Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ba/0e/b04fd2d76b6a78a02286938251b2c119fb36ddece92c76cb4886ef7d44b8/librt-0.16.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fe4372c52d4849096c6cc1cda2817d293ec51440c890474ed59ef38d46556f18", size = 148058, upload-time = "2026-09-29T00:44:40.903Z" }, + { url = "https://files.pythonhosted.org/packages/a3/fc/e1ed24aadb32d38603c0c07f579d739eb4d90e64e90d525b024e4a999b4d/librt-0.16.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c72c5295a84bd249526da9bdca38f2e176d15c31c13bb0063c5053f4ca023421", size = 153073, upload-time = "2026-09-29T00:44:42.165Z" }, + { url = "https://files.pythonhosted.org/packages/be/38/133ab655409420e0c34a9a9836a7f4e5ae75fba758d7fe177099130d58ba/librt-0.16.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:be56ba9c884143495b517f23fe794ae367d58cd89ea0fdd6d437e3c024a87f9f", size = 493052, upload-time = "2026-09-29T00:44:44.043Z" }, + { url = "https://files.pythonhosted.org/packages/94/42/aaa663bc9421f5bf7bbbe9d3316d7219749698ec7688ac3b519770a89c04/librt-0.16.0-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:ef46c1a29ffb8c72e882e22618ec618778eacd0578fb22c6e7cf9c11d15f357b", size = 485506, upload-time = "2026-09-29T00:44:45.479Z" }, + { url = "https://files.pythonhosted.org/packages/7b/59/83a6eb5087ba8b45b083859e2085256963e06d4c2531944cdd962670bfb5/librt-0.16.0-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:d3c94211ee0c4f8d649ec06b7c115c0ec4eadb873a0e3154ca15cef3f814b071", size = 498708, upload-time = "2026-09-29T00:44:46.916Z" }, + { url = "https://files.pythonhosted.org/packages/a0/e4/15a8d62b2bc12935080ec7277e2e0b9b233047781eb784a51d3e25af669a/librt-0.16.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:94aed6a8308818b91677957d1bd03188869cd7aeb23c5dba7912a6c0402f7602", size = 515981, upload-time = "2026-09-29T00:44:48.316Z" }, + { url = "https://files.pythonhosted.org/packages/46/4f/287cc282ac5dd815204c0779e79401bb0a568c3a1335fb319bf0838fb566/librt-0.16.0-cp311-cp311-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:349c0bcb87ebd07481b6ff781e25cdc699723dbe2212e57dabb27f7a13b7b87d", size = 508670, upload-time = "2026-09-29T00:44:49.726Z" }, + { url = "https://files.pythonhosted.org/packages/bf/5b/ab7292add898ade0d2b5b75d32a923aae315861671aa5c39f5491309f7ae/librt-0.16.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:001bfd59a7d45b17e3e75f2a8c6405280b35e7b84471792778e718c4f368950e", size = 530393, upload-time = "2026-09-29T00:44:51.356Z" }, + { url = "https://files.pythonhosted.org/packages/7a/9e/8e6bcf027d4bcbc16a4e864b3d158a1d3e5f55ffa53af0238020cad89271/librt-0.16.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:28e038895b998d7a0c7798922ce8a1dc157675df5cf1c9ef0aca809ed804b7a1", size = 534302, upload-time = "2026-09-29T00:44:52.893Z" }, + { url = "https://files.pythonhosted.org/packages/96/a4/8c5ab4f3b3a8e905ff8305d76976a2e666f52fe049edd398aed2402beb36/librt-0.16.0-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:0dbe4096a7ecc00fa835d24510ad8545a4efef738dac96e0e63516783ccde905", size = 536150, upload-time = "2026-09-29T00:44:54.421Z" }, + { url = "https://files.pythonhosted.org/packages/ea/5e/7c4bc267e3cd4b8bd288de9f62d61fff203829c9cc649ea2aa12e9218cf0/librt-0.16.0-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:5cd5b092441053364af968ea12084692cb9d4a22f3ce9524e377880bf028761e", size = 514316, upload-time = "2026-09-29T00:44:55.998Z" }, + { url = "https://files.pythonhosted.org/packages/e0/75/c8bc6b50f43c73819334233f5a3259c81216742cef56d2140c3dd377c3f0/librt-0.16.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:3ddeb3c9dedb461bb457c6c7d9aa7fbf35329da313d1a7543d00c8d0f3473c96", size = 557731, upload-time = "2026-09-29T00:44:57.581Z" }, + { url = "https://files.pythonhosted.org/packages/93/fb/e241f91bc8de6c7ac1c6a20ea6dd381bc52312b44d711ffcd97140db1e57/librt-0.16.0-cp311-cp311-win32.whl", hash = "sha256:e05108e0849966f53a8d2d3112a7af881d0efaa479bc735bba91108f9f2350a7", size = 104922, upload-time = "2026-09-29T00:44:59.078Z" }, + { url = "https://files.pythonhosted.org/packages/d1/38/c892383d2bb1a6a80b2ec8ede84970a265a792c56614a06282bf3008517c/librt-0.16.0-cp311-cp311-win_amd64.whl", hash = "sha256:5f49cff01bd608ef7d97104cb035c75455e79c2d70bf4a506cf773338ac1860d", size = 125093, upload-time = "2026-09-29T00:49:01.621Z" }, + { url = "https://files.pythonhosted.org/packages/e4/56/8bbde1ed0b21480163617648f638fdaec9374cf5e9c846ebcee34ec02a42/librt-0.16.0-cp311-cp311-win_arm64.whl", hash = "sha256:1d28ae980ae2218f9c5b95d191e947296f918c9bf0b400d467a9430275bbe678", size = 115910, upload-time = "2026-09-29T00:52:40.131Z" }, + { url = "https://files.pythonhosted.org/packages/ad/76/bbdaeb87b7c47b5c7343e90222b9bfa4e4a8a83f647e02933ad0129225b1/librt-0.16.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:fe52bf4641069e7978a14253b036cb9002def1926317e710f2e249f8a8c47742", size = 151028, upload-time = "2026-09-29T00:52:41.508Z" }, + { url = "https://files.pythonhosted.org/packages/fd/0c/ab8ed3dab0085931aec4a792c7eaac8dc6c5ff4691fda3a5360d9d8a9cd2/librt-0.16.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5bcc2c4726ced915b00de0c9856a4eeabfb3fddb93e10e0b8f735b7709358b6d", size = 155283, upload-time = "2026-09-29T00:52:42.873Z" }, + { url = "https://files.pythonhosted.org/packages/eb/36/494e79d460c80c1f030661e8287c9eca5e1ad652dc2b2180b6cd42abce0a/librt-0.16.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ff7baa55f8e7c69851419e50a666015d02a74198716fd45c0125a2112e0a389f", size = 503185, upload-time = "2026-09-29T00:52:44.638Z" }, + { url = "https://files.pythonhosted.org/packages/9b/34/a8464038dd9db6e4381fa2b6eb73dc9a50888d77102c4c139304ac35cddc/librt-0.16.0-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:b95d5d92ab83d39e760a52091bb1baba664f3a2351e39b1e16801e5747c2f0e9", size = 496738, upload-time = "2026-09-29T00:52:46.441Z" }, + { url = "https://files.pythonhosted.org/packages/6a/53/e0e5e334ef0c6ed27039d323819368b9ef6712be87d55ee2bf9799398afd/librt-0.16.0-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:b6d085d70bce51d43c5c7c36d63490770180d8779e71c49305c87b4213918de7", size = 513818, upload-time = "2026-09-29T00:52:48.068Z" }, + { url = "https://files.pythonhosted.org/packages/ad/f7/7ce72cbf19d0addd05090b339152fd0548a02562c2866a603e6e3b3da2df/librt-0.16.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:36e53948e99bbe3ffea257124cfcae1cfb01831555c9a9c903c9f9a72db7fd07", size = 531952, upload-time = "2026-09-29T00:52:49.816Z" }, + { url = "https://files.pythonhosted.org/packages/83/22/0b1bcb6a8e723c8b4fd60dfc8ae8ec6461c54073fbc8685efeb8d900d407/librt-0.16.0-cp312-cp312-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:54d11f726aae9df5a6ffbbf0a03a52449bbac84a53ef03669cb41cdfd4ae41bf", size = 524465, upload-time = "2026-09-29T00:52:51.354Z" }, + { url = "https://files.pythonhosted.org/packages/64/2e/e9c23b8b9df1813da1be205deca9606beb7ddd033972246cd426d05374a0/librt-0.16.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:4323193ac0cd025f85af531df8ba91bf24d1973b401697347a6282e8fd3fcf5e", size = 543191, upload-time = "2026-09-29T00:52:53.284Z" }, + { url = "https://files.pythonhosted.org/packages/bc/e5/6a8b21b342c03ed7e230fa3afbfd2edc58e6e87ef1f0d11fa2b9a748c252/librt-0.16.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:e42f8e098b9c5396fefa05fb1cc7e33b0e08fc51da106b5de4a45fd22aac6743", size = 546979, upload-time = "2026-09-29T00:52:54.932Z" }, + { url = "https://files.pythonhosted.org/packages/84/9e/b5129023eced1be01e01c22757f53be551d463b1bb7264f787927404c1d6/librt-0.16.0-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:39ec1d5a14e37baf1450a6cabf03fe552340808bf1ad9d71824ab90117716459", size = 555317, upload-time = "2026-09-29T00:52:56.869Z" }, + { url = "https://files.pythonhosted.org/packages/71/89/28bba5938c725fe91f06bf93f7fa6c6b150229df53a87b454b0d5c2a796e/librt-0.16.0-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:d1aabe3925cbb4a08d15b7b20ba4011b53019da0c4173a25155139b7b1baed65", size = 535846, upload-time = "2026-09-29T00:52:58.475Z" }, + { url = "https://files.pythonhosted.org/packages/22/92/63773026614f888c5d4e370e395ce42ca604b89f70b3acdfedbf94851b80/librt-0.16.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:300c3ffdc459f4a779a8411ecb188e3ac0b1ff3a3a7b099642555dedae06c69b", size = 573700, upload-time = "2026-09-29T00:53:00.127Z" }, + { url = "https://files.pythonhosted.org/packages/66/8f/347d4677eefb57cd9f8e01d95a1dcee9a91b4e44e664173c32ff6f3752e5/librt-0.16.0-cp312-cp312-win32.whl", hash = "sha256:c17194318e4c0c0348b36f36c2ec7534436fe0a4c15582403162a4f08c80797a", size = 106158, upload-time = "2026-09-29T00:53:02.031Z" }, + { url = "https://files.pythonhosted.org/packages/f0/2c/5193dc81127cd5ddfad031391b046bf32dda219b38463ab872407ca30646/librt-0.16.0-cp312-cp312-win_amd64.whl", hash = "sha256:25a58a19ea8d83b68209f04912df765e9260635ef77646542ed4b4abe6bc7940", size = 126176, upload-time = "2026-09-29T00:53:03.445Z" }, + { url = "https://files.pythonhosted.org/packages/ff/3d/9668a400c8dd81d162eba38b33fa49fa6205f1a64493570a13fbb815c3ee/librt-0.16.0-cp312-cp312-win_arm64.whl", hash = "sha256:f7be7cf555bc30ec12622e9447299cc4a9b8ff307548b634794353db0c2065dc", size = 116572, upload-time = "2026-09-29T00:53:04.815Z" }, + { url = "https://files.pythonhosted.org/packages/46/cd/ae5e0e9dba45d1399aa04a5395bcc0bead40d9fa06dc903634a7b4d7473d/librt-0.16.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:c5e6144e68b577f157519f2ba88ca20e3ed61c29b00e5cdfa76cd2d45acf059a", size = 151036, upload-time = "2026-09-29T00:53:06.284Z" }, + { url = "https://files.pythonhosted.org/packages/41/5a/48a16e323c5f9447a94cce7b59babf60fa04e62c3365ecf060c77ed8b320/librt-0.16.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:33f41443a1f4e1f099331b3d8120e409fbff84b9760bc1cc9ea496f37ddaa5cc", size = 155211, upload-time = "2026-09-29T00:53:07.72Z" }, + { url = "https://files.pythonhosted.org/packages/3f/29/0f59299eb4251a409b2e690ad4b7d9f8a676db829d7817ec961f32b44f7e/librt-0.16.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7e510b7770bee609617a3374a96548eb114cae048023e3f049ee449e7ff2db32", size = 502587, upload-time = "2026-09-29T00:53:09.191Z" }, + { url = "https://files.pythonhosted.org/packages/de/ba/d6fb4ef8d1537c396079d72289f16be7cd35a366e5065c51253fea2760b6/librt-0.16.0-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:efc49c462d4516b8a58b00b490078fa64689fd1fe66970cc190131d7afb8027e", size = 496146, upload-time = "2026-09-29T00:53:11.016Z" }, + { url = "https://files.pythonhosted.org/packages/52/fc/8c50dd4d7cc97c0ee8f252c8a3104980f234391cf1519b554e8b9de08b60/librt-0.16.0-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:92caf82ebef5e12d21c72242b70d1e92536f1711cf2a727a4c276de4b4469087", size = 513336, upload-time = "2026-09-29T00:53:12.655Z" }, + { url = "https://files.pythonhosted.org/packages/a9/59/16c409c56f708eda2db9a0553662845d45e3871c77d70a240dae3f3bdc56/librt-0.16.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:17bac7f7a16b328fff77e440287693eb017abde913595b5827ebccbc21ecd8a6", size = 531689, upload-time = "2026-09-29T00:53:14.39Z" }, + { url = "https://files.pythonhosted.org/packages/88/82/d34772a6c29d1446dcca6e64d74062efd508523ab351aa16625a4689d5cc/librt-0.16.0-cp313-cp313-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:5b976054553670829985ed767feb78fb6bcede0175327c4844dd5c281c1be659", size = 524537, upload-time = "2026-09-29T00:53:16.064Z" }, + { url = "https://files.pythonhosted.org/packages/77/8f/24c5631313746131ccee53bc91fdc8374f9cf25e0082a1fee9c93bb98acc/librt-0.16.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:0058f9d68721094105917254c72ac0569117bb7b13b9769cf45d26d89f9d21cd", size = 543231, upload-time = "2026-09-29T00:53:17.939Z" }, + { url = "https://files.pythonhosted.org/packages/f2/cb/5f8e0d41dbd8b499c2265e939c31acc9ba59845565bf99539ad1c06aebcf/librt-0.16.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:30b7beaf3f4487b7d8adef1f158b49067cb4d5a19fa7a3bf31a4e7a820e435c5", size = 546499, upload-time = "2026-09-29T00:53:19.666Z" }, + { url = "https://files.pythonhosted.org/packages/be/61/063052de441d1385f59cea4223f184bf9e5d125de1ae3239b490aa1e486e/librt-0.16.0-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:468df902df016a06eb0e40b0747dc8d14e47d7a38b18b63b1fb167d85cb94d63", size = 555261, upload-time = "2026-09-29T00:53:21.292Z" }, + { url = "https://files.pythonhosted.org/packages/14/11/a2ada0529372268d6401afa9d457a095b68cd7753532b6f7f33049a19b43/librt-0.16.0-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:aea7b1f2b125dad5de85f049136651bff256c883c65e6b9209b2da0a1ac3cdef", size = 536029, upload-time = "2026-09-29T00:53:23.07Z" }, + { url = "https://files.pythonhosted.org/packages/23/9d/5bb6d38853382986dca702fc7e06c8256d30f5fa0676d882773b744610dc/librt-0.16.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a8afb6557920860b7a3a596eb804cf37e09e7cf8a803db2478c202acc72d8c2e", size = 573748, upload-time = "2026-09-29T00:53:24.696Z" }, + { url = "https://files.pythonhosted.org/packages/99/f6/0025cde35ff7f607684dc775a2b2d732cce2561cec050a6ee1fb2e1fc6fe/librt-0.16.0-cp313-cp313-pyemscripten_2025_0_wasm32.whl", hash = "sha256:77c7a2b4fe2c1369e0d5aa1cade26740a7b14be32fbc9a5535d617d20065c39d", size = 79861, upload-time = "2026-09-29T00:53:26.089Z" }, + { url = "https://files.pythonhosted.org/packages/93/93/303b8592909bd583f83f02818ffbea3f7647ca1e22b1cd5465d04b8145fe/librt-0.16.0-cp313-cp313-win32.whl", hash = "sha256:02d89c813d5ff74b17df72d3a34819d132cd168e56b81bf755b809bd9e46b8c4", size = 106236, upload-time = "2026-09-29T00:53:27.43Z" }, + { url = "https://files.pythonhosted.org/packages/cf/24/80bbb463c60ed18e29cb26aba386ddb76609580e4e7160710e550587018c/librt-0.16.0-cp313-cp313-win_amd64.whl", hash = "sha256:14ed6ebe3e4f85f326d7920011ad30ff49ed9334e62cf88caef9ba973d9e3a92", size = 126180, upload-time = "2026-09-29T00:53:28.7Z" }, + { url = "https://files.pythonhosted.org/packages/43/80/b1a6fbdd7da825cdd55c71aa81eb6cfa82c513c360774152eacb50b4a771/librt-0.16.0-cp313-cp313-win_arm64.whl", hash = "sha256:83d4041a3d9b2fd053a8a4e1f22878b3e5833e2712956382d5c048d791454e91", size = 116557, upload-time = "2026-09-29T00:53:30.012Z" }, + { url = "https://files.pythonhosted.org/packages/1e/93/9e0cf7da129a93c3dc7f45bc3cd4a660f2aaa995aa8a6f95c2583ef41239/librt-0.16.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:931a0bb0fcac88f263e269e46eb30ba8e21402cd3c62ca40cb97034c0693fab1", size = 149844, upload-time = "2026-09-29T00:53:31.391Z" }, + { url = "https://files.pythonhosted.org/packages/8f/26/8a90d2a8f2b2e471bb486b7aec117b8ae622715ed6c39853aec48ea20073/librt-0.16.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:1bc17e54e5305f8d40b7ca203671ff5a9e59c1d0f8ea0f625dcca53a3984de11", size = 154111, upload-time = "2026-09-29T00:53:32.718Z" }, + { url = "https://files.pythonhosted.org/packages/35/ce/67abb46258da4d3e42ff5b141db6f38c59357bef84c7979f183b22f924f1/librt-0.16.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:877698bf6bca5721d8be345f2fe09778e40ecadea8b58c73075f2b1a53666bf2", size = 494234, upload-time = "2026-09-29T00:53:34.466Z" }, + { url = "https://files.pythonhosted.org/packages/12/f9/ea7162414a16f8f1bbd3b493ad6d22b926c5471916e078350bdbca8c4e5f/librt-0.16.0-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:5981c011b306781ce561e18e14230a14524a3d8109b97553666c942c18f31a96", size = 491173, upload-time = "2026-09-29T00:53:36.124Z" }, + { url = "https://files.pythonhosted.org/packages/b1/09/9b3e869060dd33f9989b80ba4fea306f6db8cecefcdfe6d7346ef0603f65/librt-0.16.0-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:afced3dfc17cd805ecf7a3d77996a71cf5f2c75aa66eb0c21a9930f4fc992f86", size = 505547, upload-time = "2026-09-29T00:53:37.686Z" }, + { url = "https://files.pythonhosted.org/packages/50/07/79007d2165f649ea93e08c0962d1d62c70af9cde77965255095bf9d96f9a/librt-0.16.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ca8052401c55d7511dda6760719fda7618067e83535d7d0010096d216c34b667", size = 523057, upload-time = "2026-09-29T00:53:39.301Z" }, + { url = "https://files.pythonhosted.org/packages/61/0c/8fbaff66d0ba376d8864653f5acce1569bae27e89648671f26f7eca67ab8/librt-0.16.0-cp314-cp314-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:1e511762a074005bb0aa569166779834e75e438370226930d0ce1866d4b6a33b", size = 515158, upload-time = "2026-09-29T00:53:41.012Z" }, + { url = "https://files.pythonhosted.org/packages/df/2e/23ff0dece76f07a4124413a57682efa0bbeb5765ac0122bc0955513f82ca/librt-0.16.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:f1e8591bd8a5a628cd7f07954c6a1592359a878bf032957a8e9057a41d644311", size = 534183, upload-time = "2026-09-29T00:53:42.451Z" }, + { url = "https://files.pythonhosted.org/packages/26/c4/e11dea21d9a29486eba78887380374189d472734fa32cc50cb37ca44d3d0/librt-0.16.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:a4aaefb4ba6c07e1aeebb2795c8958148f1d6f9af3b555b53d23d766edb6d67a", size = 540663, upload-time = "2026-09-29T00:53:44.272Z" }, + { url = "https://files.pythonhosted.org/packages/44/75/e873ae158a8b7f5359be33e7fd6c1fbe02d9a78a3e89a77de6b0e837f476/librt-0.16.0-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:d92db7a0f6aee44f1baee94750457e8d2d1c6ccea41842de6268d34e8dc7eddd", size = 545908, upload-time = "2026-09-29T00:53:45.812Z" }, + { url = "https://files.pythonhosted.org/packages/ba/36/8939d3f6a93e11bd9592e6fe28d2b44f1c2dc4bed6e22e72359a91e18ffb/librt-0.16.0-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:378dfaffb38e59c24a87cde5713cd865d51ff7383fa12947f3907f306ea1ca55", size = 523302, upload-time = "2026-09-29T00:53:47.596Z" }, + { url = "https://files.pythonhosted.org/packages/71/14/35309f44a077f0f42ade0e2e7cd88c0cea760c661af205c01ea90d3c0e1f/librt-0.16.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:3e0c39bdc85370422e8b637be76eb1fd07d30967551b03e62267dd156f553152", size = 565911, upload-time = "2026-09-29T00:53:49.278Z" }, + { url = "https://files.pythonhosted.org/packages/78/0c/df6255b94967f3159ebc46f08d8e783c12da6ee269ddb74b2efed63c640c/librt-0.16.0-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:1b384b90ab79a7bc30b566895809a636e0666f21f3cf12b54823d025b7e83839", size = 79119, upload-time = "2026-09-29T00:53:50.938Z" }, + { url = "https://files.pythonhosted.org/packages/6b/44/d30d5a5461378c9d33f36736c6791c3b4c4ba4b1ffe0da7350aedcb2c9a0/librt-0.16.0-cp314-cp314-win32.whl", hash = "sha256:52327da75a94012e7f932f913d20d3876bed3c102be00e6c3e8600ff7bdd58a7", size = 100140, upload-time = "2026-09-29T00:53:52.205Z" }, + { url = "https://files.pythonhosted.org/packages/c2/98/769712f356a1e897df3581bb0c3100375d054a000de26099360ea65b5111/librt-0.16.0-cp314-cp314-win_amd64.whl", hash = "sha256:3f0b8114c44b2ac06ff5dacd08e07e8e807ff4f46083f2a1602685122559be41", size = 120464, upload-time = "2026-09-29T00:53:53.495Z" }, + { url = "https://files.pythonhosted.org/packages/bf/d3/ae2abccc8bdc8b063c1613a77686e17b74e9d3d60cfe6f12c63fa2821b9f/librt-0.16.0-cp314-cp314-win_arm64.whl", hash = "sha256:8caf96a4ef8fb27d0ac0d1ad8337d26a240acd4a02fe4345d0a8f264753e8f99", size = 110889, upload-time = "2026-09-29T00:53:54.817Z" }, + { url = "https://files.pythonhosted.org/packages/e4/26/0737d4be058dd6376eade7dd8b380d4b869b6394cee929393a5a431c45bb/librt-0.16.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:953107e2f68d0f3512c48f898b0dbf0ce5cc52bba0f318d847c985dc555ee4cc", size = 159838, upload-time = "2026-09-29T00:53:56.22Z" }, + { url = "https://files.pythonhosted.org/packages/01/96/9bc96531d7c620e9949af904470f02e3fa8f35129ab8e8f281c51eaa3788/librt-0.16.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:ad37d5b9abd49c9a655dcda7ea52a8a752884062ef1ee71ae17c2f2a0f81fe6a", size = 162018, upload-time = "2026-09-29T00:53:57.532Z" }, + { url = "https://files.pythonhosted.org/packages/0e/fa/b0289dcb186eb3f97221ba00da5f4bd3ba7fa5e99752d48aa8d336615334/librt-0.16.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:2c4aa329c17bd1aaea4f6e89335d8ccd494b3a5830b6654462273e50e11023f0", size = 703983, upload-time = "2026-09-29T00:53:59.024Z" }, + { url = "https://files.pythonhosted.org/packages/d9/ab/05ebbbde7530fc5eeb58fbd1581522a9f64f132fa703c4c595eed6e14760/librt-0.16.0-cp314-cp314t-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:0ead24d2562a49473dddd9efef8581f020007eb0054389c3ee3ffad38b1ca4c9", size = 683847, upload-time = "2026-09-29T00:54:00.671Z" }, + { url = "https://files.pythonhosted.org/packages/a3/75/f52aeecd4dbadbddf80725ba7de126d8bd5d0eb66247eae17a81ed90dd4d/librt-0.16.0-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:02118f56a9c36ddd07dfd9b919d9ecc117ba20a90987d56aa4c429fa34509188", size = 698045, upload-time = "2026-09-29T00:54:02.247Z" }, + { url = "https://files.pythonhosted.org/packages/e6/55/fa277a835cd6eb42380591ceb85f48c5b4d2b2d7e2cb9869e1e17d24d237/librt-0.16.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4e29522c62e28595ff7e324c6834ade51127707f0e255b18d1c1cf03d39c1048", size = 724640, upload-time = "2026-09-29T00:54:04.078Z" }, + { url = "https://files.pythonhosted.org/packages/25/e4/2cf64354f3fde8ebd591b3b48f96510bee24ac5f7d1e567adbbe210abdbd/librt-0.16.0-cp314-cp314t-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:3ff4b2367926b69c6215635902cccb04048e73094e9862900d27cb2c6bbff143", size = 731748, upload-time = "2026-09-29T00:54:05.741Z" }, + { url = "https://files.pythonhosted.org/packages/f8/c9/c180af3e94e01aa529fa93d7733fec2abc47f222345400cf21d5481d5f8a/librt-0.16.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:c6f1b27bf1632a7e016af9f145f82be95e1edd7721a646505c21059257cb5a04", size = 754960, upload-time = "2026-09-29T00:54:07.38Z" }, + { url = "https://files.pythonhosted.org/packages/95/d6/01073aa78c58f356b10d9c57b3fe9abb143df338142bcd316df417b89db0/librt-0.16.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:5696d7f52e7b37217cb3a8f92c744fe835942602fdd4c1a8bc4741d3bfdce15e", size = 747000, upload-time = "2026-09-29T00:54:09.06Z" }, + { url = "https://files.pythonhosted.org/packages/f7/d8/1de3783908658d697a8cfc00582f61299ffba7796d7260c112e4700b1109/librt-0.16.0-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:6072e92dd876ff6ceeb6cf371e35e51f479349837391341f479b08df4564242b", size = 749569, upload-time = "2026-09-29T00:54:10.702Z" }, + { url = "https://files.pythonhosted.org/packages/b7/32/e817f66c96d6caa8bb8435ff93c4c220624d59efc506be59ab98fcd01d0c/librt-0.16.0-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:39ca4f2f2fe05de8e63493da592d84311adabe5bef52b193851981da9816b302", size = 729483, upload-time = "2026-09-29T00:54:12.25Z" }, + { url = "https://files.pythonhosted.org/packages/7c/c9/23992ccd2b9d22798fdd0f61353183a47414e651da782ad83eb680f50833/librt-0.16.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:f9807485a908f00355820f18e91e045ffdcdc5adb68aaec40a1e2b88c5f7bba1", size = 776584, upload-time = "2026-09-29T00:54:13.837Z" }, + { url = "https://files.pythonhosted.org/packages/67/3b/e8af957f08e6e2e8e566b099e43d2748418aa565df6ee1d9d3331209fdfe/librt-0.16.0-cp314-cp314t-win32.whl", hash = "sha256:94be5cb7bca4df6201f4183e9e4fa2086c655283d20b38cd84500a69057575a7", size = 104402, upload-time = "2026-09-29T00:54:15.568Z" }, + { url = "https://files.pythonhosted.org/packages/ca/1c/946e6443d7cd32347a086043395e421e52fd603c9163d2ec970ceab8eed6/librt-0.16.0-cp314-cp314t-win_amd64.whl", hash = "sha256:d46ca272b251d033dd4527b0dec5f261a28a52bd5fa0f99c117b0a1f8588cc2d", size = 126227, upload-time = "2026-09-29T00:54:17.165Z" }, + { url = "https://files.pythonhosted.org/packages/c2/a3/bc4f9959d3c62bcbf9e5fd3470a8bbd8bf33224ed4c25d7fba173201b8ac/librt-0.16.0-cp314-cp314t-win_arm64.whl", hash = "sha256:b9d6d4b14e92d876f8026b54c20c445f36425214c1081dc76f74e40db386b82b", size = 116493, upload-time = "2026-09-29T00:54:18.567Z" }, + { url = "https://files.pythonhosted.org/packages/b6/4b/10fdb42dfab4c1533e1570e686b18e86ff4328b406361b39fb3016667638/librt-0.16.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:6fe436af2eaf630474f491af5d032cbe45f93fcff5c3b9fe4ab194a7255b20ff", size = 149829, upload-time = "2026-09-29T00:54:19.933Z" }, + { url = "https://files.pythonhosted.org/packages/8e/30/a90ca13f1d3d91af1680000a4038536907018fbd51764767287a05d28b8b/librt-0.16.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:8ff5d26c529336be9bd7ae04483235d77778ee7d6444a95353102b542601ce81", size = 154522, upload-time = "2026-09-29T00:54:21.306Z" }, + { url = "https://files.pythonhosted.org/packages/5c/dd/bcf364eacfa070bb1fc88d503111ae7177914197ba1fa717c748926e7930/librt-0.16.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:909d8e3c1faee44cb762b1c519ff8613dcc5ceae5c99987a00917b5a31fd1d6a", size = 497593, upload-time = "2026-09-29T00:54:22.798Z" }, + { url = "https://files.pythonhosted.org/packages/18/c1/2c4e81e347bdabfe8346bfc6dc37ae5e154d61c88e30848ec0606025a5e0/librt-0.16.0-cp315-cp315-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:6d4a64283ee61824b5790de882bc68e2d9d7a5143537cb7a966f7354f71646d4", size = 480459, upload-time = "2026-09-29T00:54:24.364Z" }, + { url = "https://files.pythonhosted.org/packages/ab/d7/fef2a3cb8400701be496f6e459876f650b3451f407e30cb243de571ae615/librt-0.16.0-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:5810ba811297fdf37a1531a57667cb8ace0842013ca8606bf9eb7c24cf4be154", size = 507814, upload-time = "2026-09-29T00:54:25.997Z" }, + { url = "https://files.pythonhosted.org/packages/e1/6f/53762927a32e9dc9eb1d1c1f3528da281290c86d96929a8af652f671266e/librt-0.16.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e56aaf8c167548dc8e5d6f3bd0f48dcdd299a23c73be3f744aab79d99e9c7f5d", size = 525114, upload-time = "2026-09-29T00:54:27.747Z" }, + { url = "https://files.pythonhosted.org/packages/6c/67/0b9d031f303c4e8c691a9a8ef9d272f13b530c11cc563b819df621b6a348/librt-0.16.0-cp315-cp315-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:8f36c58e33b304b525c6c9c5076399c6ebf1109e17b9051a05a407b091b9215b", size = 520465, upload-time = "2026-09-29T00:54:29.331Z" }, + { url = "https://files.pythonhosted.org/packages/ae/d5/2056a3a85864e882eb17a203a10ddb26fa748bc9718ec67e79059ab46cae/librt-0.16.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:242e00b3d4fa37c3d3c1ca5f5c9adb7d909ddb1eac9c41f2787320d00caa0af2", size = 537257, upload-time = "2026-09-29T00:54:30.915Z" }, + { url = "https://files.pythonhosted.org/packages/54/57/e0d79790c163cbc0909e209a6f62e30bb713b647f905a176cdc64848fd4d/librt-0.16.0-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:0253721561787b8df8443eb347b7a6461015354e5bdd37ee38a41fef220d2bb0", size = 527442, upload-time = "2026-09-29T00:54:32.478Z" }, + { url = "https://files.pythonhosted.org/packages/aa/50/1c0c95aba7af51f4752ea34fbf2eb79b36e7cae3a72536248e8c735de735/librt-0.16.0-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:3e483a8d69ede8067db70c0e83007423b6925de6fd53afed01d66160f2e9398c", size = 548139, upload-time = "2026-09-29T00:54:34.183Z" }, + { url = "https://files.pythonhosted.org/packages/98/91/a8a43dd5138d4f55f88846b8f0c85454a4fad69952cebfcff9948f831290/librt-0.16.0-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:69ba927445cfaaffb4081003ef5224c55a5c2ab67ef956f416ef744916e44121", size = 529708, upload-time = "2026-09-29T00:54:35.761Z" }, + { url = "https://files.pythonhosted.org/packages/2d/41/d5226881ab2b7c20d9d587b37bdd4a0ec8775a96d00ca87ac9f385587db4/librt-0.16.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:d6a365f2ab45a984d0e00eee0dd17f599ceab8cadab6ea07b6111c8132fc0e42", size = 567781, upload-time = "2026-09-29T00:54:37.409Z" }, + { url = "https://files.pythonhosted.org/packages/bb/bf/2345ba57a626e8c78c4ddcc724636a8df5a593fe46c1ee76bbf477e32b0d/librt-0.16.0-cp315-cp315-pyemscripten_2026_5_wasm32.whl", hash = "sha256:f01f3805f2dae4781c0c34b440e31740d082950bdaf89a6f601ad589a28af57a", size = 79177, upload-time = "2026-09-29T00:54:38.792Z" }, + { url = "https://files.pythonhosted.org/packages/1e/40/99e77936cc9207f629b077bf7cbc5e2f0827cddd7c29792f04ef881bd2c3/librt-0.16.0-cp315-cp315-win32.whl", hash = "sha256:b0e3e721c75d2e79a76d4422c79d7ba705fe1bbafec907037fe7a657a480a0e3", size = 100127, upload-time = "2026-09-29T00:54:40.251Z" }, + { url = "https://files.pythonhosted.org/packages/56/1e/801fe26bc622061b9dfd010e166d94142cb774b733217e6d98d1c0cf2638/librt-0.16.0-cp315-cp315-win_amd64.whl", hash = "sha256:bc02954b1295de798bbdb0b4e2d8a28c2117de8b5c73dcbeb27dc32572dfb971", size = 120480, upload-time = "2026-09-29T00:54:41.722Z" }, + { url = "https://files.pythonhosted.org/packages/bb/a9/d533983055bd36e112627384c2c038845d1df882540b8bcefb566475640b/librt-0.16.0-cp315-cp315-win_arm64.whl", hash = "sha256:c5db585d43449a5f54303d4b2774e45e1babd975cfe1630a3d708c0b80c3e560", size = 110915, upload-time = "2026-09-29T00:54:43.052Z" }, + { url = "https://files.pythonhosted.org/packages/55/fe/d62238fa9c653b0e0613290349467cb65711b5800e8e474f45e942a0ad95/librt-0.16.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:f06c689cb14afd9b612727553a5ec5a40febf113ca41c4413a2b0b334285884b", size = 159714, upload-time = "2026-09-29T00:54:44.497Z" }, + { url = "https://files.pythonhosted.org/packages/f3/ac/f31efe7818700be72ba4f9af8a80fa67c39808c8d26dacc55dc1f6f35172/librt-0.16.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:13b4e8aba90b0b1c82474e9844aa9ffe7ad3faa484350e1da64cb8188d903134", size = 162086, upload-time = "2026-09-29T00:54:45.968Z" }, + { url = "https://files.pythonhosted.org/packages/d9/16/4d7487bf86a9d7e8e18f37ba5538789233ea693637379b75701bd35ec9de/librt-0.16.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5a269c46ae327d8e6f8c1f85f7516cb52c0fa48127565a1105a4f4a05ff2a0b4", size = 712727, upload-time = "2026-09-29T00:54:47.486Z" }, + { url = "https://files.pythonhosted.org/packages/77/74/50cd550ccc1a517b9ed62347625c01ddf8c4afad66490312677c011458f6/librt-0.16.0-cp315-cp315t-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:a33e0dae1f8592146a4764d54ce842b278732d21a84e17c3bbe6b1bc158a2248", size = 681106, upload-time = "2026-09-29T00:54:49.126Z" }, + { url = "https://files.pythonhosted.org/packages/df/5d/7293f712975ee6fdd2251411fd9ef1c62bc99c7b83ecbe62dbc999b1fab7/librt-0.16.0-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:47ada6ea32636492c61aa8ad27ae3b9404bfe7a97e3ba946d1984236cc741da0", size = 705921, upload-time = "2026-09-29T00:54:50.905Z" }, + { url = "https://files.pythonhosted.org/packages/67/f7/8aab946f11d59d1bece9ffc65d994b200c789a8ca5a95c17e17e609f912a/librt-0.16.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c43bd6e642d8a248c114327f98dd25ac5a7cb5aa168ef02f0559b91874df16b8", size = 731786, upload-time = "2026-09-29T00:54:52.584Z" }, + { url = "https://files.pythonhosted.org/packages/43/76/1c42ab31e7cb8384ebf6d3af607213c495222474f4940443ae7639ab7685/librt-0.16.0-cp315-cp315t-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c3d1bb7841a816ace6449bb26d3f9560dbfa20e71c568d23f0f62bf1e68f50b1", size = 744964, upload-time = "2026-09-29T00:54:54.217Z" }, + { url = "https://files.pythonhosted.org/packages/6f/2e/4b19982d933d2dfced671e840b219e4c1cd3f507df6e6dabb51bbd4e3850/librt-0.16.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:3931f7a3db322e7f44e02a280e3949326ce9579ad388ee8d691dc7c76da9fb70", size = 765305, upload-time = "2026-09-29T00:54:55.815Z" }, + { url = "https://files.pythonhosted.org/packages/b8/1b/e872583de2dcb3ac7746e7a2321aeeb168274f3952a87dc66e05ddb29faf/librt-0.16.0-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:f4462528b6000afe8f16907b5c7c2553abf1df005ba5140e6eb394541c3624c3", size = 744959, upload-time = "2026-09-29T00:54:57.532Z" }, + { url = "https://files.pythonhosted.org/packages/10/de/a18c6bcfb297af2674233e90b3c3661c3a0af0f1434a0c966d2ef708a835/librt-0.16.0-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:80039ba9b6a7d5f1a0175a4cca6bbefead87bd854c80abad1cb30afe47a830db", size = 758138, upload-time = "2026-09-29T00:54:59.484Z" }, + { url = "https://files.pythonhosted.org/packages/22/1c/0df1d732539c297bb1a093e1fe3204d2faf76a9022cf4e1d1c2fce059790/librt-0.16.0-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:7a1d272724b581bb6bc769dfdafed6da2ecc9886ba2450311de55a4ac2e1e9cd", size = 744268, upload-time = "2026-09-29T00:55:01.179Z" }, + { url = "https://files.pythonhosted.org/packages/a2/f7/ccaf31331f20c91a5bd9bd48ffc3f743f9c81bb5720cc7b2a720ca204f0a/librt-0.16.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:fbe4fb8c5445f7496d7f7f6bb0807875d09d47e6771ffa175fb2df2895fb86ba", size = 785783, upload-time = "2026-09-29T00:55:02.938Z" }, + { url = "https://files.pythonhosted.org/packages/c1/ea/7421d9e6db894cd6cd788b604b3394a163ded6b942052b6f96c23ccf08e1/librt-0.16.0-cp315-cp315t-win32.whl", hash = "sha256:375bfe6b572a8f6cfc398709356046173bf27e64c4c5edaf5f7062f051fb4bf9", size = 104355, upload-time = "2026-09-29T00:55:04.533Z" }, + { url = "https://files.pythonhosted.org/packages/85/6d/7c31a506eb847bc58aeb2402d58e17605e821f68ab5df5e66fe274a6df41/librt-0.16.0-cp315-cp315t-win_amd64.whl", hash = "sha256:bd3150023d3dc2bc70f3784e59ffa1140d56ddba3d8125b3d6f9f85221279bfc", size = 126134, upload-time = "2026-09-29T00:55:06.017Z" }, + { url = "https://files.pythonhosted.org/packages/36/69/7a5d10ac409c4da0355e054a14371871da9b5557fcc42772cd00181c6cce/librt-0.16.0-cp315-cp315t-win_arm64.whl", hash = "sha256:8ceafb70f2a4f0826f11031942e59c0728fd98da112dc346d4352bde1e486866", size = 116391, upload-time = "2026-09-29T00:55:07.484Z" }, +] + [[package]] name = "markdown-it-py" version = "4.2.0" @@ -117,6 +303,75 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" }, ] +[[package]] +name = "mypy" +version = "2.4.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "ast-serialize" }, + { name = "librt", marker = "platform_python_implementation != 'PyPy'" }, + { name = "mypy-extensions" }, + { name = "pathspec" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/4a/3c/78ecece71ee4b5445389a4ccd11627cfb9c69e4de554d11060171f376305/mypy-2.4.1.tar.gz", hash = "sha256:63b590965691e540a335fa74dadf31a7069142f6b72e234689bbd244edf55623", size = 4066728, upload-time = "2026-10-28T19:23:13.286Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4b/8b/2bc7f489528db504221ad7eff6b3f83979ee57d066103c72a85d09046a30/mypy-2.4.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:79a1e79199e980fb41f219cb3d4746d25c64b0b623840d3ed57df1cdc13a6502", size = 14321495, upload-time = "2026-10-28T19:21:16.612Z" }, + { url = "https://files.pythonhosted.org/packages/18/9a/b2f037b4982dce33645296e4394b031ade60f697f468761fa3ea8e2f8ece/mypy-2.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4e18d0da3898b3bcd16192f15a206e7b8b8dd0f4a0b3e51aa5bd5c2afe749e2c", size = 14467468, upload-time = "2026-10-28T19:22:10.629Z" }, + { url = "https://files.pythonhosted.org/packages/c4/5a/379f9bfa18bf3f8d43668fbd9ae4f2922dd027a559c461ca9d41cde1d32e/mypy-2.4.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b69a15fc2e75858d6b15e91ed3a0dcff1a533265183b64734138791fe0f49aa5", size = 15421496, upload-time = "2026-10-28T19:22:48.005Z" }, + { url = "https://files.pythonhosted.org/packages/83/50/3bde18a2824ec296432cebe01752ccd0ab8a2ad784abe4390040d019b3bf/mypy-2.4.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:70971cc0bcb1d3f03d2eb68fa430a6481ccc03558dc001d9534d7e5fa274c392", size = 15670425, upload-time = "2026-10-28T19:21:57.026Z" }, + { url = "https://files.pythonhosted.org/packages/6a/36/8b722b88c325d317354de7d10d8fb9d4dc0f958433e873a91fc4ed21a06e/mypy-2.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:6f7225951a277dd0d6add900731d487174b7d24ac133c09d670ed63b4d8cb90d", size = 11300972, upload-time = "2026-10-28T19:21:48.724Z" }, + { url = "https://files.pythonhosted.org/packages/c2/d6/fb2bab1245658d68af8abfe776362a780c621fe0f364f2c7b53039a945ee/mypy-2.4.1-cp311-cp311-win_arm64.whl", hash = "sha256:be4c03f33c55500191df2ed4a9b5e7edbdd1fff067fe361a5a9b1b5d3262da6e", size = 10873349, upload-time = "2026-10-28T19:21:32.104Z" }, + { url = "https://files.pythonhosted.org/packages/c0/1a/0be9dc6af5e0e04128f18a5e36b4ca44bfb0085857d37aa6a7de1ac2b0cb/mypy-2.4.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d63737426a048a27705a4eedb828669f4bc0873612a1b46b0b9fe892b2ebaaaf", size = 14381321, upload-time = "2026-10-28T19:21:54.223Z" }, + { url = "https://files.pythonhosted.org/packages/0d/a6/7907e36711a8a8c703f961f076fab61793383694140bd1fd87589f3f68d4/mypy-2.4.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7344869cad05f073b8cae2826774fa0161e3eb2f5c685b76813574008d77d750", size = 14466373, upload-time = "2026-10-28T19:22:25.211Z" }, + { url = "https://files.pythonhosted.org/packages/5d/b8/7313212b29de570c25c9859d7c8e4ef2251a6d34338a1e20031d94297721/mypy-2.4.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a20ff6cd2af7a670c64f089bfa5fbcebe8ff3bf896c5e6ac7c9862c7960e4494", size = 15553666, upload-time = "2026-10-28T19:22:36.511Z" }, + { url = "https://files.pythonhosted.org/packages/23/8f/92966b6082ff49da9142e1e527eb9af4359a9a61632a1cfc313da96b37fe/mypy-2.4.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:9ed1195502cca32be5ef756b1693477f4991db2f2e34eaa90cc4ad6bea4f9531", size = 15802641, upload-time = "2026-10-28T19:21:13.421Z" }, + { url = "https://files.pythonhosted.org/packages/b6/b4/874f6fd54b005020ad63e2cf7a59b178d16a771d478849b29b842cb0cf14/mypy-2.4.1-cp312-cp312-win_amd64.whl", hash = "sha256:4c194c5d878130fca1ae662dfb1feb6274afbab0b40032c80147377e0ea803d5", size = 11383067, upload-time = "2026-10-28T19:22:03.516Z" }, + { url = "https://files.pythonhosted.org/packages/b0/41/5ae8e6528c2faa96e4a921a999d2c7ac7c565bee184b4282bf62ffa76b5d/mypy-2.4.1-cp312-cp312-win_arm64.whl", hash = "sha256:71eda06e5bae51976ce869fda429159c9cec678bd02f25bb197f0265c8f991be", size = 10946882, upload-time = "2026-10-28T19:21:39.51Z" }, + { url = "https://files.pythonhosted.org/packages/6a/65/cd19bc06b67d2df4828220245fd98569ba40fac00c60ba48bef1817d8ac3/mypy-2.4.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3f1613bfe6726169a5680ec3dad5fe1f6d96285c12aded51ad432eadedd39d45", size = 14214179, upload-time = "2026-10-28T19:22:27.49Z" }, + { url = "https://files.pythonhosted.org/packages/c9/db/4d54ca4f49a0113d0c956980272aefdc6eec5458f7a72b350785b9ef2249/mypy-2.4.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:680ba5d9f0e3fe0c746b3d14df15f2a718e4bc308a1145616a1ea691ce7c354b", size = 14376217, upload-time = "2026-10-28T19:21:08.019Z" }, + { url = "https://files.pythonhosted.org/packages/a2/45/089b4724b85f0f408941be5298f817ee89181c1ce031a73d60ebb150c2c7/mypy-2.4.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1fb70621535c22fd4b1a0450d37ed1d6c5eb39656a1cebfb189084c12de54ba7", size = 15467623, upload-time = "2026-10-28T19:21:21.555Z" }, + { url = "https://files.pythonhosted.org/packages/27/4c/15edbc64b0b1412bfe94c74192b3b56554ab642b85a31bb06cef6313101f/mypy-2.4.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:4af5ad558033bf71a44a1be149ed61633522824f84c1b6bc2445d3fe2d2a5296", size = 15729867, upload-time = "2026-10-28T19:21:37.557Z" }, + { url = "https://files.pythonhosted.org/packages/76/5b/7d160fb685994b65b0ca86d352f3afb5424f96a9e6914719f7b861fb6701/mypy-2.4.1-cp313-cp313-win_amd64.whl", hash = "sha256:acdd82cb3a2eb10720e87706a128d75785d005a8c47e36a4973221524f41fc56", size = 11390802, upload-time = "2026-10-28T19:22:18.081Z" }, + { url = "https://files.pythonhosted.org/packages/9a/ea/453d27f8d531f57c5f14aa73094eaa48e3fb77f680bdede2045cb64fa58b/mypy-2.4.1-cp313-cp313-win_arm64.whl", hash = "sha256:133886ef1a7a8cf673df55d865e41580c6c46aa9b8e31e1325dfe315c038f745", size = 10950427, upload-time = "2026-10-28T19:22:59.003Z" }, + { url = "https://files.pythonhosted.org/packages/7d/75/282d43d6fea7be984ac63e75ffd8eee146ba2f3b077bb1ca5bf3f973e0c4/mypy-2.4.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c45485061ba08f700acc12cfc8b177e6997e6bc353605babfc0abb081e079456", size = 14233251, upload-time = "2026-10-28T19:22:44.977Z" }, + { url = "https://files.pythonhosted.org/packages/ac/a8/9021263cc7e761451c7d8131bdfab3c0a5c2d67aa2d694670019e1ab86a7/mypy-2.4.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:727890a32f1858c09549eb55a8b234fe990d460450b28f03e8213ef925f1247c", size = 14394953, upload-time = "2026-10-28T19:21:29.492Z" }, + { url = "https://files.pythonhosted.org/packages/16/10/4192a5cea09ebbc41c534f57bd0d8f0fb42a8e810632cda6e37f072c59fd/mypy-2.4.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:beb254fec368c4e7f7f82a5f310c6470b893ec88a90b66426da971c6826b0453", size = 15442824, upload-time = "2026-10-28T19:22:42.068Z" }, + { url = "https://files.pythonhosted.org/packages/99/e6/d3b0a7474aa4f696594a47a218b6796d9c4346fc81ed288904278cddd9bd/mypy-2.4.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:ec416d5d2ae689e681f5727e328723f18d8b5dc8c903a146b7851dc5727aad8a", size = 15717227, upload-time = "2026-10-28T19:22:54.026Z" }, + { url = "https://files.pythonhosted.org/packages/48/6a/2ec530dacd4f77ca50d0fa05b854098f2d75e5d18c587d2612b44f10d68c/mypy-2.4.1-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:0e95ad0bec03ced9a73b42514208abd24c789e67f0e1eba476e276dd7a2dea3a", size = 7898637, upload-time = "2026-10-28T19:21:41.709Z" }, + { url = "https://files.pythonhosted.org/packages/cc/56/de9d7bad12e3868d5f1f4279aed20b1b568b2c5e166f2d3a05b211dca0b1/mypy-2.4.1-cp314-cp314-win_amd64.whl", hash = "sha256:51f742d4154824837ca6e92aa81f00eec222700a3c337bd258e5562a3880d75a", size = 11576656, upload-time = "2026-10-28T19:22:13.232Z" }, + { url = "https://files.pythonhosted.org/packages/b8/12/4fa9883b9b59e5c96ff62845ad019dc47786031c45d67eaccf452cffffd8/mypy-2.4.1-cp314-cp314-win_arm64.whl", hash = "sha256:f44dd4c5ab22df21206dd926c98381ebdbf5bfd696df37dd38ded2d23143fcb6", size = 11174403, upload-time = "2026-10-28T19:23:01.346Z" }, + { url = "https://files.pythonhosted.org/packages/3f/f2/827e356fc4f74c60b8da42663336e035b49d948a3c11224b0fc7543086b1/mypy-2.4.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:2875280687e64740e6ddcef43bd4c5852ad45ff34549740f6aea3f0373870b93", size = 15713427, upload-time = "2026-10-28T19:21:26.757Z" }, + { url = "https://files.pythonhosted.org/packages/a2/fa/e58a4fcae1d238189eac758036c0921992a86e3e6209190efd96d61fc5d4/mypy-2.4.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ea0714d2bccaf6d010c970e1d3ba2c9c2add79d2030aad2ef03167d788948276", size = 15938481, upload-time = "2026-10-28T19:22:34.371Z" }, + { url = "https://files.pythonhosted.org/packages/a1/54/a20f881801b88900923f2be1541a4b438ad0f0883e03836641fdc3d7adf4/mypy-2.4.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:63c6ff0e7ea546943001a91639c9f0c64b60d239268fa5d29e4a6c87f82c2373", size = 17243006, upload-time = "2026-10-28T19:22:39.425Z" }, + { url = "https://files.pythonhosted.org/packages/de/1c/ff84a6133a6e89c390bff6b25d9bad6598e7891b205f4b30b496906d636d/mypy-2.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:a5b5da107dc2c93fb0a22f7a45dbaea5dc131afc7056b5468d78e819f9a138e6", size = 17557728, upload-time = "2026-10-28T19:21:43.607Z" }, + { url = "https://files.pythonhosted.org/packages/15/4a/effa47d39b8fadf679c08e7c78559e523f9769a42a75662d2d15b2b9cdd6/mypy-2.4.1-cp314-cp314t-win_amd64.whl", hash = "sha256:c3a4d0c47053cc90035dd3a2c321112b593ad42935d0cbfd747288e1564fa8ca", size = 12370826, upload-time = "2026-10-28T19:22:29.779Z" }, + { url = "https://files.pythonhosted.org/packages/46/9f/b214ececb1a97fbb61ab3dfd48ae3cffd92ae2c148af4c9dc94c6c56772b/mypy-2.4.1-cp314-cp314t-win_arm64.whl", hash = "sha256:0c5bf267645351887b72903fd2f5fbddcf85234e0e6c4ad94e2fcfb4f0c3f971", size = 11851083, upload-time = "2026-10-28T19:23:11.288Z" }, + { url = "https://files.pythonhosted.org/packages/57/5b/e44a2edb0b25a9f1429de770e1d0238af23302671dd40c77ac5efeb0c559/mypy-2.4.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:db599d03e7d60d15f2e0a11665c18bc52a88699fcab990fdf8cecd5be8ac801c", size = 14243144, upload-time = "2026-10-28T19:21:10.975Z" }, + { url = "https://files.pythonhosted.org/packages/59/d4/5c99dc3a28e11d2f0fcbb02df63d2d3e574dedc0f9f69d50901df305a7a6/mypy-2.4.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c6c7210e40dd423af7d65cbe428b5906d11dc60659337bdae4e5fdf02ce32ed7", size = 14409316, upload-time = "2026-10-28T19:22:15.515Z" }, + { url = "https://files.pythonhosted.org/packages/c3/c9/3108b38f4c30eabd80194f5d9771a87e27196c5e0ddb5bf4b99c6ed1e97e/mypy-2.4.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a2d4a51db92059eecc2c33b2a5194b28585ebfd917292c015fe87a77dbff6cd2", size = 15445573, upload-time = "2026-10-28T19:22:05.635Z" }, + { url = "https://files.pythonhosted.org/packages/dd/12/84a53eceaf11c46dfd7931fb6b8902d01fb33787d3a991e81c461458150b/mypy-2.4.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:01b7718552d017f88d1151f3cc9d6556d778a90bd58060a2c3d87d070f9099fb", size = 15732989, upload-time = "2026-10-28T19:23:06.512Z" }, + { url = "https://files.pythonhosted.org/packages/65/ba/bf017dc2abdf83b2f74e29c43834b7af67dc1f1b20202f02dae60b4781a0/mypy-2.4.1-cp315-cp315-pyemscripten_2026_5_wasm32.whl", hash = "sha256:3467b1d13000812ab85dc2a3834b9379ec77798ca1bcabe434e23fb21fead692", size = 7898932, upload-time = "2026-10-28T19:21:59.366Z" }, + { url = "https://files.pythonhosted.org/packages/76/05/0c22b1f0390120a8592d31209cb6b9f932b6a0b426fe643e550de15139e3/mypy-2.4.1-cp315-cp315-win_amd64.whl", hash = "sha256:080cf64a60b90a73435542feecf4171904cc5710658165b40c6869115d4aa100", size = 11577577, upload-time = "2026-10-28T19:22:01.302Z" }, + { url = "https://files.pythonhosted.org/packages/73/fb/ac01e173629697ddac2f11e51efd10347d673f9a7311b03f4aba710ebccd/mypy-2.4.1-cp315-cp315-win_arm64.whl", hash = "sha256:f9118a3f50de264b614861bb11814833a742138ac3c8e2e49a860b6977fb2704", size = 11173540, upload-time = "2026-10-28T19:21:46.444Z" }, + { url = "https://files.pythonhosted.org/packages/5b/e4/b9b9c8eb09e70927ee65b1456cfed35710b6e4ff0b07f364ceaf2202307c/mypy-2.4.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:9d7dafd56179d296651df9e1844b91c9517c379398f017a2a435d077a28943c1", size = 15706623, upload-time = "2026-10-28T19:22:20.528Z" }, + { url = "https://files.pythonhosted.org/packages/26/74/1ceb1ca884add0565e618d013dd24333039100dc0fcc42661561f2e1cae5/mypy-2.4.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d923cec43316f0e6736b8298fd00abeaaf348a091c20e7296b3aebceecb63eca", size = 15944095, upload-time = "2026-10-28T19:21:04.779Z" }, + { url = "https://files.pythonhosted.org/packages/2b/68/27bcf9b4efa22733b6050485ae37845b94c9b8851abe4fc60632d905c32d/mypy-2.4.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d6e081b466e88d4343adffe11aff0f02df34b5b9070b4b700053a0b7294c0be1", size = 17223065, upload-time = "2026-10-28T19:23:03.724Z" }, + { url = "https://files.pythonhosted.org/packages/1a/a3/ed5724b317bf585c29f3c8be2792e97d45925d65a9c8af40ceeb267072e6/mypy-2.4.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:70196470ac300f444a302a738541101893c2c57804078b33690286a7899149e9", size = 17560589, upload-time = "2026-10-28T19:21:34.539Z" }, + { url = "https://files.pythonhosted.org/packages/42/2f/005185e6ab4752fd6cc2d1a6d1421fe21979770afe2490c00c555f34a913/mypy-2.4.1-cp315-cp315t-win_amd64.whl", hash = "sha256:de95648e0a6d46fa9929b956ed2c87c5dc9933d4d59945e6390e9d753c74e7c1", size = 12353324, upload-time = "2026-10-28T19:22:51.481Z" }, + { url = "https://files.pythonhosted.org/packages/a1/d6/20420cc9c780087139662534d128c2f3274361f8bb7e9cf0d5495a846ed5/mypy-2.4.1-cp315-cp315t-win_arm64.whl", hash = "sha256:ef8d5be90032261197ac388d945d8ff4f476c95880798a1911760af64ddfe71f", size = 11845599, upload-time = "2026-10-28T19:22:23.136Z" }, + { url = "https://files.pythonhosted.org/packages/21/5c/6e8010f8f2c4ad817364592d4b3883633417269b913fc9d5174fdeb7e565/mypy-2.4.1-py3-none-any.whl", hash = "sha256:1784648d6ec8c2b5465e3f26241b845a0b3cb4e56c993c64abe16989e7698999", size = 2801286, upload-time = "2026-10-28T19:21:19.516Z" }, +] + +[[package]] +name = "mypy-extensions" +version = "1.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d0/6f/43edf3be2748d0e40974a5ee046a8bb4c9961a4bdd3e7d5c6dcbf32d1af6/mypy_extensions-1.2.0.tar.gz", hash = "sha256:c6e275a07f1c2fc096b62940452d0eaa3f3af7de45d704787866240a7c6d5a51", size = 6566, upload-time = "2026-11-03T16:26:33.692Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b5/99/7b1adac7e97ce7bbda34792dc6e9b2f5cc5cffd1875883f78a818b2a2687/mypy_extensions-1.2.0-py3-none-any.whl", hash = "sha256:993e7a20aa5671eb41a7132cf555af30062da99729601601b9a8382b11cae768", size = 5114, upload-time = "2026-11-03T16:26:32.731Z" }, +] + [[package]] name = "nodeenv" version = "1.11.0" @@ -321,6 +576,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/99/d5/4ad4ed31413c301430918e70d3d38ae6f097af0766cb9ab8c9d502b2a4d6/ruff-0.17.3-py3-none-win_arm64.whl", hash = "sha256:81fce74bcd6be0e9da7c67c7553fd0f1f12964a2052cd728ef917b937a5ca1d9", size = 9854332, upload-time = "2026-10-27T00:34:03.847Z" }, ] +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f6/cc/6253133b5bb138fc3306cebfbda2c520f545d36b5be2c7255cc528bb45d6/typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", size = 113555, upload-time = "2026-07-02T08:40:05.92Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8", size = 45571, upload-time = "2026-07-02T08:40:04.659Z" }, +] + [[package]] name = "virtualenv" version = "21.14.13"