Compare commits

...

6 Commits

Author SHA1 Message Date
ad3020809e merge commands 2025-02-07 16:37:00 +00:00
76c6630892 fix deferred task 2025-02-07 15:09:36 +00:00
cc46fc31f8 upd build script, format files/dirs the same as Taskfile 2025-02-07 15:09:21 +00:00
8657e8846a add Taskfile 2025-02-07 14:53:21 +00:00
43aad156a0 upd flags passed to rewriter 2025-02-07 14:53:07 +00:00
5101ff01f2 change --cleanup flag for --restore
run file through ruff formatter
2025-02-07 14:52:40 +00:00
4 changed files with 180 additions and 103 deletions

77
Taskfile.yml Normal file
View File

@ -0,0 +1,77 @@
version: '3'
vars:
SHELL: pwsh
tasks:
default:
desc: "Prepare artifacts for release"
deps: [release]
release:
desc: "Build and compress all artifacts"
cmds:
- task: build
- task: compress
- echo "Release complete"
build:
desc: "Build all artifacts"
cmds:
- task: build-sunvalley
- echo "Sunvalley build complete"
- task: build-forest
- echo "Forest build complete"
build-sunvalley:
desc: "Build Sunvalley artifacts"
cmds:
- for:
matrix:
KIND: ["basic", "banana", "potato"]
cmd: poetry run pyinstaller --noconfirm --distpath dist/sunvalley-{{.ITEM.KIND}} spec/sunvalley-{{.ITEM.KIND}}.spec
build-forest:
desc: "Build Forest artifacts"
deps: [rewrite]
cmds:
- defer: { task: restore }
- for:
matrix:
KIND: ["basic", "banana", "potato"]
THEME: ["light", "dark"]
cmd: poetry run pyinstaller --noconfirm --distpath dist/forest-{{.ITEM.KIND}}-{{.ITEM.THEME}} spec/forest-{{.ITEM.KIND}}-{{.ITEM.THEME}}.spec
rewrite:
desc: "Run the source code rewriter"
cmds:
- poetry run python tools/rewriter.py --rewrite
restore:
desc: "Restore the backup files"
cmds:
- poetry run python tools/rewriter.py --restore
compress:
deps: [compress-sunvalley, compress-forest]
compress-sunvalley:
cmds:
- for:
matrix:
KIND: ["basic", "banana", "potato"]
cmd: '{{.SHELL}} -Command "Compress-Archive -Path dist/sunvalley-{{.ITEM.KIND}} -DestinationPath dist/sunvalley-{{.ITEM.KIND}}.zip"'
compress-forest:
cmds:
- for:
matrix:
KIND: ["basic", "banana", "potato"]
THEME: ["light", "dark"]
cmd: '{{.SHELL}} -Command "Compress-Archive -Path dist/forest-{{.ITEM.KIND}}-{{.ITEM.THEME}} -DestinationPath dist/forest-{{.ITEM.KIND}}-{{.ITEM.THEME}}.zip"'
clean:
cmds:
- |
{{.SHELL}} -Command "
Remove-Item -Path build/forest-*,build/sunvalley-*,dist/forest-*,dist/sunvalley-* -Recurse -Force"

View File

