Skip to content

Fix template for library packages#1

Merged
JoshCLWren merged 6 commits into
mainfrom
fix/template-library-support
Mar 16, 2026
Merged

Fix template for library packages#1
JoshCLWren merged 6 commits into
mainfrom
fix/template-library-support

Conversation

@JoshCLWren

@JoshCLWren JoshCLWren commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Phase 0 of package consolidation plan.

Changes:

  • Add [build-system] with hatchling so uv build works
  • Add [tool.hatch.build.targets.wheel] packages config
  • Fix make init to handle hyphenated names (dir uses _, project name uses -)
  • Fix make init to update ci.yml coverage module name
  • Fix make init to remove template main.py for library packages
  • Switch [project.optional-dependencies] dev to [dependency-groups] dev
  • Add authors, license fields to pyproject.toml
  • Add __version__ to __init__.py
  • Remove libvips/xvfb/unar from CI setup action (leftover from another project)

Verified: make init NAME=longbox-commons → clean project that passes uv build + uv pip install .

Summary by CodeRabbit

  • Build & Infrastructure

    • Reduced system-level package installs, switched dependency sync to a dev-group workflow, and added Hatch-based build config.
  • New Features

    • Exposed package version via a module-level version identifier.
  • Documentation

    • Added CHANGELOG, post-init checklist, template guide, updated README and agent guidance; introduced placeholders for project naming.
  • Chores

    • Updated project metadata (license, author) and improved initialization messaging.

- Add [build-system] with hatchling
- Add [tool.hatch.build.targets.wheel] packages config
- Fix make init to handle hyphenated names (dir uses _, name uses -)
- Fix make init to update ci.yml coverage module name
- Fix make init to remove template main.py for library packages
- Switch [project.optional-dependencies] dev to [dependency-groups] dev
- Add authors, license fields to pyproject.toml
- Add __version__ to __init__.py
- Remove libvips/xvfb/unar from CI setup action
- Update sync commands from --all-extras to --group dev

Amp-Thread-ID: https://ampcode.com/threads/T-019cec73-4e6a-732e-acf1-30c4bfec4195
Co-authored-by: Amp <amp@ampcode.com>
@coderabbitai

coderabbitai Bot commented Mar 14, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@JoshCLWren has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 57b128ee-99c7-4c3c-b39a-a2500eec8919

📥 Commits

Reviewing files that changed from the base of the PR and between a4733f0 and 7535869.

📒 Files selected for processing (4)
  • .github/actions/setup/action.yml
  • POST_INIT_CHECKLIST.md
  • README.md
  • TEMPLATE_GUIDE.md
📝 Walkthrough

Walkthrough

Makefile init now derives PKG_DIR from NAME and renames package; pyproject switches to Hatchling and adds a dev dependency group; CI/setup action adjusts system packages and uses uv sync --group dev; example_module.__init__ adds __version__; extensive template docs and post-init checklist added.

Changes

Cohort / File(s) Summary
CI / Action
.github/actions/setup/action.yml, .github/workflows/ci.yml
Adjusted system packages (removed several, added libatomic1/gnupg), changed dependency sync to uv sync --group dev, and added a TODO comment about CODECOV_TOKEN.
Makefile / Init flow
Makefile
Init flow derives PKG_DIR from NAME, renames package dir and references, conditionally removes template main.py, and updates messages and install guidance to use PKG_DIR and uv sync --group dev.
Build config
pyproject.toml
Switched build backend to Hatchling ([build-system]), added license/authors, added Hatch wheel target, and introduced a [dependency-groups] dev group with development tools.
Package code
example_module/__init__.py
Added __version__ = "0.1.0" at module level.
Docs & Onboarding
README.md, AGENTS.md, TEMPLATE_GUIDE.md, POST_INIT_CHECKLIST.md, CHANGELOG.md
Added template banners, placeholder [[MODULE_NAME]] usage, post-init checklist and template guide, changelog, and broadened onboarding/dev workflow documentation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through files with a keen little grin,
PKG_DIR renamed where new journeys begin,
Hatchling lent wings, dev-groups took the stage,
Docs and checklists now guide the next page,
Cheers — nibble the carrots, then ship from the bin! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix template for library packages' directly relates to the main objectives: adding build system configuration, fixing make init for package initialization, and preparing the template for library packages with proper build support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/template-library-support
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Makefile (1)

