formatting updates

This commit is contained in:
Manuel Barkhau 2018-11-06 21:45:33 +01:00
parent 3385f2d675
commit 1129de0beb
11 changed files with 153 additions and 128 deletions

View file

@ -1,8 +1,9 @@
# This file is part of the pycalver project
# https://github.com/mbarkhau/pycalver
#
# (C) 2018 Manuel Barkhau (@mbarkhau)
# Copyright (c) 2018 Manuel Barkhau (@mbarkhau) - MIT License
# SPDX-License-Identifier: MIT
"""Functions related to version string manipulation."""
import logging
import typing as typ
@ -15,19 +16,26 @@ log = logging.getLogger("pycalver.version")
def current_calver() -> str:
"""Generate calver version string based on current date.
example result: "v201812"
"""
return dt.date.today().strftime("v%Y%m")
def bump(old_version: str, *, release: str = None) -> str:
# old_version is assumed to be a valid calver string,
# validated in pycalver.config.parse.
def incr(old_version: str, *, release: str = None) -> str:
"""Increment a full PyCalVer version string.
Old_version is assumed to be a valid calver string,
already validated in pycalver.config.parse.
"""
old_ver = parse.parse_version_info(old_version)
new_calver = current_calver()
if old_ver.calver > new_calver:
log.warning(
f"'version.bump' called with '{old_version}', "
f"'version.incr' called with '{old_version}', "
+ f"which is from the future, "
+ f"maybe your system clock is out of sync."
)