Skip to content

Commit

Permalink
Merge pull request #18 from naddeoa/bundle-files
Browse files Browse the repository at this point in the history
Bundle files
  • Loading branch information
naddeoa authored Jan 7, 2024
2 parents 1518f9f + a5e5d44 commit 4fc2c94
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 54 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
1 change: 1 addition & 0 deletions Dockerfile.binary
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from naddeoa/booty:ubuntu22.04

RUN sudo apt-get update
COPY ./ssh ./.ssh
RUN sudo chown -R myuser:myuser ./.ssh
RUN chmod 600 .ssh/id_rsa
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clean:

build-binary-linux: # Build the binary variant of booty via pyinstaller for linux.
poetry run pyinstaller ./booty/cli.py -n booty_linux_x86_64 -y \
--add-data="./booty/lang/:./booty/lang/" \
--exclude-module pandas \
--exclude-module numpy \
--exclude-module pytest \
Expand All @@ -35,6 +36,7 @@ build-binary-linux: # Build the binary variant of booty via pyinstaller for lin

build-binary-mac: # Build the binary variant of booty via pyinstaller for mac.
poetry run pyinstaller ./booty/cli.py -n booty_mac_x86_64 -y \
--add-data="./booty/lang/:./booty/lang/" \
--target-arch x86_64 \
--exclude-module pandas \
--exclude-module numpy \
Expand All @@ -46,6 +48,7 @@ build-binary-mac: # Build the binary variant of booty via pyinstaller for mac.

build-binary-mac-arm: # Build the binary variant of booty via pyinstaller for arm mac.
poetry run pyinstaller ./booty/cli.py -n booty_mac_arm64 -y \
--add-data="./booty/lang/:./booty/lang/" \
--target-arch arm64 \
--exclude-module pandas \
--exclude-module numpy \
Expand All @@ -57,6 +60,7 @@ build-binary-mac-arm: # Build the binary variant of booty via pyinstaller for a

build-binary-mac-universal: # Build the binary variant of booty via pyinstaller for arm mac.
poetry run pyinstaller ./booty/cli.py -n booty_mac_universal -y \
--add-data="./booty/lang/:./booty/lang/" \
--target-arch universal2 \
--exclude-module pandas \
--exclude-module numpy \
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Or download the appropriate binary from the latest release. This script just dow
move it somewhere on your path. The script will drop it in your `pwd`.

## Linux

