Skip to content

Commit

Permalink
Pull out the table padding logic into a common file
Browse files Browse the repository at this point in the history
Going to be applying it to the status table soon and I need this to
avoid copy/pasting all of the padding arithmetic.
  • Loading branch information
naddeoa committed Jan 7, 2024
1 parent 9e434ee commit 65f8acd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 39 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from naddeoa/booty:ubuntu22.04

RUN --mount=type=cache,target=/var/cache/apt sudo apt install -y python3 python3-pip # MANUAL install pip
RUN sudo apt-get update
RUN --mount=type=cache,target=/var/cache/apt sudo apt-get install -y python3 python3-pip # MANUAL install pip
COPY ./dist/*.whl ./
RUN --mount=type=cache,target=/home/myuser/.cache pip install --user ./*.whl # MANUAL install booty

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ from ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive

RUN --mount=type=cache,target=/var/cache/apt <<EOF
apt update && apt upgrade -y
apt install -y sudo locales keyboard-configuration
apt-get update && apt-get upgrade -y
apt-get install -y sudo locales keyboard-configuration
EOF

# Set the timezone
Expand Down
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

Some features that might be useful. If you feel up to contributing then these could be a good starting place.

- Language spec
- import system and package system

- Debug display issues with scrolling/collapsing tree during steup. This probably because the height of the table decreases and then the
tallest area is "orphaned". I probably have to have a constant wosrt case padding at the bottom of the table, wich would be 12 lines?
- Refactor release process to delay the release creation until the last step. There is a period now where the copy/paste install fails
Expand Down
19 changes: 7 additions & 12 deletions booty/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def status(self) -> StatusResult:
dependency_text = Text(deps_string)
status_text = Text("🟡 Checking...")

tree = StdTree(self._display_setup(self.data.execution_index[target]))
tree = StdTree(self._display_is_setup(self.data.execution_index[target]))

time_text = Text("") # Make update in real time

Expand Down Expand Up @@ -181,16 +181,14 @@ def install_missing(self, status_result: StatusResult) -> StatusResult:
overall_progress = Progress()
overall_id = overall_progress.add_task("Status", total=len(missing_packages))

# table_padding = Text("\n" * (len(missing_packages) + 1))

max_padding = 0
padder = Padder()
padding = Padding(table, (0, 0, 0, 0))
group = Group(padding, overall_progress)

total_time = 0.0
status_result = StatusResult()
gen = self.data.G.bfs()
with Live() as live:
with Live(auto_refresh=False) as live:
try:
next(gen) # Skip the first fake target
target = gen.send(True)
Expand All @@ -214,9 +212,8 @@ def install_missing(self, status_result: StatusResult) -> StatusResult:
time_text.plain = f"{time.perf_counter() - start_time:.2f}s"
tree.set_stdout(cmd.latest_stdout())
tree.set_stderr(cmd.latest_stderr())
max_padding = max(max_padding, tree.height())
padding.bottom = abs(max_padding - tree.height())
live.update(group)
padding.bottom = padder.get_padding(tree)
live.update(group, refresh=True)

cmd_time = time.perf_counter() - start_time
time_text.plain = f"{cmd_time:.2f}s"
Expand All @@ -226,17 +223,15 @@ def install_missing(self, status_result: StatusResult) -> StatusResult:
status_result.installed.append(target)
status_text.plain = "🟢 Installed"
tree.reset()
padding.bottom = abs(max_padding - tree.height())
live.update(group)

padding.bottom = padder.get_padding(tree)
else:
status_text.plain = "🔴 Error"
self.logger.log_setup(target, cmd.all_stdout(), cmd.all_stderr())
status_result.errors.append(target)

target = gen.send(cmd.code == 0)
overall_progress.advance(overall_id)
live.update(group)
live.update(group, refresh=True)

except StopIteration as e:
skipped: List[str] = e.value
Expand Down
26 changes: 6 additions & 20 deletions booty/ui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from typing import List, Optional
from rich.console import Group
from rich.live import Live
from rich.progress import Progress
from rich.padding import Padding
from rich.table import Table
from rich.text import Text
from rich.tree import Tree

Expand Down Expand Up @@ -68,20 +63,11 @@ def height(self) -> int:
return cmd_height + stdout_height + stderr_height


class PaddedTable:
def __init__(self, table: Table, total: int) -> None:
self.table = table
self._progress = Progress()
# self.progress_id = progress.add_task("Status", total=total)
class Padder:
def __init__(self) -> None:
self._max_padding = 0
self._padding = Padding(table, (0, 0, 0, 0))
self._group = Group(self._padding, self._progress)

# def get_std_tree(self, cmd: str) -> StdTree:
# self.std_tree = StdTree(self._display_setup(self.data.execution_index[target]))

def update(self, live: Live) -> None:
pass

# self._padding.bottom = abs(self._max_padding - self.std_tree.height())
# live.update(group)
def get_padding(self, tree: StdTree) -> int:
height = tree.height()
self._max_padding = max(self._max_padding, height)
return self._max_padding - height
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ keywords = ["bootstrap", "booty", "setup", "cli", "tool"]
authors = ["Anthony Naddeo <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{ include = "booty/**/*.py" }]

packages = [
{ include = "booty/**/*.py"},
{ include = "booty/**/*.lark"},
{ include = "booty/**/*.booty"}
]

[tool.poetry.scripts]
booty = "booty.cli:cli"


[tool.poetry.dependencies]
python = ">=3.9, <3.13"
lark = "^1.1.8"
click = "^8.1.7"
rich = "^13.7.0"


[tool.poetry.group.dev.dependencies]
pyright = "^1.1.338"
ruff = "^0.1.7"
Expand Down

0 comments on commit 65f8acd

Please sign in to comment.