Repository navigation
feat: version Python projects through pyproject.toml - #30
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AutoVer can version
.csproj,.nuspecand Dockerfile projects, but not Python ones. A Python package in a repository on AutoVer's release flow today has to derive its version from git tags instead (e.g. hatch-vcs withVersionFromTag). That works, but it comes with rules that are easy to get wrong:v*tags have to be filtered out;This adds a
pyproject.tomlproject type, so a Python package carries a static version that AutoVer bumps like any other project file:{ "Projects": [ { "Name": "my-package", "Path": "pyproject.toml" } ] }Behaviour
versionin the[project]table (PEP 621) is rewritten. The file is edited line by line, not re-serialized, so quoting, spacing, comments, key order and line endings are kept. A version is seeded afternamewhen there is none, like the other project types. A UTF-8 BOM is not kept.pyproject.tomlis never auto-discovered. Many repositories keep one purely for tool settings (black, ruff, pytest), and discovering those would start versioning a lint config in repositories that rely on discovery today."version"listed indynamic;[tool.poetry]-only project;1.2.3b1gets a suggestion to write1.2.3-b1);beta.1writes1.2.3-beta.1, which pip reads as1.2.3b1.hotfixis rejected because it would make a package pip refuses to install.post.1or1are rejected because they are post-releases, which pip ranks above1.2.3and installs by default.packaginglibrary pip uses: on a 27-label table, and on about 30k fuzzed labels.VersionCommandnow plans every update, validates them all through a newIProjectFileHandler.ValidateVersion(a no-op by default), and only then writes and stages. A version a pyproject can't take fails the release without leaving other projects bumped.autover.json.The TOML scanner handles:
"requests[socks]>=2";[project.*]sub-tables and[[array.of.tables]];Compatibility
No change for existing projects. The pre-change and new builds were run side by side on 36 scripted repositories: csproj, nuspec, Dockerfile, auto-discovery,
VersionFromTag, change files, everyversion/changelog/changeoption, and error cases. Successful runs were identical in exit codes, stdout, files, commits and tags. The differences are all on error paths:pyproject.toml;<metadata>), an earlier file is left bumped but unstaged rather than staged. No commit or tag is made in either case.IProjectHandlergainsValidateVersion. AutoVer ships only as a dotnet tool, andProjectHandleris its only implementation.Tests
PyprojectFileHandlerTest(66): matching, reading and every TOML case above, each refusal, writing (byte-for-byte), seeding positions, and Python version rules.PyprojectVersionCommandTests(10), through the CLI:--current;InitialVersion;changelog;1.2.3b1gives an explained error rather than an unhandled exception;tomllibon 36 edge-case inputs: all parse, carry the intended version, and are otherwise identical.…-0.2.0-py3-none-any.whl.Full suite: 113 integration, 256 unit, 0 failures (from 103 / 190). The clean build has no warnings.