Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 67 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ uvx repoplone settings sanity-check
See [Migrating from specification 1](#migrating-from-specification-1) for everything the command changes. Before committing the result, review the following:

- **Release step ids.** A specification 2 file accepts only `release_python` and `release_node`. The command renames them in `[repository.release]`. Update any script or CI job that passes `--start-step release_backend` or `release_frontend` too. `--start-step` still accepts the old ids, but the new ones are the names to use from now on.
- **Changelog headings.** Package sections in the repository changelog are titled with the package name instead of `Backend` / `Frontend`. Add `section = "Backend"` or `section = "Frontend"` to a `[[package]]` entry to keep the old heading.
- **Changelog headings.** Package sections in the repository changelog are titled with the package name instead of `Backend` / `Frontend`. Add `towncrier.section = "Backend"` or `towncrier.section = "Frontend"` to a `[[package]]` entry to keep the old heading.
- **Comments.** A comment placed between the end of `[frontend.package]` and the next table may be dropped. The command reports each one so you can restore it.
- **Project release hooks.** `settings.backend` and `settings.frontend` still return the primary package of the `python` and `node` families, so existing `local_step` hooks keep working.

Expand Down Expand Up @@ -489,7 +489,7 @@ primary = true
name = "acme.core"
path = "backend"
changelog = "backend/CHANGELOG.md"
towncrier_settings = "backend/pyproject.toml"
towncrier.section = "Backend"
base_package = "Products.CMFPlone"
publish = true

Expand All @@ -498,7 +498,6 @@ type = "python-plone"
name = "acme.theme"
path = "backend/sources/acme.theme"
changelog = "backend/sources/acme.theme/CHANGELOG.md"
towncrier_settings = "backend/sources/acme.theme/pyproject.toml"
publish = true

[[package]]
Expand All @@ -507,18 +506,19 @@ primary = true
name = "@acme/volto-core"
path = "frontend/packages/volto-core"
changelog = "frontend/packages/volto-core/CHANGELOG.md"
towncrier_settings = "frontend/packages/volto-core/towncrier.toml"
towncrier.settings = "frontend/packages/volto-core/towncrier.toml"
publish = true

[[package]]
type = "node-volto"
name = "@acme/volto-theme"
path = "frontend/packages/volto-theme"
changelog = "frontend/packages/volto-theme/CHANGELOG.md"
towncrier_settings = "frontend/packages/volto-theme/towncrier.toml"
publish = true
```

Here `acme.theme` and `@acme/volto-theme` rely on the [`towncrier` defaults](#the-towncrier-table): their settings file is found in their `path`, and their changelog heading is their name.

A repository that releases a single Python package living at its own root needs no frontend at all:

```toml
Expand All @@ -535,7 +535,7 @@ name = "acme-tool"
path = "."
code_path = "src/acme_tool"
changelog = "CHANGELOG.md"
towncrier_settings = "pyproject.toml"
towncrier.settings = "pyproject.toml"
publish = true
```

Expand Down Expand Up @@ -569,13 +569,66 @@ Mark it with `primary = true`. When a family marks none, the first one in the fi
| `name` | Package name, as published to PyPI or npm. |
| `path` | Path to the package, relative to the repository root. Use `"."` for a package that *is* the repository. |
| `changelog` | Path to the package changelog. |
| `towncrier_settings` | Path to the package Towncrier settings. |
| `towncrier` | News fragment settings: `settings` and `section`. See [The `towncrier` table](#the-towncrier-table). |
| `code_path` | Path to the source code, relative to `path`. |
| `publish` | Whether to publish this package to its registry. |
| `primary` | Marks the primary package of its family. |
| `section` | Heading for this package in the repository changelog. Defaults to its name. |
| `base_package` | Package this one builds on. Only meaningful on a family's primary package. |

### The `towncrier` table

The news fragments of a repository are configured with a `towncrier` table. The same table is used in two places, with the same two keys:

| Key | Description |
|------------|-----------------------------------------------------------------------------|
| `settings` | Path to the Towncrier settings file, relative to the repository root. |
| `section` | Heading for these news fragments in the repository changelog. |

What changes between the two places is the defaults.

**In a `[[package]]` entry**, the table is optional:

- `settings` defaults to the file Towncrier itself would use in the package `path`: `towncrier.toml` if it exists, otherwise `pyproject.toml`.
- `section` defaults to the package `name`.

A package that follows the usual layout needs no Towncrier lines at all. Set only what differs:

```toml
[[package]]
type = "python-plone"
name = "acme.core"
path = "backend"
changelog = "backend/CHANGELOG.md"
towncrier.section = "Backend"
```

**In `[repository]`**, the table is opt-in: a `[repository.towncrier]` table turns the repository-level news fragments on, and leaving it out turns them off.

- `settings` defaults to `towncrier.toml`.
- `section` defaults to `"Project"`.

```toml
[repository.towncrier]
```

TOML offers three spellings of the same table, and all of them work:

```toml
# Dotted keys
towncrier.settings = "backend/pyproject.toml"
towncrier.section = "Backend"

# An inline table
towncrier = { settings = "backend/pyproject.toml", section = "Backend" }

# A sub-table, after the package's other keys
[package.towncrier]
settings = "backend/pyproject.toml"
section = "Backend"
```

A misspelled key, an empty value, or `enabled` in `[repository.towncrier]` is an error rather than a silent fall back to the default.

### What changed from specification 1

| Specification 1 | Specification 2 |
Expand All @@ -584,7 +637,9 @@ Mark it with `primary = true`. When a family marks none, the first one in the fi
| `compose` as a string or a list | a list |
| `repository.managed_by_uv`, `backend.path`, `frontend.path` | removed |
| release steps `release_backend`, `release_frontend`| `release_python`, `release_node` |
| changelog sections titled `Backend` / `Frontend` | titled with the package name, unless `section` says otherwise |
| `towncrier_settings` and `section` on a package | `towncrier.settings` and `towncrier.section`, both optional |
| `repository.towncrier.enabled` | removed: the table being present turns it on |
| changelog sections titled `Backend` / `Frontend` | titled with the package name, unless `towncrier.section` says otherwise |

The release step ids are user-facing, so the rename is gradual: a specification 1 file accepts either spelling, a specification 2 file accepts only the new ones, and `--start-step` always accepts both.

Expand All @@ -606,12 +661,14 @@ The command rewrites `repository.toml` in place, preserving comments and formatt
- turns each component's package table into a `[[package]]` entry, with its `type` and `primary = true`
- normalizes `compose` to a list
- removes the deprecated `repository.managed_by_uv`, `backend.path` and `frontend.path`
- moves each package's `towncrier_settings` and `section` into its `towncrier` table, written as `towncrier.settings` and `towncrier.section`
- removes `repository.towncrier.enabled`, and removes a `[repository.towncrier]` table that names no `settings` file, since specification 1 treated it as off
- renames the release step ids
- leaves tables it does not own, such as `[cookieplone]`, alone

Every change is reported. Use `--dry-run` to print the result without writing it, and `--path` to migrate a file other than the detected one.

The command does **not** add `section` options to keep the old `Backend` / `Frontend` changelog headings — migrating is the deliberate moment those become package names. It says so, and adding `section = "Backend"` to a package restores the old heading.
The command does **not** add `towncrier.section` options to keep the old `Backend` / `Frontend` changelog headings — migrating is the deliberate moment those become package names. It says so, and adding `towncrier.section = "Backend"` to a package restores the old heading.

## Contribute 🤝

Expand Down
1 change: 1 addition & 0 deletions news/112.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In a specification 2 `repository.toml`, a package's Towncrier options move into a `towncrier` table, the same one `[repository.towncrier]` uses: write `towncrier.settings` and `towncrier.section` instead of `towncrier_settings` and `section`. Both are optional in a package: the settings file defaults to the `towncrier.toml` or `pyproject.toml` found in the package path, and the heading to the package name. A `[repository.towncrier]` table now turns the repository-level news fragments on by being present, with `towncrier.toml` and `Project` as defaults, and no longer accepts `enabled`. `repoplone settings migrate` writes the new form. @ericof
2 changes: 1 addition & 1 deletion repository.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ name = "repoplone"
path = "."
code_path = "src/repoplone"
changelog = "CHANGELOG.md"
towncrier_settings = "pyproject.toml"
towncrier.settings = "pyproject.toml"
# Published by .github/workflows/release.yml (trusted publishing).
publish = false
39 changes: 17 additions & 22 deletions src/repoplone/schemas/repository-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,30 @@
"type": "string"
},
"managed_by_uv": false,
"towncrier": { "$ref": "#/$defs/repositoryTowncrier" },
"towncrier": {
"$ref": "#/$defs/towncrier",
"description": "Repository-level news fragments. Present means enabled: settings defaults to towncrier.toml and section to \"Project\"."
},
"release": { "$ref": "#/$defs/release" }
},
"additionalProperties": true
},
"repositoryTowncrier": {
"towncrier": {
"type": "object",
"description": "Repository-level towncrier settings.",
"description": "Towncrier settings, used by [repository.towncrier] and by each [[package]].",
"properties": {
"enabled": {
"description": "Whether the repository-level towncrier is enabled. Derived from the presence of this table.",
"type": "boolean"
"settings": {
"description": "Path to the towncrier settings file, relative to the repository root.",
"type": "string",
"minLength": 1
},
"section": {
"description": "Heading used for this section in the repository changelog.",
"type": "string"
},
"settings": {
"description": "Path to the towncrier settings file.",
"type": "string"
"type": "string",
"minLength": 1
}
},
"additionalProperties": true
"additionalProperties": false
},
"release": {
"type": "object",
Expand Down Expand Up @@ -159,7 +160,7 @@
"package": {
"type": "object",
"description": "One package released from this repository. The language prefix of `type` decides how the package is built and published; the ecosystem suffix decides which extra keys apply.",
"required": ["type", "name", "path", "changelog", "towncrier_settings"],
"required": ["type", "name", "path", "changelog"],
"properties": {
"type": {
"description": "Kind of package. `backend` and `frontend` are deprecated aliases for python-plone and node-volto, accepted so a hand-migrated file still loads; `repoplone settings migrate` writes the canonical names.",
Expand Down Expand Up @@ -188,10 +189,9 @@
"type": "string",
"minLength": 1
},
"towncrier_settings": {
"description": "Path to the package towncrier settings, relative to the repository root.",
"type": "string",
"minLength": 1
"towncrier": {
"$ref": "#/$defs/towncrier",
"description": "News fragments of this package. Optional: settings defaults to the first of towncrier.toml and pyproject.toml found in the package path, as towncrier itself looks them up, and section to the package name."
},
"code_path": {
"description": "Path to the source code, relative to the package path.",
Expand All @@ -205,11 +205,6 @@
"description": "Marks this package as the primary one of its family. At most one per family; the first in document order is primary when none is marked.",
"type": "boolean"
},
"section": {
"description": "Heading used for this package in the repository changelog. Defaults to the package name.",
"type": "string",
"minLength": 1
},
"base_package": {
"description": "Package this one builds on, whose version repoplone tracks. Only meaningful on the primary package of a family.",
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion src/repoplone/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _get_settings(cwd_path: Path) -> t.RepositorySettings:
version: str = version_path.read_text().strip()
version_format: str = repository.get("version_format", "semver")
compose_path: list[Path] = _get_compose_path(root_path, raw_settings)
repository_towncrier: dict = repository.get("towncrier", {})
repository_towncrier: dict | None = repository.get("towncrier", None)
packages = _get_packages(root_path, raw_settings, spec_version)
backend = _family_primary(root_path, raw_settings, packages, t.FAMILY_PYTHON)
managed_by_uv = backend.managed_by_uv
Expand Down
70 changes: 65 additions & 5 deletions src/repoplone/settings/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#: Keys that never belonged on a package table.
DROPPED_PACKAGE_KEYS: tuple[str, ...] = ("enabled",)

#: Flat spec 1 package keys, mapped to their key in the ``towncrier`` table.
TOWNCRIER_PACKAGE_KEYS: dict[str, str] = {
"towncrier_settings": "settings",
"section": "section",
}


class MigrationError(RepoPloneException):
"""Raised when a ``repository.toml`` cannot be migrated."""
Expand All @@ -57,11 +63,63 @@ def _package_entries(document: tomlkit.TOMLDocument) -> list[tomlkit.items.Table
for key, value in package.items():
if key in DROPPED_PACKAGE_KEYS:
continue
if key in TOWNCRIER_PACKAGE_KEYS:
_add_towncrier_key(entry, TOWNCRIER_PACKAGE_KEYS[key], value)
continue
entry[key] = value
entries.append(entry)
return entries


def _add_towncrier_key(entry: tomlkit.items.Table, key: str, value: object) -> None:
"""Write one key of a package's ``towncrier`` table, as a dotted key.

``towncrier.settings = ...`` keeps the setting next to the package's other
keys, where a ``[package.towncrier]`` sub-table would move it below them.
An empty value is left out, so the spec 2 default applies.

:param entry: The ``[[package]]`` entry being built.
:param key: Key inside the ``towncrier`` table.
:param value: The spec 1 value.
"""
if not str(value or "").strip():
return
entry.append(tomlkit.key(["towncrier", key]), value)


def _migrate_repository_towncrier(document: tomlkit.TOMLDocument) -> list[str]:
"""Rewrite ``[repository.towncrier]`` for spec 2.

Spec 1 turned the table on only when it named a settings file; spec 2
turns it on by being present. A spec 1 table without ``settings`` was
therefore off, and is removed so it stays off. ``enabled`` is no longer
part of the table.

:param document: Parsed ``repository.toml``.
:returns: One note per change.
"""
repository = document.get("repository", None)
if repository is None or "towncrier" not in repository:
return []
table = repository["towncrier"]
if not str(table.get("settings", "") or "").strip():
notes = [
"Removed [repository.towncrier]: it named no settings file, so it "
"was off. In spec 2 the table being present turns it on."
]
if isinstance(table, tomlkit.items.Table):
notes.extend(
f"Dropped a comment that followed [repository.towncrier]: {comment}"
for comment in _trailing_comments(table)
)
del repository["towncrier"]
return notes
if "enabled" in table:
del table["enabled"]
return ["Removed repository.towncrier.enabled"]
return []


def _normalize_compose(document: tomlkit.TOMLDocument) -> bool:
"""Turn a bare ``compose`` string into a list.

Expand Down Expand Up @@ -205,6 +263,7 @@ def migrate_document(document: tomlkit.TOMLDocument) -> list[str]:
if _normalize_compose(document):
notes.append("Turned repository.compose into a list")
notes.extend(_rename_steps(document))
notes.extend(_migrate_repository_towncrier(document))

notes.extend(_remove_components(document))

Expand Down Expand Up @@ -236,24 +295,25 @@ def changelog_heading_note(document: tomlkit.TOMLDocument) -> str:
"""Return the warning about changelog headings changing, if it applies.

Migrating is the deliberate moment section titles become package names.
Writing ``section`` keys to preserve the old headings would pin spec 1
behaviour into every migrated file, so the change is reported instead.
Writing ``towncrier.section`` keys to preserve the old headings would pin
spec 1 behaviour into every migrated file, so the change is reported
instead.

:param document: Migrated ``repository.toml``.
:returns: The note, or an empty string when no package would change.
"""
names = [
str(entry["name"])
for entry in document.get("package", [])
if not entry.get("section", "")
if not (entry.get("towncrier", None) or {}).get("section", "")
]
if not names:
return ""
listed = ", ".join(names)
return (
f"Changelog sections will now be titled {listed}, rather than "
f'Backend / Frontend. Add `section = "Backend"` to a package to keep '
f"the old heading."
f'Backend / Frontend. Add `towncrier.section = "Backend"` to a package '
f"to keep the old heading."
)


Expand Down
Loading