53-54: ⚠️ Potential issue | 🟡 Minor

The run target will fail after init removes main.py.

For library packages, main.py is deleted during initialization (lines 25-28), but the run target still references it. Consider removing this target or documenting that it's only for application templates.

🛠️ Option: Remove run target for library template
 venv:  ## Create virtual environment
 	uv venv
-
-run:  ## Run the app
-	python main.py

Or update the help text to clarify it's for application templates only.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Makefile` around lines 53 - 54, The Makefile's run target (run:) still
executes python main.py but init removes main.py for library templates, causing
run to fail; update the Makefile by either removing the run target entirely for
library templates or conditionally document/guard it so it only exists for
application templates—modify the run target or the init logic and the Makefile
help text to ensure run does not reference main.py when init deletes it, and
mention the change near the init and run target declarations to keep behavior
consistent.
🧹 Nitpick comments (1)
example_module/__init__.py (1)

2-3: Consider using dynamic versioning to avoid dual maintenance.

The version "0.1.0" is now defined in both __init__.py and pyproject.toml. When bumping versions, both files must be updated in sync.

Hatchling supports reading the version from __version__ dynamically. Alternatively, this dual-source approach is acceptable if you prefer explicit control in the template.

♻️ Optional: Configure dynamic versioning in pyproject.toml
 [project]
 name = "python-starter-template"
-version = "0.1.0"
+dynamic = ["version"]
 description = "Python starter template with best practices"

And add:

[tool.hatch.version]
path = "example_module/__init__.py"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@example_module/__init__.py` around lines 2 - 3, The package version is
duplicated: __version__ is hardcoded in __init__.py while pyproject.toml
contains the canonical version; switch to dynamic versioning by configuring
Hatch to read the package's __version__ (i.e., add a [tool.hatch.version] entry
that points at your package to use the __version__ symbol) so you only maintain
the version in one place, or conversely remove the duplicate from pyproject.toml
and keep the single source as __version__ in __init__.py — update the
pyproject.toml Hatch config accordingly to reference the __version__ symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@Makefile`:
- Around line 53-54: The Makefile's run target (run:) still executes python
main.py but init removes main.py for library templates, causing run to fail;
update the Makefile by either removing the run target entirely for library
templates or conditionally document/guard it so it only exists for application
templates—modify the run target or the init logic and the Makefile help text to
ensure run does not reference main.py when init deletes it, and mention the
change near the init and run target declarations to keep behavior consistent.

---

Nitpick comments:
In `@example_module/__init__.py`:
- Around line 2-3: The package version is duplicated: __version__ is hardcoded
in __init__.py while pyproject.toml contains the canonical version; switch to
dynamic versioning by configuring Hatch to read the package's __version__ (i.e.,
add a [tool.hatch.version] entry that points at your package to use the
__version__ symbol) so you only maintain the version in one place, or conversely
remove the duplicate from pyproject.toml and keep the single source as
__version__ in __init__.py — update the pyproject.toml Hatch config accordingly
to reference the __version__ symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 58120ce8-5b64-48d5-959d-e16635fa278a

📥 Commits

Reviewing files that changed from the base of the PR and between 5b3bc09 and e5c1645.

📒 Files selected for processing (4)
  • .github/actions/setup/action.yml
  • Makefile
  • example_module/__init__.py
  • pyproject.toml

