Skip to content

templates: add a flat template - #29

Open
eunomie wants to merge 1 commit into
dagger:mainfrom
eunomie:python-sdk-flat-template
Open

eunomie wants to merge 1 commit into
dagger:mainfrom
eunomie:python-sdk-flat-template

Conversation

@eunomie

@eunomie eunomie commented Sep 16, 2026

Copy link
Copy Markdown
Member

dagger module init python --name my-module --template flat writes the module's code as a single file at the module root, <package>.py, instead of src/<package>/__init__.py. The example module is the one the default template writes, so the two templates differ only in layout. --template still defaults to default.

The template builds with hatchling rather than uv_build. uv_build packages a directory module only: with module-root = "" it looks for <package>/__init__.py at the root and refuses a root-level <package>.py. A root-level package directory would in turn match neither glob the runtimes use to find a module's Python files, hasPythonFiles in runtime/build.dang and src/**/*.py|*.py in the engine's builtin runtime, so it would need a change on both sides. A single root-level file matches both globs, and hatchling derives it from [project] name with no further configuration, so the flat template needs no runtime change.

`dagger module init python --name my-module --template flat` writes the
module's code as a single file at the module root, `<package>.py`, instead of
`src/<package>/__init__.py`. The example module is the one the default
template writes, so the two templates differ only in layout. `--template`
still defaults to `default`.

The template builds with hatchling rather than uv_build. uv_build packages a
directory module only: with `module-root = ""` it looks for
`<package>/__init__.py` at the root and refuses a root-level `<package>.py`.
A root-level package directory would in turn match neither glob the runtimes
use to find a module's Python files, `hasPythonFiles` in runtime/build.dang
and `src/**/*.py|*.py` in the engine's builtin runtime, so it would need a
change on both sides. A single root-level file matches both globs, and
hatchling derives it from `[project] name` with no further configuration, so
the flat template needs no runtime change.

Signed-off-by: Yves Brissaud <yves@dagger.io>
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