bump_version¶
-
privex.helpers.setuppy.bump.
bump_version
(part='patch', dry=False, **kwargs)[source]¶ Bump semver version and replace version line inside of
settings.VERSION_FILE
Obtains the current package version using
version_func
Uses
semver
to increment thepart
portion and resets any lower portions to zeroReads the file
settings.VERSION_FILE
and passes it toreplace_func
along with the original version and new bumped version to obtain the modified file contents.Writes the file contents containing the updated version number back to
settings.VERSION_FILE
Basic usage:
>>> from privex.helpers import settings, setuppy >>> bump_version('minor')
If you want to use this function outside of privex-helpers, for your own package/project, ensure you adjust the settings and version functions as required.
To change the file which contains your package version, as well as the function used to get the current version:
>>> import mypackage >>> from privex.helpers import settings >>> settings.VERSION_FILE = '/home/john/mypackage/mypackage/__init__.py'
If you use the same version line format at privex-helpers, like this:
VERSION = '1.2.3' # In-line comments are fine, as are double quotes instead of single quotes.
Then you don’t need to make a custom version retrieval or replacement function.
Otherwise… this is how you write and register a custom version retrieval and replacement function:
import re from privex.helpers.setuppy import bump # Regex to find the string: version='x.y.z' # and extract the version x.y.z on it's own. my_regex = re.compile(r'version='?"?([0-9a-zA-Z-._]+)'?"?') def my_version_finder(data: str): return str(my_regex.search(data).group(1)) # Set your function `my_version_finder` as the default used to obtain the current package version bump.default_current_ver = my_version_finder def my_version_replacer(data: str, old_version: str, new_version: str): # This is an example of a version replacer if you just put your version straight into setup.py return data.replace(f"version='{old_version}'", f"version='{new_version}'") # Alternatively use regex substitution return my_regex.sub(f"version='{new_version}'", data) # Set your function `my_version_replacer` as the default used to replace the version in a file. bump.default_replace_func = my_version_replacer
- Parameters
- Key callable replace_func
Custom version replacement function. Should take the arguments (data, old_version, new_version) and return
data
with the version line replaced.- Key callable version_func
Custom version retrieval function. Takes no args, returns curr version as a string.
- Key str token
If using part
build
orprerelease
, this overrides the version token- Returns