@ -10,9 +10,9 @@ function Format-SpecName {
)
return @(
$prefix,
(& { if ($theme) { $theme } else { "" } }),
$Kind
).Where({ $_ -ne "" }) -Join "_"
$Kind,
(& { if ($theme) { $theme } else { "" } })
).Where({ $_ -ne "" }) -Join "-"
}
function Compress-Builds {

View File

@ -4,19 +4,19 @@ from pathlib import Path
def build_sunvalley():
buildscript = Path.cwd() / "build.ps1"
subprocess.run(["powershell", str(buildscript), "sv"])
buildscript = Path.cwd() / 'build.ps1'
subprocess.run(['powershell', str(buildscript), 'sunvalley'])
def build_forest():
rewriter = Path.cwd() / "tools" / "rewriter.py"
subprocess.run([sys.executable, str(rewriter), "-r"])
rewriter = Path.cwd() / 'tools' / 'rewriter.py'
subprocess.run([sys.executable, str(rewriter), '--rewrite'])
buildscript = Path.cwd() / "build.ps1"
for theme in ("light", "dark"):
subprocess.run(["powershell", str(buildscript), "fst", theme])
buildscript = Path.cwd() / 'build.ps1'
for theme in ('light', 'dark'):
subprocess.run(['powershell', str(buildscript), 'forest', theme])
subprocess.run([sys.executable, str(rewriter), "-c"])
subprocess.run([sys.executable, str(rewriter), '--restore'])
def build_all():

View File

@ -4,11 +4,11 @@ from pathlib import Path
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("vm-compact-rewriter")
logger = logging.getLogger('vm-compact-rewriter')
PACKAGE_DIR = Path(__file__).parent.parent / "vmcompact"
PACKAGE_DIR = Path(__file__).parent.parent / 'vmcompact'
SRC_DIR = Path(__file__).parent / "src"
SRC_DIR = Path(__file__).parent / 'src'
def write_outs(output, outs: tuple):
@ -17,183 +17,183 @@ def write_outs(output, outs: tuple):
def rewrite_app():
app_logger = logger.getChild("app")
app_logger.info("rewriting app.py")
infile = Path(SRC_DIR) / "app.bk"
outfile = Path(PACKAGE_DIR) / "app.py"
with open(infile, "r") as input:
with open(outfile, "w") as output:
app_logger = logger.getChild('app')
app_logger.info('rewriting app.py')
infile = Path(SRC_DIR) / 'app.bk'
outfile = Path(PACKAGE_DIR) / 'app.py'
with open(infile, 'r') as input:
with open(outfile, 'w') as output:
for line in input:
match line:
# App init()
case " def __init__(self, vmr):\n":
output.write(" def __init__(self, vmr, theme):\n")
case " self._vmr = vmr\n":
case ' def __init__(self, vmr):\n':
output.write(' def __init__(self, vmr, theme):\n')
case ' self._vmr = vmr\n':
write_outs(
output,
(
" self._vmr = vmr\n",
" self._theme = theme\n",
' self._vmr = vmr\n',
' self._theme = theme\n',
' tcldir = Path.cwd() / "theme"\n',
" if not tcldir.is_dir():\n",
' if not tcldir.is_dir():\n',
' tcldir = Path.cwd() / "_internal" / "theme"\n',
' self.tk.call("source", tcldir.resolve() / f"forest-{self._theme}.tcl")\n',
),
)
# def connect()
case "def connect(kind_id: str, vmr) -> App:\n":
case 'def connect(kind_id: str, vmr) -> App:\n':
output.write(
'def connect(kind_id: str, vmr, theme="light") -> App:\n'
)
case " return VMMIN_cls(vmr)\n":
output.write(" return VMMIN_cls(vmr, theme)\n")
case ' return VMMIN_cls(vmr)\n':
output.write(' return VMMIN_cls(vmr, theme)\n')
case _:
output.write(line)
def rewrite_builders():
builders_logger = logger.getChild("builders")
builders_logger.info("rewriting builders.py")
infile = Path(SRC_DIR) / "builders.bk"
outfile = Path(PACKAGE_DIR) / "builders.py"
with open(infile, "r") as input:
with open(outfile, "w") as output:
builders_logger = logger.getChild('builders')
builders_logger.info('rewriting builders.py')
infile = Path(SRC_DIR) / 'builders.bk'
outfile = Path(PACKAGE_DIR) / 'builders.py'
with open(infile, 'r') as input:
with open(outfile, 'w') as output:
ignore_next_lines = 0
for line in input:
if ignore_next_lines > 0:
builders_logger.info(f"ignoring: {line}")
builders_logger.info(f'ignoring: {line}')
ignore_next_lines -= 1
continue
match line:
# loading themes
case "import sv_ttk\n":
output.write("#import sv_ttk\n")
case " self.app.resizable(False, False)\n":
case 'import sv_ttk\n':
output.write('#import sv_ttk\n')
case ' self.app.resizable(False, False)\n':
write_outs(
output,
(
" self.app.resizable(False, False)\n"
" if _configuration.themes_enabled:\n",
' self.app.resizable(False, False)\n'
' if _configuration.themes_enabled:\n',
' ttk.Style().theme_use(f"forest-{self.app._theme}")\n',
' self.logger.info(f"Forest Theme applied")\n',
),
)
ignore_next_lines = 6
# setting navframe button widths
case " variable=self.navframe.submix,\n":
case ' variable=self.navframe.submix,\n':
write_outs(
output,
(
" variable=self.navframe.submix,\n"
" width=8,\n",
' variable=self.navframe.submix,\n'
' width=8,\n',
),
)
case " variable=self.navframe.channel,\n":
case ' variable=self.navframe.channel,\n':
write_outs(
output,
(
" variable=self.navframe.channel,\n"
" width=8,\n",
' variable=self.navframe.channel,\n'
' width=8,\n',
),
)
case " variable=self.navframe.extend,\n":
case ' variable=self.navframe.extend,\n':
write_outs(
output,
(
" variable=self.navframe.extend,\n"
" width=8,\n",
' variable=self.navframe.extend,\n'
' width=8,\n',
),
)
case " variable=self.navframe.info,\n":
case ' variable=self.navframe.info,\n':
write_outs(
output,
(
" variable=self.navframe.info,\n"
" width=8,\n",
' variable=self.navframe.info,\n'
' width=8,\n',
),
)
# set channelframe button widths
case " variable=self.labelframe.mute,\n":
case ' variable=self.labelframe.mute,\n':
write_outs(
output,
(
" variable=self.labelframe.mute,\n"
" width=7,\n",
' variable=self.labelframe.mute,\n'
' width=7,\n',
),
)
case " variable=self.labelframe.conf,\n":
case ' variable=self.labelframe.conf,\n':
write_outs(
output,
(
" variable=self.labelframe.conf,\n"
" width=7,\n",
' variable=self.labelframe.conf,\n'
' width=7,\n',
),
)
case " variable=self.labelframe.on,\n":
case ' variable=self.labelframe.on,\n':
write_outs(
output,
(
" variable=self.labelframe.on,\n"
" width=7,\n",
' variable=self.labelframe.on,\n'
' width=7,\n',
),
)
# set stripconfigframe button widths
case " self.configframe.phys_out_params.index(param)\n":
case ' self.configframe.phys_out_params.index(param)\n':
write_outs(
output,
(
" self.configframe.phys_out_params.index(param)\n",
" ],\n",
" width=6,\n",
' self.configframe.phys_out_params.index(param)\n',
' ],\n',
' width=6,\n',
),
)
ignore_next_lines = 1
case " self.configframe.virt_out_params.index(param)\n":
case ' self.configframe.virt_out_params.index(param)\n':
write_outs(
output,
(
" self.configframe.virt_out_params.index(param)\n",
" ],\n",
" width=6,\n",
' self.configframe.virt_out_params.index(param)\n',
' ],\n',
' width=6,\n',
),
)
ignore_next_lines = 1
# This does both strip and bus param vars buttons
case " variable=self.configframe.param_vars[i],\n":
case ' variable=self.configframe.param_vars[i],\n':
write_outs(
output,
(
" variable=self.configframe.param_vars[i],\n",
" width=6,\n",
' variable=self.configframe.param_vars[i],\n',
' width=6,\n',
),
)
case _:
if "Toggle.TButton" in line:
output.write(line.replace("Toggle.TButton", "ToggleButton"))
if 'Toggle.TButton' in line:
output.write(line.replace('Toggle.TButton', 'ToggleButton'))
else:
output.write(line)
def rewrite_menu():
menu_logger = logger.getChild("menu")
menu_logger.info("rewriting menu.py")
infile = Path(SRC_DIR) / "menu.bk"
outfile = Path(PACKAGE_DIR) / "menu.py"
with open(infile, "r") as input:
with open(outfile, "w") as output:
menu_logger = logger.getChild('menu')
menu_logger.info('rewriting menu.py')
infile = Path(SRC_DIR) / 'menu.bk'
outfile = Path(PACKAGE_DIR) / 'menu.py'
with open(infile, 'r') as input:
with open(outfile, 'w') as output:
ignore_next_lines = 0
for line in input:
if ignore_next_lines > 0:
menu_logger.info(f"ignoring: {line}")
menu_logger.info(f'ignoring: {line}')
ignore_next_lines -= 1
continue
match line:
case "import sv_ttk\n":
output.write("#import sv_ttk\n")
case " # layout/themes\n":
case 'import sv_ttk\n':
output.write('#import sv_ttk\n')
case ' # layout/themes\n':
ignore_next_lines = 14
case _:
output.write(line)
@ -202,13 +202,13 @@ def rewrite_menu():
def prepare_for_build():
################# MOVE FILES FROM PACKAGE DIR INTO SRC DIR #########################
for file in (
PACKAGE_DIR / "app.py",
PACKAGE_DIR / "builders.py",
PACKAGE_DIR / "menu.py",
PACKAGE_DIR / 'app.py',
PACKAGE_DIR / 'builders.py',
PACKAGE_DIR / 'menu.py',
):
if file.exists():
logger.debug(f"moving {str(file)}")
file.rename(SRC_DIR / f"{file.stem}.bk")
logger.debug(f'moving {str(file)}')
file.rename(SRC_DIR / f'{file.stem}.bk')
###################### RUN THE FILE REWRITER FOR EACH *.BK #########################
steps = (
@ -222,29 +222,29 @@ def prepare_for_build():
def cleanup():
########################## RESTORE *.BK FILES #####################################
for file in (
PACKAGE_DIR / "app.py",
PACKAGE_DIR / "builders.py",
PACKAGE_DIR / "menu.py",
PACKAGE_DIR / 'app.py',
PACKAGE_DIR / 'builders.py',
PACKAGE_DIR / 'menu.py',
):
file.unlink()
for file in (
SRC_DIR / "app.bk",
SRC_DIR / "builders.bk",
SRC_DIR / "menu.bk",
SRC_DIR / 'app.bk',
SRC_DIR / 'builders.bk',
SRC_DIR / 'menu.bk',
):
file.rename(PACKAGE_DIR / f"{file.stem}.py")
file.rename(PACKAGE_DIR / f'{file.stem}.py')
if __name__ == "__main__":
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--rewrite", action="store_true")
parser.add_argument("-c", "--cleanup", action="store_true")
parser.add_argument('--rewrite', action='store_true')
parser.add_argument('--restore', action='store_true')
args = parser.parse_args()
if args.rewrite:
logger.info("preparing files for build")
logger.info('preparing files for build')
prepare_for_build()
elif args.cleanup:
logger.info("cleaning up files")
elif args.restore:
logger.info('cleaning up files')
cleanup()