Automated fixes applied by ralph_loop.sh
Model: zai-coding-plan/glm-4.7
Phase: 0
Add warning banners to README.md and AGENTS.md to clearly indicate template
files that need manual updates after initialization. Replace hardcoded
"example_module" references with [[MODULE_NAME]] placeholders for easier
customization. Create comprehensive POST_INIT_CHECKLIST.md and
TEMPLATE_GUIDE.md to guide users through the initialization process.

Enhance make init output with detailed summary of automated changes and
manual updates required. Add placeholder comments in CI workflow and update
CHANGELOG.md to document template improvements.

This addresses confusion about placeholder text and unclear instructions
by making it explicit what needs to be updated after running make init.
@codecov

codecov Bot commented Mar 16, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
README.md (2)

40-40: ⚠️ Potential issue | 🟠 Major

Quick Start/Daily commands reference removed file.

Lines 40 and 68 run python main.py after initialization, but library init removes main.py. This is a broken default path for first-time users.

Suggested doc fix
-# Run your application
-python main.py --name World --value 42
+# Run tests (library default workflow)
+pytest

Also applies to: 68-68

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 40, The README still instructs users to run "python
main.py" which no longer exists after the library initialization; update both
occurrences (the example at line ~40 and the one at ~68) to the correct runtime
invocation for this project (e.g., replace "python main.py --name World --value
42" with the actual entrypoint such as "python -m <module_name> --name World
--value 42" or the new script name), and ensure the Quick Start example matches
the package's current entrypoint or installation instructions so first-time
users can run the app successfully.

31-31: ⚠️ Potential issue | 🟠 Major

Fix uv sync command to use --group instead of --all-extras.

Lines 31 and 54 use uv sync --all-extras, but the project uses [dependency-groups] in pyproject.toml. The --all-extras flag doesn't apply to dependency groups, so this command won't install test/lint tools from the dev group. Use uv sync --group dev instead.

Suggested fix
-uv sync --all-extras
+uv sync --group dev

Also applies to: 54-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 31, Replace the incorrect use of the Poetry/uvicorn sync
flag: find occurrences of the command string "uv sync --all-extras" (used in
README examples) and change them to use the dependency-group flag for the dev
group, i.e. "uv sync --group dev"; update both occurrences (the ones noted
around the README examples) so the dev dependency group from pyproject.toml is
installed correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/actions/setup/action.yml:
- Around line 10-11: The CI step runs apt-get as a non-root user and must use
sudo; update the action.yml step that contains the two commands "apt-get update
-qq" and "apt-get install -y -qq ca-certificates curl git python3 python3-venv
libatomic1 gnupg" to prepend sudo to both invocations so the package
update/install runs with elevated privileges in GitHub-hosted runners.

In `@AGENTS.md`:
- Line 6: Update the AGENTS.md guidance that currently assumes a main.py
entrypoint: where text mentions "The entrypoint is `main.py`" (and the similar
reference later) change it to explain that `make init` may remove main.py for
library packages and that the module directory may be a library without an
entrypoint; state the default behaviors for apps versus libraries (e.g., apps
use `main.py` as entrypoint, libraries have no entrypoint and should expose
package API) and mention contributors should create a new package directory or
add an entrypoint if they need CLI/startup files.

In `@CHANGELOG.md`:
- Line 35: Replace the placeholder date in the release header "## [0.1.0] -
2024-01-XX" with a concrete ISO date (e.g., "## [0.1.0] - 2024-01-15") or remove
the date portion entirely (leaving "## [0.1.0]") if the release date is not yet
finalized; update the header text in CHANGELOG.md where the string "## [0.1.0] -
2024-01-XX" appears.

In `@POST_INIT_CHECKLIST.md`:
- Around line 24-27: The checklist's example for replacing `[[MODULE_NAME]]` is
confusing because it repeats `my_project` and omits a hyphenated project-name
example; update the example under the "Replace `[[MODULE_NAME]]` references"
bullet so it shows both forms (e.g., project name with hyphen like `my-project`
and package/module directory name like `my_project`) and clarify which form is
used where, referencing the `[[MODULE_NAME]]` placeholder text and the example
text currently showing `my_project`.

In `@README.md`:
- Line 95: Update the README line that currently reads "├── [[MODULE_NAME]]/    
# Main package (rename via make init)" to clarify that placeholder replacement
is a manual step: change the parenthetical to something like "(replace
[[MODULE_NAME]] manually as described in the init checklist)" or point to the
specific "init" checklist/section; reference the exact token [[MODULE_NAME]] and
the phrase "make init" so reviewers can find and update the README entry and any
related init instructions to avoid implying automatic renaming.

