Skip to content

Commit

Permalink
fix bump script
Browse files Browse the repository at this point in the history
  • Loading branch information
sauljabin committed Jan 8, 2025
1 parent 0c4ad0f commit 1554553
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
26 changes: 1 addition & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ funding = "https://github.com/sponsors/sauljabin"
[tool.poetry.group.dev.dependencies]
black = "*"
faker = "*"
toml = "*"
pre-commit = "*"
ruff = "*"
mypy = "*"
types-attrs = "*"
types-protobuf = "*"
types-toml = "*"
changeloggh = "*"
textual-dev = "*"
typos = "*"
Expand Down
12 changes: 8 additions & 4 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ def __init__(self, commands: dict[str, str], rollback: dict[str, str] | None = N
self.rollback = rollback
self.console = Console()

def run(self) -> None:
def run(self) -> str:
output = ""
for name, command in self.commands.items():
result = self.execute_command(name, command)
if result.returncode:
self.console.print(
"\n[bold red]Error[/] when executing "
f'[bold blue]"{name}" ([bold yellow]{command}[/])[/]:exclamation::\n'
f"[red]{result.stdout.decode().strip()}{result.stderr.decode().strip()}[/]\n"
f"[red]{result.stdout}{result.stderr}[/]\n"
)

if self.rollback:
Expand All @@ -29,19 +30,22 @@ def run(self) -> None:
self.execute_command(rollback_name, rollback_command)

sys.exit(result.returncode)
else:
output += result.stdout

return output

def execute_command(self, name: str, command: str) -> subprocess.CompletedProcess:
self.console.print()
self.console.print(f"[bold blue]{name.lower()}:")
self.console.print(f"[bold yellow]{command}[/]")
return subprocess.run(shlex.split(command), capture_output=True)
return subprocess.run(shlex.split(command), capture_output=True, text=True)


if __name__ == "__main__":
test_commands = {
"list files": "ls .",
"testing echo": "echo 'hello world'",
"no command": "false",
}
test_rollback = {"echo rollback": "echo 'error'"}
command_processor = CommandProcessor(test_commands, test_rollback)
Expand Down
9 changes: 5 additions & 4 deletions scripts/bump.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import click
import toml
from rich.console import Console

from scripts import CommandProcessor
Expand Down Expand Up @@ -83,9 +82,11 @@ def revert_changes() -> None:


def get_app_version() -> str:
toml_data = toml.load("pyproject.toml")
app_version = toml_data["tool"]["poetry"]["version"]
return str(app_version)
revert_commands = {
"get version": "poetry version -s",
}
command_processor = CommandProcessor(revert_commands)
return command_processor.run().strip()


if __name__ == "__main__":
Expand Down

0 comments on commit 1554553

Please sign in to comment.