misc cleanup and linting

This commit is contained in:
Manuel Barkhau 2020-09-18 17:50:13 +00:00
parent 76fe72da43
commit 033a324488
12 changed files with 179 additions and 235 deletions

View file

@ -73,6 +73,7 @@ def _validate_release_tag(release: str) -> None:
@click.option('-v', '--verbose', count=True, help="Control log level. -vv for debug level.")
def cli(verbose: int = 0) -> None:
"""Automatically update PyCalVer version strings on python projects."""
# pylint:disable=global-statement; global flag is global.
global _VERBOSE
_VERBOSE = verbose
@ -164,6 +165,8 @@ def _try_print_diff(cfg: config.Config, new_version: str) -> None:
else:
click.echo(diff)
except Exception as ex:
# pylint:disable=broad-except; Mostly we expect IOError here, but
# could be other things and there's no option to recover anyway.
logger.error(str(ex), exc_info=True)
sys.exit(1)

View file

@ -185,37 +185,6 @@ FULL_PART_FORMATS = {
}
# TODO (mb 2020-09-17): I think this is garbage
# PART_FORMATS = {
# 'major' : "[0-9]+",
# 'minor' : "[0-9]{3,}",
# 'patch' : "[0-9]{3,}",
# 'bid' : "[0-9]{4,}",
# 'MAJOR' : "[0-9]+",
# 'MINOR' : "[0-9]+",
# 'MM' : "[0-9]{2,}",
# 'MMM' : "[0-9]{3,}",
# 'MMMM' : "[0-9]{4,}",
# 'MMMMM' : "[0-9]{5,}",
# 'MMMMMM' : "[0-9]{6,}",
# 'MMMMMMM': "[0-9]{7,}",
# 'PATCH' : "[0-9]+",
# 'PP' : "[0-9]{2,}",
# 'PPP' : "[0-9]{3,}",
# 'PPPP' : "[0-9]{4,}",
# 'PPPPP' : "[0-9]{5,}",
# 'PPPPPP' : "[0-9]{6,}",
# 'PPPPPPP': "[0-9]{7,}",
# 'BID' : "[1-9][0-9]*",
# 'BB' : "[1-9][0-9]{1,}",
# 'BBB' : "[1-9][0-9]{2,}",
# 'BBBB' : "[1-9][0-9]{3,}",
# 'BBBBB' : "[1-9][0-9]{4,}",
# 'BBBBBB' : "[1-9][0-9]{5,}",
# 'BBBBBBB': "[1-9][0-9]{6,}",
# }
class Pattern(typ.NamedTuple):
raw : str # "{pycalver}", "{year}.{month}", "YYYY0M.BUILD"

View file

@ -75,7 +75,7 @@ class VCSAPI:
logger.debug(cmd_str)
output_data: bytes = sp.check_output(cmd_str.split(), env=env, stderr=sp.STDOUT)
# TODO (mb 2018-11-15): Detect encoding of output?
# TODO (mb 2018-11-15): Detect encoding of output? Use chardet?
_encoding = "utf-8"
return output_data.decode(_encoding)
@ -99,11 +99,13 @@ class VCSAPI:
@property
def has_remote(self) -> bool:
# pylint:disable=broad-except; Not sure how to anticipate all cases.
try:
output = self('show_remotes')
if output.strip() == "":
return False
return True
else:
return True
except Exception:
return False

View file

@ -21,16 +21,48 @@ logger = logging.getLogger("pycalver.version")
TODAY = dt.datetime.utcnow().date()
MaybeInt = typ.Optional[int]
class CalendarInfo(typ.NamedTuple):
"""Container for calendar components of version strings."""
year : int
quarter : int
month : int
dom : int
doy : int
iso_week: int
us_week : int
year : MaybeInt
quarter : MaybeInt
month : MaybeInt
dom : MaybeInt
doy : MaybeInt
iso_week: MaybeInt
us_week : MaybeInt
class VersionInfo(typ.NamedTuple):
"""Container for parsed version string."""
year : MaybeInt
quarter : MaybeInt
month : MaybeInt
dom : MaybeInt
doy : MaybeInt
iso_week: MaybeInt
us_week : MaybeInt
major : int
minor : int
patch : int
bid : str
tag : str
def _ver_to_cal_info(vinfo: VersionInfo) -> CalendarInfo:
return CalendarInfo(
vinfo.year,
vinfo.quarter,
vinfo.month,
vinfo.dom,
vinfo.doy,
vinfo.iso_week,
vinfo.us_week,
)
def _date_from_doy(year: int, doy: int) -> dt.date:
@ -95,23 +127,6 @@ def cal_info(date: dt.date = None) -> CalendarInfo:
return CalendarInfo(**kwargs)
class VersionInfo(typ.NamedTuple):
"""Container for parsed version string."""
year : typ.Optional[int]
quarter : typ.Optional[int]
month : typ.Optional[int]
dom : typ.Optional[int]
doy : typ.Optional[int]
iso_week: typ.Optional[int]
us_week : typ.Optional[int]
major : int
minor : int
patch : int
bid : str
tag : str
FieldKey = str
MatchGroupKey = str
MatchGroupStr = str
@ -438,8 +453,8 @@ def incr(
cur_cal_nfo = cal_info()
old_date = (old_vinfo.year or 0, old_vinfo.month or 0, old_vinfo.dom or 0)
cur_date = (cur_cal_nfo.year , cur_cal_nfo.month , cur_cal_nfo.dom)
old_date = (old_vinfo.year or 0 , old_vinfo.month or 0 , old_vinfo.dom or 0)
cur_date = (cur_cal_nfo.year or 0, cur_cal_nfo.month or 0, cur_cal_nfo.dom or 0)
if old_date <= cur_date:
cur_vinfo = cur_vinfo._replace(**cur_cal_nfo._asdict())