Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(args: Optional[List[str]] = None) -> None:
# Supress backtrace if exception derives from tbump.Error
if not args:
args = sys.argv[1:]
try:
run(args)
except tbump.Error as error:
error.print_error()
sys.exit(1)
self.regex = regex
def print_error(self) -> None:
ui.error("Could not parse", self.version, "as a valid version string")
class SourceFileNotFound(tbump.Error):
def __init__(self, *, src: str):
super().__init__()
self.src = src
def print_error(self) -> None:
ui.error(self.src, "does not exist")
class CurrentVersionNotFound(tbump.Error):
def __init__(self, *, src: str, current_version_string: str):
super().__init__()
self.src = src
self.current_version_string = current_version_string
# TODO: raise just once for all errors
def print_error(self) -> None:
ui.error(
"Current version string: (%s)" % self.current_version_string,
"not found in",
self.src,
)
def should_replace(line: str, old_string: str, search: Optional[str] = None) -> bool:
if not search:
"\n",
]
ui.error(*message, end="", sep="")
class InvalidVersion(tbump.Error):
def __init__(self, *, version: str, regex: Pattern[str]):
super().__init__()
self.version = version
self.regex = regex
def print_error(self) -> None:
ui.error("Could not parse", self.version, "as a valid version string")
class SourceFileNotFound(tbump.Error):
def __init__(self, *, src: str):
super().__init__()
self.src = src
def print_error(self) -> None:
ui.error(self.src, "does not exist")
class CurrentVersionNotFound(tbump.Error):
def __init__(self, *, src: str, current_version_string: str):
super().__init__()
self.src = src
self.current_version_string = current_version_string
# TODO: raise just once for all errors
def print_error(self) -> None:
pass
class AfterPushHook(Hook):
pass
HOOKS_CLASSES = {
"after_push": AfterPushHook,
"before_commit": BeforeCommitHook,
"before_push": BeforeCommitHook, # retro-compat name
"hook": BeforeCommitHook, # retro-compat name
}
class HookError(tbump.Error):
def __init__(self, *, name: str, cmd: str, rc: int):
super().__init__()
self.cmd = cmd
self.rc = rc
self.name = name
def print_error(self) -> None:
ui.error(ui.reset, "`%s`" % self.cmd, "exited with return code", self.rc)
class HooksRunner:
def __init__(self, working_path: Path, current_version: str):
self.hooks = [] # type: List[Hook]
self.working_path = working_path
self.current_version = current_version
]
message += [
"More info:\n",
" * version groups: ",
repr(self.groups),
"\n" " * template: ",
self.template,
"\n",
" * version: ",
self.version,
"\n",
]
ui.error(*message, end="", sep="")
class InvalidVersion(tbump.Error):
def __init__(self, *, version: str, regex: Pattern[str]):
super().__init__()
self.version = version
self.regex = regex
def print_error(self) -> None:
ui.error("Could not parse", self.version, "as a valid version string")
class SourceFileNotFound(tbump.Error):
def __init__(self, *, src: str):
super().__init__()
self.src = src
def print_error(self) -> None:
ui.error(self.src, "does not exist")
def get_ending(line: bytes) -> bytes:
if line.endswith(b"\r\n"):
return b"\r\n"
else:
return b"\n"
def apply(self) -> None:
file_path = self.working_path / self.src
contents = file_path.bytes()
lines = contents.splitlines(keepends=True)
old_line = lines[self.lineno]
lines[self.lineno] = self.new_line.encode() + Patch.get_ending(old_line)
file_path.write_lines(lines, linesep=None)
class BadSubstitution(tbump.Error):
def __init__(
self,
*,
src: str,
verb: str,
groups: Dict[str, str],
template: str,
version: str
):
super().__init__()
self.src = src
self.verb = verb
self.groups = groups
self.template = template
self.version = version
self,
io_error: Optional[IOError] = None,
parse_error: Optional[Exception] = None,
):
super().__init__()
self.io_error = io_error
self.parse_error = parse_error
def print_error(self) -> None:
if self.io_error:
ui.error("Could not read config file:", self.io_error)
if self.parse_error:
ui.error("Invalid config:", self.parse_error)
class Cancelled(tbump.Error):
def print_error(self) -> None:
ui.error("Cancelled by user")
@attr.s
class BumpOptions:
working_path = attr.ib() # type: Path
new_version = attr.ib() # type: str
interactive = attr.ib(default=True) # type: bool
dry_run = attr.ib(default=False) # type: bool
only_patch = attr.ib(default=False) # type: bool
def run(cmd: List[str]) -> None:
opt_dict = docopt.docopt(USAGE, argv=cmd)
if opt_dict["--version"]:
from typing import List, Optional, Tuple
import subprocess
from path import Path
import cli_ui as ui
import tbump
class GitError(tbump.Error):
pass
class GitCommandError(GitError):
def __init__(
self, cmd: List[str], working_path: Path, output: Optional[str] = None
):
super().__init__()
self.cmd = cmd
self.output = output
self.working_path = working_path
def print_error(self) -> None:
cmd_str = " ".join(self.cmd)
ui.error("Command", "`%s`" % cmd_str, "failed")
tbump [options] init
tbump --help
tbump --version
Options:
-h --help Show this screen.
-v --version Show version.
-C --cwd=