Skip to content

Commit

Permalink
Updated formatting documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Apr 20, 2023
1 parent 4fb5158 commit 8006f3e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
56 changes: 56 additions & 0 deletions docsrc/formatting-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Formatting context

These fields are available for

- version serializing
- searching and replacing in files
- commit messages
- tag names
- tag annotations

## Escaped characters

**`#`** The literal hash or [octothorpe](https://www.merriam-webster.com/dictionary/octothorpe) character.

**`;`** The literal semicolon character.


## Date and time fields

**`now`** A Python datetime object representing the current local time, without a time zone reference.

**`utcnow`** A Python datetime object representing the current local time in the UTC time zone.

You can provide [additional formatting guidance](https://docs.python.org/3.11/library/datetime.html#strftime-and-strptime-format-codes) for datetime objects using formatting codes. Put the formatting codes after the field and a colon. For example, `{now:%Y-%m-%d}` would output the current local time as `2023-04-20`.

## Source code management fields

These fields will only have values if the code is in a Git or Mercurial repository.

**`commit_sha`** The latest commit reference.

**`distance_to_latest_tag`** The number of commits since the latest tag.

**`dirty`** A boolean indicating if the current repository has pending changes.

## Version fields

**`current_version`** The current version serialized as a string

**`current_<version part>`** Each version part defined by the [version configuration parsing regular expression](version-parts.md#version-configuration). The default configuration would have `current_major`, `current_minor`, and `current_patch` available.

**`new_version`** The new version serialized as a string

**`new_<version part>`** Each version part defined by the [version configuration parsing regular expression](version-parts.md#version-configuration). The default configuration would have `new_major`, `new_minor`, and `new_patch` available.

:::{note}
The following fields are only available when serializing a version.
:::

**`<version part>`** Each version part defined by the [version configuration parsing regular expression](version-parts.md#version-configuration). The default configuration would have `major`, `minor`, and `patch` available.

## Environment variables

Every environment variable available at runtime is included with a `$` prefix. For example if `USER` was in the environment, `{$USER}` would render that value.

If you use environment variables in your version serialization, you might want to ensure they are set by executing `export VAR=value` before running the `bump-my-version` command.
3 changes: 3 additions & 0 deletions docsrc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ caption: Contents
Introduction <readme>
usage
configuration
version-parts
formatting-context
search-and-replace
cli
api
contributing
Expand Down
2 changes: 1 addition & 1 deletion docsrc/search-and-replace.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using this `.bumpversion.toml` will ensure only the line containing `MyProject`
[tool.bumpversion]
current_version = "1.5.6"

[[tool.bumpversion:files]]
[[tool.bumpversion.files]]
filename = "requirements.txt"
search = "MyProject=={current_version}"
replace = "MyProject=={new_version}"
Expand Down

0 comments on commit 8006f3e

Please sign in to comment.