Skip to content

Commit 9f29344

Browse files
author
matmoncon
committed
refactor: remove tabulate and add pretty_print function
1 parent 6f00d0b commit 9f29344

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

poetry.lock

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyneo4j_ogm/migrations/actions/status.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import datetime
66
from typing import List, Optional, TypedDict
77

8-
from tabulate import tabulate
98
from typing_extensions import Literal
109

1110
from pyneo4j_ogm.logger import logger
@@ -28,6 +27,30 @@ class MigrationStatus(TypedDict):
2827
status: Literal["APPLIED", "PENDING"]
2928

3029

30+
def pretty_print(migrations: List[List[str]]) -> None:
31+
"""
32+
Prints a pretty version of the migration status.
33+
34+
migrations(List[List[str]]): A list of migrations where the first item is the migration
35+
name and the second item is the status.
36+
"""
37+
max_length = max(len(str(item[0])) for item in migrations)
38+
top_border_line = "┌" + "─" * (max_length + 2) + "┬" + "─" * 26 + "┐"
39+
bottom_border_line = "└" + "─" * (max_length + 2) + "┴" + "─" * 26 + "┘"
40+
header_line = "│ " + "Migration".ljust(max_length) + " │ " + "Applied At".ljust(24) + " │"
41+
separator_line = "├" + "─" * (max_length + 2) + "┼" + "─" * 26 + "┤"
42+
43+
print(top_border_line)
44+
print(header_line)
45+
print(separator_line)
46+
47+
for migration in migrations:
48+
row = "│ " + str(migration[0]).ljust(max_length) + " │ " + str(migration[1]).ljust(24) + " │"
49+
print(row)
50+
51+
print(bottom_border_line)
52+
53+
3154
async def status(config_path: Optional[str] = None) -> List[MigrationStatus]:
3255
"""
3356
Visualize the status of all migrations.
@@ -81,7 +104,7 @@ async def status(config_path: Optional[str] = None) -> List[MigrationStatus]:
81104

82105
logger.debug("Sorting %s migrations by applied_at timestamp and name", len(migrations))
83106
migrations.sort(key=lambda migration: (migration[1], migration[0]))
84-
print(tabulate(migrations, headers=["Migration", "Applied at"], tablefmt="fancy_grid"))
107+
pretty_print(migrations)
85108

86109
migration_status.sort(
87110
key=lambda migration: (migration["applied_at"] is None, migration["applied_at"], migration["name"])

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pydantic = ">=1.10,<3.0"
2727
neo4j = "^5.9.0"
2828
typing-extensions = "^4.8.0"
2929
argparse = "^1.4.0"
30-
tabulate = "^0.9.0"
3130

3231
[tool.poetry.group.dev.dependencies]
3332
pylint = "^2.17.5"

0 commit comments

Comments
 (0)