Skip to content

Commit

Permalink
Incorporate bump and serialize utility functions from Dunamai
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Mar 22, 2020
1 parent 5387f3b commit c1b0469
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 113 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Unreleased

* Expose new Dunamai functions via `format-jinja`:
* `bump_version`
* `serialize_pep440`
* `serialize_pvp`
* `serialize_semver`

## v0.5.0 (2020-02-12)

* Added the `format-jinja` option.
Expand Down
49 changes: 38 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,44 @@ In your pyproject.toml file, you may configure the following options:
Example: `v{base}+{distance}.{commit}`
* `format-jinja`: String. Default: unset. This defines a custom output format
for the version, using a [Jinja](https://pypi.org/project/Jinja2) template.
When this is set, `format` is ignored. Available variables:

* `{{ base }}` (string)
* `{{ stage }}` (string or None)
* `{{ revision }}` (integer or None)
* `{{ distance }}` (integer)
* `{{ commit }}` (string)
* `{{ dirty }}` (boolean)
* `{{ env }}` (dictionary of environment variables)

Example: `{% if distance == 0 %}{{ base }}{% else %}{{ base }}+{{ distance }}.{{ commit }}{% endif %}`
When this is set, `format` is ignored.

Available variables:

* `base` (string)
* `stage` (string or None)
* `revision` (integer or None)
* `distance` (integer)
* `commit` (string)
* `dirty` (boolean)
* `env` (dictionary of environment variables)

Available functions:

* `bump_version` ([from Dunamai](https://github.com/mtkennerly/dunamai/blob/dc2777cdcc5eeff61c10602e33b1a0dc0bb0357b/dunamai/__init__.py#L786-L797))
* `serialize_pep440` ([from Dunamai](https://github.com/mtkennerly/dunamai/blob/dc2777cdcc5eeff61c10602e33b1a0dc0bb0357b/dunamai/__init__.py#L687-L710))
* `serialize_semver` ([from Dunamai](https://github.com/mtkennerly/dunamai/blob/dc2777cdcc5eeff61c10602e33b1a0dc0bb0357b/dunamai/__init__.py#L740-L752))
* `serialize_pvp` ([from Dunamai](https://github.com/mtkennerly/dunamai/blob/dc2777cdcc5eeff61c10602e33b1a0dc0bb0357b/dunamai/__init__.py#L766-L775))

Simple example:

```toml
format-jinja = "{% if distance == 0 %}{{ base }}{% else %}{{ base }}+{{ distance }}.{{ commit }}{% endif %}"
```

Complex example:

```toml
format-jinja = """
{%- if distance == 0 -%}
{{ serialize_pep440(base, stage, revision) }}
{%- elif revision is not None -%}
{{ serialize_pep440(base, stage, revision + 1, dev=distance, metadata=[commit]) }}
{%- else -%}
{{ serialize_pep440(bump_version(base), stage, revision, dev=distance, metadata=[commit]) }}
{%- endif -%}
"""
```
* `style`: String. Default: unset. One of: `pep440`, `semver`, `pvp`.
These are preconfigured output formats. If you set both a `style` and
a `format`, then the format will be validated against the style's rules.
Expand Down
Loading

0 comments on commit c1b0469

Please sign in to comment.