In `@TEMPLATE_GUIDE.md`:
- Around line 84-86: The guide currently tells users to run "python main.py"
after initialization but earlier sections (and later notes) indicate main.py is
removed for library-package setups, causing a dead-end; update TEMPLATE_GUIDE.md
to either remove the "python main.py" run step or make it conditional by
checking the project type (e.g., add text like "If this is an application with
an entrypoint, run `python main.py`; if you initialized a library/package (no
main.py), skip this step and follow the publishing or import instructions"), and
reference the entrypoint filename "main.py" and the
initialization/library-package notes so the doc flow remains consistent.
- Around line 117-140: Update the fenced code block that shows the project tree
in TEMPLATE_GUIDE.md to include a language specifier (use "text") after the
opening triple backticks so markdownlint MD040 is satisfied; locate the block
that begins with ``` and the directory tree (python-starter-template/ ...
TEMPLATE_GUIDE.md) and change the opening fence to ```text.
- Around line 52-53: Update the command recommendation in TEMPLATE_GUIDE.md:
replace the existing "uv sync --all-extras" suggestion with guidance to run "uv
sync" for the default dev group, or "uv sync --all-groups" (or "uv sync --group
<name>") when you need dependency groups beyond extras; ensure the doc text
around the uv sync invocation explains that --all-extras only installs extras
and will skip packages declared under [dependency-groups].

---

Outside diff comments:
In `@README.md`:
- Line 40: The README still instructs users to run "python main.py" which no
longer exists after the library initialization; update both occurrences (the
example at line ~40 and the one at ~68) to the correct runtime invocation for
this project (e.g., replace "python main.py --name World --value 42" with the
actual entrypoint such as "python -m <module_name> --name World --value 42" or
the new script name), and ensure the Quick Start example matches the package's
current entrypoint or installation instructions so first-time users can run the
app successfully.
- Line 31: Replace the incorrect use of the Poetry/uvicorn sync flag: find
occurrences of the command string "uv sync --all-extras" (used in README
examples) and change them to use the dependency-group flag for the dev group,
i.e. "uv sync --group dev"; update both occurrences (the ones noted around the
README examples) so the dev dependency group from pyproject.toml is installed
correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 43699b56-b5f7-4e2b-9979-94db9c089f4a

📥 Commits

Reviewing files that changed from the base of the PR and between e5c1645 and 9760984.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .github/actions/setup/action.yml
  • .github/workflows/ci.yml
  • AGENTS.md
  • CHANGELOG.md
  • Makefile
  • POST_INIT_CHECKLIST.md
  • README.md
  • TEMPLATE_GUIDE.md
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/ci.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • Makefile

Comment thread .github/actions/setup/action.yml
Comment thread AGENTS.md Outdated
Comment thread CHANGELOG.md Outdated
Comment thread POST_INIT_CHECKLIST.md
Comment thread README.md Outdated
Comment thread TEMPLATE_GUIDE.md Outdated
Comment thread TEMPLATE_GUIDE.md Outdated
Comment on lines +84 to +86
# Run your application (if you have an entrypoint)
python main.py
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Contradictory entrypoint guidance after initialization.

Line 85 instructs python main.py, but Lines 100 and 132 indicate main.py is removed for library-package initialization. This will produce a dead-end flow immediately after setup.

Suggested doc fix
-# Run your application (if you have an entrypoint)
-python main.py
+# Run your package tests (library default)
+pytest
+
+# If you later add an entrypoint script, run that script instead.

Also applies to: 100-100, 132-132

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@TEMPLATE_GUIDE.md` around lines 84 - 86, The guide currently tells users to
run "python main.py" after initialization but earlier sections (and later notes)
indicate main.py is removed for library-package setups, causing a dead-end;
update TEMPLATE_GUIDE.md to either remove the "python main.py" run step or make
it conditional by checking the project type (e.g., add text like "If this is an
application with an entrypoint, run `python main.py`; if you initialized a
library/package (no main.py), skip this step and follow the publishing or import
instructions"), and reference the entrypoint filename "main.py" and the
initialization/library-package notes so the doc flow remains consistent.

Comment thread TEMPLATE_GUIDE.md Outdated
- Add sudo to apt-get commands in CI action.yml
- Clarify main.py entrypoint behavior for apps vs libraries in AGENTS.md
- Fix uv sync commands to use --group dev instead of --all-extras
- Replace placeholder date in CHANGELOG.md
- Improve MODULE_NAME example with hyphenated project names
- Clarify [[MODULE_NAME]] is manually replaced in README.md
- Make python main.py execution conditional in docs
- Add language specifier to code fence in TEMPLATE_GUIDE.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

106-106: ⚠️ Potential issue | 🟡 Minor

Make main.py note consistent with library-default flow.

Line 106 presents main.py as a standard file, but library initialization removes it by default. Consider annotating this line similarly to other sections (e.g., “entrypoint for apps; removed for library packages”).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 106, Update the README entry for main.py to match the
library-default flow by annotating it as an application entrypoint that is
removed for library packages; specifically modify the line referencing "main.py"
(the symbol main.py) to read something like "main.py — application entrypoint;
removed for library packages" so it matches the other section annotations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@POST_INIT_CHECKLIST.md`:
- Line 8: Update the checklist line that currently reads "✅ Renames the module
directory from `example_module` to your project name" to clarify that package
directory names are underscore-normalized for hyphenated project names (e.g.,
"my-project" → "my_project") and make the wording consistent with the later
phrasing used elsewhere in the document (match the language that explains
hyphen-to-underscore normalization).

In `@TEMPLATE_GUIDE.md`:
- Line 43: Update the phrasing that references the package directory to say
"package directory/module name" instead of implying the directory is the exact
project name, and add an explicit hyphen-to-underscore example such as
"my-project → my_project"; reference the existing wording around
`example_module` and the sentence at lines 43 and 97 to replace the ambiguous
text and insert the `my-project` → `my_project` example for consistency.

---

Outside diff comments:
In `@README.md`:
- Line 106: Update the README entry for main.py to match the library-default
flow by annotating it as an application entrypoint that is removed for library
packages; specifically modify the line referencing "main.py" (the symbol
main.py) to read something like "main.py — application entrypoint; removed for
library packages" so it matches the other section annotations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 134fa7c6-1be1-4528-bd91-751ded76e665

📥 Commits

Reviewing files that changed from the base of the PR and between 9760984 and a4733f0.

📒 Files selected for processing (6)
  • .github/actions/setup/action.yml
  • AGENTS.md
  • CHANGELOG.md
  • POST_INIT_CHECKLIST.md
  • README.md
  • TEMPLATE_GUIDE.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/actions/setup/action.yml

Comment thread POST_INIT_CHECKLIST.md Outdated
Comment thread TEMPLATE_GUIDE.md Outdated
Debian containers run as root by default, so sudo is not available.
Reverting previous change that added sudo to apt-get commands.
- Clarify that hyphenated project names are normalized to underscores in package directory names
- Add explicit example (my-project → my_project) in POST_INIT_CHECKLIST.md and TEMPLATE_GUIDE.md
- Update main.py annotation to note it's removed for library packages
@JoshCLWren JoshCLWren merged commit 8e7ca02 into main Mar 16, 2026
4 checks passed
@JoshCLWren JoshCLWren deleted the fix/template-library-support branch March 16, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant