wads.version_sync¶
One version number for a Python package and its npm twin (i2mint/wads#210).
A repo that publishes the same code to PyPI and npm lists, in pyproject.toml,
the manifests that carry the Python version too:
[tool.wads.ci.version]
sync = ["ts/package.json"]
Two things follow, both in uv-ci:
Release: right after the publish job bumps
[project].version, it writes that version into each listed manifest (and thepackage-lock.jsonbeside it), so the bump commit carries all of them.Check: the setup job fails when a listed manifest’s version differs from
[project].version, so a hand edit on one side shows up before a release.
And one in npm-ci: npm packs the commit that was pushed, which comes before the
bump commit of the Python release the same push cuts, so it would carry the
previous release’s number with newer code. npm_publish_refusal() refuses
that publish (see its docstring).
package.json (npm) and Cargo.toml (a crate that ships with the Python package, as a
maturin binding crate does) are supported. A Cargo manifest’s version is [package].version,
or [workspace.package].version when the crate inherits it; the Cargo.lock beside it
follows (the crates that take the version: the manifest’s own, and the workspace members that inherit it), so
cargo build --locked still passes. A crate that has its own release line on crates.io
should not be listed. This module imports only the standard library (and wads.ci_config, which
does too), because the CI scripts load it by path from the wads checkout
(wads/scripts/_checkout_import.py).
Module Attributes
Manifest file names |
|
The lockfile npm keeps beside a |
|
A semver version, the only kind npm accepts (PEP 440 forms like |
Functions
|
The repo-relative workflow file in |
|
The version a |
|
Raise |
|
Why npm-ci must not publish |
|
Whether uv-ci's publish job releases to PyPI for a push with this commit |
|
Write |
|
Write |
|
Write |
|
|
|
The manifests |
|
Write |
|
|
- wads.version_sync.NPM_LOCKFILE = 'package-lock.json'¶
The lockfile npm keeps beside a
package.json; its own version fields follow.
- wads.version_sync.SEMVER = re.compile('^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$')¶
A semver version, the only kind npm accepts (PEP 440 forms like
1.0rc1are not).
- wads.version_sync.SYNCABLE_MANIFESTS = ('package.json', 'Cargo.toml')¶
Manifest file names
[tool.wads.ci.version].syncmay list.
- wads.version_sync.caller_workflow_path(workflow_ref)[source]¶
The repo-relative workflow file in
github.workflow_ref;Noneif there is none.In a reusable workflow,
github.workflow_refnames the caller’s file (owner/repo/.github/workflows/npm-ci.yml@refs/heads/main): the npm stub.>>> caller_workflow_path("i2mint/demo/.github/workflows/npm-ci.yml@refs/heads/main") '.github/workflows/npm-ci.yml' >>> caller_workflow_path("") is None True
- wads.version_sync.cargo_version(text)[source]¶
The version a
Cargo.toml’s text declares (see_cargo_version_line()).
- wads.version_sync.check_versions_agree(repo_dir, pyproject_data)[source]¶
Raise
ValueErrornaming every listed manifest whose version differs.- Return type:
- wads.version_sync.npm_publish_refusal(pyproject_data, package_dir, changed_files, subject, *, also_inside=())[source]¶
Why npm-ci must not publish
package_dirfrom this push, orNonewhen it may.It refuses only when all of these hold:
[tool.wads.ci.version].synclists a manifest insidepackage_dir(so its version comes from the Python release);this push also cuts a PyPI release (
pypi_release_expected()), whose bump commit comes after the commit npm packs;the push changes files outside
package_dir(changed_files, repo relative). A push that changes only the npm package publishes the version the last Python release wrote. When the npm package is the repo root, every change counts as outside it. Files inalso_inside(the npm stub’s own workflow file, which the Python stub’s paths filter ignores) count as inside.
>>> data = {"project": {"version": "1.2.3"}, ... "tool": {"wads": {"ci": {"version": {"sync": ["ts/package.json"]}}}}} >>> npm_publish_refusal(data, "ts", ["ts/src/a.ts"], "Release [publish-npm]") is None True >>> print(npm_publish_refusal(data, "ts", ["ts/src/a.ts", "pkg/b.py"], "Release [publish-npm]")) This push also releases the Python package, so npm would get the previous release's number (1.2.3) with newer code: uv-ci writes the new number into ts/package.json in its bump commit, after this one. Publish npm from a commit that changes only ts/ (or carries the skip-publish marker '[skip publish]'). Changed outside ts/: pkg/b.py >>> npm_publish_refusal(data, "ts", ["pkg/b.py"], "Release [publish-npm] [skip publish]") is None True >>> npm_publish_refusal({}, "ts", ["pkg/b.py"], "Release [publish-npm]") is None True
- wads.version_sync.pypi_release_expected(pyproject_data, subject)[source]¶
Whether uv-ci’s publish job releases to PyPI for a push with this commit
subject.Mirrors uv-ci’s gates (markers match the subject case-insensitively, like GitHub’s
contains()): the skip-ci and skip-publish markers suppress the release; with[tool.wads.ci.publish].enabled = falseonly the publish marker cuts one; in on-demand trigger mode only the deploy marker does, or the run-ci marker whenrun_ci_publishesis on.>>> pypi_release_expected({}, "Fix a typo") True >>> pypi_release_expected({}, "Fix a typo [Skip Publish]") False >>> off = {"tool": {"wads": {"ci": {"publish": {"enabled": False}}}}} >>> pypi_release_expected(off, "Fix a typo"), pypi_release_expected(off, "Fix [publish]") (False, True)
- Return type:
- wads.version_sync.set_cargo_version(path, version)[source]¶
Write
versioninto aCargo.toml(and theCargo.lockbeside it).Returns the files written. Only the version line changes, in the file’s own layout.
>>> import tempfile >>> d = Path(tempfile.mkdtemp()) >>> _ = (d / "Cargo.toml").write_text('[package]\nname = "a"\nversion = "0.1.0"\n') >>> _ = (d / "Cargo.lock").write_text('[[package]]\nname = "a"\nversion = "0.1.0"\n\n[[package]]\nname = "dep"\nversion = "0.1.0"\nsource = "registry+x"\n') >>> [p.name for p in set_cargo_version(d / "Cargo.toml", "0.2.0")] ['Cargo.toml', 'Cargo.lock'] >>> (d / "Cargo.toml").read_text() '[package]\nname = "a"\nversion = "0.2.0"\n' >>> (d / "Cargo.lock").read_text().count('0.2.0'), (d / "Cargo.lock").read_text().count('0.1.0') (1, 1)
- wads.version_sync.set_json_version(path, version)[source]¶
Write
versioninto onepackage.jsonorpackage-lock.json, as npm would.A lockfile carries the version twice: at the top and on its root package (
packages[""]); dependencies’ versions are left alone. Everything else in the file, and its layout, is kept. Used by the release (set_manifest_version()) and by the git-commit action’s push-back conflict resolver.- Return type:
- wads.version_sync.set_manifest_version(manifest, version)[source]¶
Write
versionintomanifestand the lockfile beside it (npm or Cargo).Returns the files written. Refuses a version npm would reject, before writing.
>>> import tempfile >>> d = Path(tempfile.mkdtemp()) >>> _ = (d / "package.json").write_text('{\n "name": "x",\n "version": "0.0.1"\n}\n') >>> [p.name for p in set_manifest_version(d / "package.json", "0.0.2")] ['package.json'] >>> print((d / "package.json").read_text(), end="") { "name": "x", "version": "0.0.2" }
- wads.version_sync.static_project_version(pyproject_data)[source]¶
[project].version, whichsyncneeds: CI bumps and copies that line.>>> static_project_version({"project": {"version": "1.2.3"}}) '1.2.3' >>> static_project_version({"project": {"dynamic": ["version"]}}) Traceback (most recent call last): ... ValueError: [tool.wads.ci.version].sync needs a static [project].version in pyproject.toml, and this project's version is dynamic. Make it static, or remove the sync key (and keep those versions by hand).
- Return type:
- wads.version_sync.sync_files(pyproject_data)[source]¶
The manifests
[tool.wads.ci.version].synclists, validated.>>> sync_files({"tool": {"wads": {"ci": {"version": {"sync": ["ts/package.json"]}}}}}) ['ts/package.json'] >>> sync_files({}) [] >>> sync_files({"tool": {"wads": {"ci": {"version": {"sync": ["rust/core/setup.py"]}}}}}) Traceback (most recent call last): ... ValueError: [tool.wads.ci.version].sync: 'rust/core/setup.py' is not one of ('package.json', 'Cargo.toml').