Skip to content

Commit

Permalink
Add bump option
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Nov 18, 2020
1 parent 7b57245 commit d56635b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

* Added:
* `bump` option.

## v0.10.0 (2020-10-08)

* Added:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ In your pyproject.toml file, you may configure the following options:
* `latest-tag`: Boolean. Default: false. If true, then only check the latest
tag for a version, rather than looking through all the tags until a suitable
one is found to match the `pattern`.
<!--
* `bump`: Boolean. Default: false. If true, then increment the last part of
the version `base` by 1, unless the `stage` is set, in which case increment
the `revision` by 1 or set it to a default of 2 if there was no `revision`.

Example:
* PEP 440 with `bump = false`: `1.3.1.post3.dev0+28c1684`
* PEP 440 with `bump = true`: `1.3.2.dev3+28c1684`
-->
* `[tool.poetry-dynamic-versioning.subversion]`: Options specific to Subversion.
* `tag-dir`: String. Default: `tags`. This is the location of tags relative
to the root.
Expand Down
9 changes: 5 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def _default_config() -> Mapping:
"format": None,
"format-jinja": None,
"format-jinja-imports": [],
"bump": False,
}
}
}
Expand Down Expand Up @@ -139,11 +140,23 @@ def _get_version(config: Mapping) -> Tuple[Version, str]:
version = Version.from_vcs(
vcs, config["pattern"], config["latest-tag"], config["subversion"]["tag-dir"]
)

if config["format-jinja"]:
base = version.base
revision = version.revision
if config["bump"]:
if version.stage is None:
base = bump_version(version.base)
else:
if version.revision is None:
revision = 2
else:
revision = version.revision + 1

default_context = {
"base": version.base,
"base": base,
"stage": version.stage,
"revision": version.revision,
"revision": revision,
"distance": version.distance,
"commit": version.commit,
"dirty": version.dirty,
Expand All @@ -167,7 +180,9 @@ def _get_version(config: Mapping) -> Tuple[Version, str]:
if style is not None:
check_version(serialized, style)
else:
serialized = version.serialize(config["metadata"], config["dirty"], config["format"], style)
serialized = version.serialize(
config["metadata"], config["dirty"], config["format"], style, bump=config["bump"]
)

return (version, serialized)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include = ["zzz_poetry_dynamic_versioning.pth"]

[tool.poetry.dependencies]
python = "^3.5"
dunamai = "^1.3"
dunamai = "^1.4"
tomlkit = ">= 0.4"
jinja2 = "^2.11.1"

Expand Down
7 changes: 7 additions & 0 deletions tests/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ function test_poetry_core_as_build_system {
ls $dummy/dist | should_fail grep 0.0.999
}

function test_bumping_enabled {
# Poetry will convert "-pre.1" to "rc1".
sed -i 's/vcs = .*/bump = true/' $dummy/pyproject.toml && \
$do_poetry build -v && \
ls $dummy/dist | grep rc1
}

function run_test {
cd $dummy
git checkout -- $dummy
Expand Down

0 comments on commit d56635b

Please sign in to comment.