Skip to content

Commit

Permalink
Update pyinstaller build to bundle the booty/lark files
Browse files Browse the repository at this point in the history
I had turned these files into python modules to avoid dealing with the
bundling process but the upcoming package work means I need to touch the
grammar again, and having it as a python string without any syntax
highlighting is lame. Wasn't that hard anyway.
  • Loading branch information
naddeoa committed Jan 6, 2024
1 parent 1518f9f commit 9e434ee
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
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
6 changes: 3 additions & 3 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
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/
"""
2 changes: 0 additions & 2 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 Down Expand Up @@ -40,4 +39,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)

0 comments on commit 9e434ee

Please sign in to comment.