From e5e57b90b9577b63111512b8aac43c442555f0d0 Mon Sep 17 00:00:00 2001 From: TDV Alinsa Date: Wed, 30 Sep 2026 14:43:01 -0700 Subject: [PATCH 1/6] ci: build and publish to PyPI via GitHub Actions on tag push --- .github/workflows/publish.yml | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..1f89432 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,69 @@ +name: Build and publish + +on: + push: + tags: + - "v*" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # setuptools_scm needs full history and tags to compute the version + fetch-depth: 0 + + - uses: astral-sh/setup-uv@v6 + + - name: Run tests + run: uv run --extra tests pytest + + - name: Build sdist and wheel + run: uv build + + - name: Check distribution metadata + run: uv tool run twine check dist/* + + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + + publish-testpypi: + needs: build + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/tdvutil + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true + + publish-pypi: + # only publish to real PyPI for tag pushes, not manual runs + if: startsWith(github.ref, 'refs/tags/v') + needs: publish-testpypi + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/tdvutil + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - uses: pypa/gh-action-pypi-publish@release/v1 From 1206dae723d074b0aabca347d2481aeca16fd6e1 Mon Sep 17 00:00:00 2001 From: TDV Alinsa Date: Wed, 30 Sep 2026 16:02:17 -0700 Subject: [PATCH 2/6] docs: add README --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/README.md b/README.md index e69de29..da021dc 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,55 @@ +# tdvutil + +A grab bag of little Python helpers I kept copy-pasting between projects, so +I finally stuck them in one place. + +**Heads up:** this is mostly here for my own convenience. You're welcome to +use it, but I make no promises about keeping the API stable. Things can and +will get renamed, changed, or ripped out whenever it suits me, even in minor +releases. If you depend on it, pin a version. + +## Installing + +```sh +pip install tdvutil +``` + +Needs Python 3.9+. + +## What's in here + +From `tdvutil` directly: + +- `ppretty`: pretty-prints objects +- `alintrospect` / `whatis`: a very janky way to poke at an object's class + hierarchy and see where its methods and attributes come from +- `now` / `nowf`: current time, with less typing +- `pathfix`: path cleanup +- `sec_to_hms`, `sec_to_timecode`, `sec_to_shortstr`, `hms_to_sec`, + `timecode_to_sec`: converting between seconds and human-readable times + +Plus a couple of submodules: + +- `tdvutil.argparse`: `CheckFile` and `NegateAction`, for argparse +- `tdvutil.llmcost`: pricing data for a bunch of LLM models, and a way to + figure out what a call cost + +```python +from tdvutil import sec_to_hms +from tdvutil.llmcost import get_model + +sec_to_hms(3725) # '01:02:05.000' + +cost = get_model("gpt-4o").cost(input_tokens=10_000, output_tokens=2_000) +print(cost.total_cost) # 0.045 +``` + +## Hacking on it + +Uses [uv](https://docs.astral.sh/uv/). `make localdev` sets things up, +`make test` runs the tests, and `make dist` builds. Pushing a `v*` tag makes +GitHub Actions build it and push it to PyPI. + +## License + +GPLv3, see [LICENSE.txt](LICENSE.txt). From c249d6a87a8e7c477c7aaa7e3fd59a6f8d591db6 Mon Sep 17 00:00:00 2001 From: TDV Alinsa Date: Wed, 30 Sep 2026 16:02:21 -0700 Subject: [PATCH 3/6] ci: re-enable strict twine check now that README exists --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1f89432..25bb4ea 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,7 +24,7 @@ jobs: run: uv build - name: Check distribution metadata - run: uv tool run twine check dist/* + run: uv tool run twine check --strict dist/* - uses: actions/upload-artifact@v4 with: From 43efc7c55f379724a662d5bc6768e93790b17208 Mon Sep 17 00:00:00 2001 From: TDV Alinsa Date: Wed, 30 Sep 2026 16:17:23 -0700 Subject: [PATCH 4/6] ci: harden publishing workflow and clarify manual releases --- .github/workflows/publish.yml | 27 ++++++++++++++++++--------- README.md | 8 ++++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 25bb4ea..8e97fb1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,19 +6,27 @@ on: - "v*" workflow_dispatch: +permissions: {} + jobs: build: runs-on: ubuntu-latest + permissions: + contents: read steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: # setuptools_scm needs full history and tags to compute the version fetch-depth: 0 + persist-credentials: false - - uses: astral-sh/setup-uv@v6 + - uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0 + with: + version: "0.12.1" + python-version: "3.14.7" - name: Run tests - run: uv run --extra tests pytest + run: uv run --locked --extra tests pytest - name: Build sdist and wheel run: uv build @@ -26,12 +34,14 @@ jobs: - name: Check distribution metadata run: uv tool run twine check --strict dist/* - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: dist path: dist/ publish-testpypi: + # Tag pushes and manual runs on v* tags can publish; branch runs only build. + if: startsWith(github.ref, 'refs/tags/v') needs: build runs-on: ubuntu-latest environment: @@ -40,18 +50,17 @@ jobs: permissions: id-token: write steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: dist path: dist/ - - uses: pypa/gh-action-pypi-publish@release/v1 + - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 with: repository-url: https://test.pypi.org/legacy/ skip-existing: true publish-pypi: - # only publish to real PyPI for tag pushes, not manual runs if: startsWith(github.ref, 'refs/tags/v') needs: publish-testpypi runs-on: ubuntu-latest @@ -61,9 +70,9 @@ jobs: permissions: id-token: write steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: dist path: dist/ - - uses: pypa/gh-action-pypi-publish@release/v1 + - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 diff --git a/README.md b/README.md index da021dc..a960865 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,12 @@ print(cost.total_cost) # 0.045 ## Hacking on it Uses [uv](https://docs.astral.sh/uv/). `make localdev` sets things up, -`make test` runs the tests, and `make dist` builds. Pushing a `v*` tag makes -GitHub Actions build it and push it to PyPI. +`make test` runs the tests, and `make dist` builds. + +Pushing a `v*` tag makes GitHub Actions build it and publish to TestPyPI, +then PyPI. Manually running the workflow on a `v*` tag does the same, +including publishing to real PyPI. Manual branch runs just run the checks +and save the built packages as workflow artifacts; they don't publish. ## License From 7ae7acd8d20768d8ac2dc1334eb4597db802b83f Mon Sep 17 00:00:00 2001 From: TDV Alinsa Date: Wed, 30 Sep 2026 16:37:34 -0700 Subject: [PATCH 5/6] ci: run builds on pull requests and main updates --- .github/workflows/publish.yml | 5 ++++- README.md | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8e97fb1..2a68fb2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,10 @@ name: Build and publish on: + pull_request: + branches: [main] push: + branches: [main] tags: - "v*" workflow_dispatch: @@ -40,7 +43,7 @@ jobs: path: dist/ publish-testpypi: - # Tag pushes and manual runs on v* tags can publish; branch runs only build. + # Tag pushes and manual runs on v* tags can publish; branch and PR runs only build. if: startsWith(github.ref, 'refs/tags/v') needs: build runs-on: ubuntu-latest diff --git a/README.md b/README.md index a960865..548d506 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ print(cost.total_cost) # 0.045 Uses [uv](https://docs.astral.sh/uv/). `make localdev` sets things up, `make test` runs the tests, and `make dist` builds. +GitHub Actions runs the tests and builds packages for PRs targeting `main` +and pushes to `main`, without publishing. Maintainer approval is required +to run outside contributors' PR workflows. + Pushing a `v*` tag makes GitHub Actions build it and publish to TestPyPI, then PyPI. Manually running the workflow on a `v*` tag does the same, including publishing to real PyPI. Manual branch runs just run the checks From f865c35c28e346340038d01cb26010ff50328d0d Mon Sep 17 00:00:00 2001 From: TDV Alinsa Date: Wed, 30 Sep 2026 16:43:29 -0700 Subject: [PATCH 6/6] ci: update uv to support the pinned Python release --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2a68fb2..cb93808 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,7 +25,7 @@ jobs: - uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0 with: - version: "0.12.1" + version: "0.12.21" python-version: "3.14.7" - name: Run tests