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)
def run(self) -> None:
full_args = [self.repo_path] + self.cmd
return tbump.git.run_git(*full_args, verbose=False)
def run_git(self, *args: str, verbose: bool = False) -> None:
full_args = [self.repo_path] + list(args)
return tbump.git.run_git(*full_args, verbose=verbose)
def print_error(self) -> None:
ui.error(
"Current branch (%s)" % self.branch, "does not track anything. Cannot push."
)
class RefAlreadyExists(tbump.git.GitError):
def __init__(self, *, ref: str):
super().__init__()
self.ref = ref
def print_error(self) -> None:
ui.error("git ref", self.ref, "already exists")
class Command(tbump.action.Action):
def __init__(self, repo_path: Path, cmd: List[str]):
super().__init__()
self.repo_path = repo_path
self.cmd = list(cmd)
self.verbose = True
def print_self(self) -> None:
tbump.git.print_git_command(self.cmd)
def do(self) -> None:
self.run()
def run(self) -> None:
full_args = [self.repo_path] + self.cmd
return tbump.git.run_git(*full_args, verbose=False)
git_bumper.check_branch_state(new_version)
except tbump.git.GitError as e:
if dry_run:
git_state_error = e
else:
raise
file_bumper = FileBumper(working_path)
file_bumper.set_config(config)
hooks_runner = HooksRunner(working_path, config.current_version)
if not only_patch:
for hook in config.hooks:
hooks_runner.add_hook(hook)
executor = Executor(new_version, file_bumper)
if not only_patch:
executor.add_git_and_hook_actions(new_version, git_bumper, hooks_runner)
if interactive:
executor.print_self(dry_run=True)
if not dry_run:
proceed = ui.ask_yes_no("Looking good?", default=False)
if not proceed:
raise Cancelled()
if dry_run:
if git_state_error:
ui.error("Git repository state is invalid")
git_state_error.print_error()
sys.exit(1)
else:
def parse_config(working_path: Path) -> Config:
tbump_path = working_path / "tbump.toml"
try:
config = tbump.config.parse(tbump_path)
except IOError as io_error:
raise InvalidConfig(io_error=io_error)
except Exception as parse_error:
raise InvalidConfig(parse_error=parse_error)
return config
def version_from_git_tag(git_tag):
prefix = "v"
assert git_tag.startswith(prefix), "tag should start with %s" % prefix
tbump_cfg = tbump.config.parse(Path("tbump.toml"))
regex = tbump_cfg.version_regex
version = git_tag[len(prefix):]
match = regex.match(version)
assert match, "Could not parse %s as a valid tag" % git_tag
return version
def bump_files(new_version: str, repo_path: Path = None) -> None:
repo_path = repo_path or Path(".")
bumper = FileBumper(repo_path)
cfg = tbump.config.parse(repo_path / "tbump.toml")
bumper.set_config(cfg)
patches = bumper.get_patches(new_version=new_version)
n = len(patches)
for i, patch in enumerate(patches):
ui.info_count(i, n, patch.src)
patch.print_self()
patch.apply()
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: