mypy pacification

This commit is contained in:
Manuel Barkhau 2018-09-04 20:16:46 +02:00
parent b3c2dc03eb
commit 6aa16f7b37
3 changed files with 33 additions and 23 deletions

View file

@ -83,7 +83,7 @@ def incr(old_version: str, release: str = None) -> None:
new_version_nfo = parse.parse_version_info(new_version) new_version_nfo = parse.parse_version_info(new_version)
print("PyCalVer Version:", new_version) print("PyCalVer Version:", new_version)
print("PEP440 Version:", new_version_nfo["pep440_version"]) print("PEP440 Version:", new_version_nfo.pep440_version)
@cli.command() @cli.command()
@ -196,15 +196,14 @@ def bump(
filepaths = set(file_patterns.keys()) filepaths = set(file_patterns.keys())
_vcs = vcs.get_vcs() _vcs = vcs.get_vcs()
_vcs.assert_not_dirty(filepaths, allow_dirty)
rewrite.rewrite(new_version, file_patterns, dry, verbose)
if dry:
return
if not commit:
return
if _vcs is None: if _vcs is None:
log.warn("Version Control System not found, aborting commit.") log.warn("Version Control System not found, aborting commit.")
else:
_vcs.assert_not_dirty(filepaths, allow_dirty)
rewrite.rewrite(new_version, file_patterns, dry, verbose)
if dry or not commit or _vcs is None:
return return
# TODO (mb 2018-09-04): add files and commit

View file

@ -102,7 +102,7 @@ def ord_val(lex_id: str) -> int:
return int(lex_id[1:], 10) return int(lex_id[1:], 10)
def main(): def main() -> None:
_curr_id = "01" _curr_id = "01"
print(f"{'lexical':<13} {'numerical':>12}") print(f"{'lexical':<13} {'numerical':>12}")

View file

@ -21,18 +21,29 @@ log = logging.getLogger("pycalver.vcs")
class BaseVCS: class BaseVCS:
@classmethod _TEST_USABLE_COMMAND: typ.List[str]
def commit(cls, message): _COMMIT_COMMAND: typ.List[str]
f = tempfile.NamedTemporaryFile("wb", delete=False) _STATUS_COMMAND: typ.List[str]
f.write(message.encode("utf-8"))
f.close()
cmd = cls._COMMIT_COMMAND + [f.name]
env_items = list(os.environ.items()) + [(b"HGENCODING", b"utf-8")]
sp.check_output(cmd, env=dict(env_items))
os.unlink(f.name)
@classmethod @classmethod
def is_usable(cls): def commit(cls, message: str) -> None:
message_data = message.encode("utf-8")
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
with tmp_file as fh:
fh.write(message_data)
cmd = cls._COMMIT_COMMAND + [tmp_file.name]
env = os.environ.copy()
# TODO (mb 2018-09-04): check that this works on py27,
# might need to be bytes there, idk.
env["HGENCODING"] = "utf-8"
sp.check_output(cmd, env=env)
os.unlink(tmp_file.name)
@classmethod
def is_usable(cls) -> bool:
try: try:
return sp.call( return sp.call(
cls._TEST_USABLE_COMMAND, cls._TEST_USABLE_COMMAND,
@ -46,7 +57,7 @@ class BaseVCS:
raise raise
@classmethod @classmethod
def dirty_files(cls): def dirty_files(cls) -> typ.List[str]:
status_output = sp.check_output(cls._STATUS_COMMAND) status_output = sp.check_output(cls._STATUS_COMMAND)
return [ return [
line.decode("utf-8")[2:].strip() line.decode("utf-8")[2:].strip()
@ -107,7 +118,7 @@ class Mercurial(BaseVCS):
VCS = [Git, Mercurial] VCS = [Git, Mercurial]
def get_vcs(): def get_vcs() -> typ.Optional[typ.Type[BaseVCS]]:
for vcs in VCS: for vcs in VCS:
if vcs.is_usable(): if vcs.is_usable():
return vcs return vcs