```bash
curl https://raw.githubusercontent.com/naddeoa/booty/master/scripts/booty-download-linux.sh | bash
```
Expand All @@ -36,6 +37,7 @@ curl https://raw.githubusercontent.com/naddeoa/booty/master/scripts/booty-downlo
```

## Mac Arm

```bash
curl https://raw.githubusercontent.com/naddeoa/booty/master/scripts/booty-download-mac-universal.sh | bash
```
Expand All @@ -56,7 +58,7 @@ Options:
-i, --install Install all uninstalled targets
-d, --debug See the AST of the config file
-l, --log-dir TEXT Where to store logs. Defaults to ./logs
--no-sudo Don't allow booty to prompt with sudo -v. Instead, you
--no-sudo Don't allow booty to prompt with sudo -v. Instead, you
can manually run sudo -v before using booty to cache
credentials for any targets that use sudo. By default,
booty runs sudo -v upfront if you use sudo in any
Expand Down Expand Up @@ -263,4 +265,3 @@ There are a lot of good things about make though. My favorite relevant parts are

- Easy, independent dependency specification
- Plain old shell for each target definition.

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
37 changes: 20 additions & 17 deletions booty/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from booty.ast_util import get_dependencies, get_executable_index, get_recipe_definition_index
from booty.execute import BootyData, CommandExecutor, get_commands
from booty.graph import DependencyGraph
from booty.lang import get_stdlib
from booty.parser import parse
from booty.target_logger import TargetLogger
from booty.types import Executable, RecipeInvocation
from booty.ui import StdTree
from booty.ui import Padder, StdTree
from booty.validation import validate
from booty.lang.stdlib import stdlib


_REFRESH_RATE = 8
Expand Down Expand Up @@ -52,7 +52,7 @@ def setup(self, debug: bool) -> BootyData:
if debug:
print("AST:")
print(ast.pretty())
stdlib_ast = parse(stdlib)
stdlib_ast = parse(get_stdlib())
executables = get_executable_index(ast)
if debug:
print("Executables:")
Expand Down Expand Up @@ -118,16 +118,19 @@ def status(self) -> StatusResult:
status_result = StatusResult()
total_time = 0.0

group = Group(table, overall_progress)
with Live(group, refresh_per_second=_REFRESH_RATE):
padder = Padder()
padding = Padding(table, (0, 0, 0, 0))
group = Group(padding, overall_progress)

with Live(auto_refresh=False) as live:
for target in self.data.G.iterator():
deps_string = dependency_strings[target]

target_text = Text(target)
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 All @@ -137,6 +140,10 @@ def status(self) -> StatusResult:
cmd = CommandExecutor(self.data, target, "is_setup")
for _ in cmd.execute():
time_text.plain = f"{time.perf_counter() - start_time:.2f}s"
tree.set_stdout(cmd.latest_stdout())
tree.set_stderr(cmd.latest_stderr())
padding.bottom = padder.get_padding(tree)
live.update(group, refresh=True)

target_time = time.perf_counter() - start_time
total_time += target_time
Expand All @@ -160,6 +167,7 @@ def status(self) -> StatusResult:
self.logger.log_is_setup(target, cmd.all_stdout(), cmd.all_stderr())

overall_progress.advance(overall_id)
live.update(group, refresh=True)

overall_progress.update(overall_id, completed=True)
overall_progress.update(overall_id, visible=False)
Expand All @@ -181,16 +189,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 +220,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 +231,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
18 changes: 18 additions & 0 deletions booty/lang/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
import os
from typing import cast


def __get_file_content(file_name: str) -> str:
is_binary = getattr(sys, "_MEIPASS", None)
here: str = cast(str, os.path.join(sys._MEIPASS, "booty", "lang") if is_binary else os.path.dirname(__file__)) # type: ignore
with open(os.path.join(here, file_name), "r") as f:
return f.read()


def get_stdlib() -> str:
return __get_file_content("stdlib.booty")


def get_grammar() -> str:
return __get_file_content("grammar.lark")
2 changes: 0 additions & 2 deletions booty/lang/grammar.py → booty/lang/grammar.lark
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
grammar = r"""
%import common.SH_COMMENT
%import common.WS_INLINE
%ignore SH_COMMENT
Expand Down Expand Up @@ -50,4 +49,3 @@
# Note the leadering space before implements. It has to be indented somewhat.
IMPLEMENTS_NAME: /[ \t]+[a-zA-Z0-9_\.-]+/
_NEW_LINE: /\n/
"""
3 changes: 0 additions & 3 deletions booty/lang/stdlib.py → booty/lang/stdlib.booty
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
stdlib = """
recipe apt(packages):
setup: sudo apt-get install -y $((packages))
is_setup:
Expand All @@ -11,7 +10,6 @@

recipe ppa(name):
setup:
apt(software-properties-common)
sudo add-apt-repository -y $((name))
sudo apt-get update
is_setup: grep $((name)) /etc/apt/sources.list
Expand Down Expand Up @@ -40,4 +38,3 @@
cp -r $((src)) $((dst))
is_setup: test -e $((dst))

"""
5 changes: 3 additions & 2 deletions booty/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Optional
from lark import Lark, ParseTree
from pathlib import Path
from booty.lang.grammar import grammar

from booty.lang import get_grammar

__parser: Optional[Lark] = None

Expand All @@ -15,6 +16,6 @@ def get_lang_path(file: str) -> Path:
def parse(text: str) -> ParseTree:
global __parser
if __parser is None:
__parser = Lark(grammar, debug=True)
__parser = Lark(get_grammar(), debug=True)

return __parser.parse(text)
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
3 changes: 2 additions & 1 deletion examples/install.booty
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

essentials: apt(wget git vim autokey-gtk silversearcher-ag gawk xclip
gnome-disk-utility cryptsetup build-essential dconf-editor ripgrep xdotool
luarocks cmake libterm-readkey-perl expect ssh curl fzf)
luarocks cmake libterm-readkey-perl expect ssh curl fzf software-properties-common)

files.git -> essentials
files.git: git([email protected]:~/git/files, ~/files)
Expand Down Expand Up @@ -141,6 +141,7 @@ node:
## Racket
##

racket -> essentials
racket:
setup:
ppa(ppa:plt/racket)
Expand Down
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 4fc2c94

Please sign in to comment.