From 0b499d62b5815e4ed9bed1eee35eee3c1e51b6d9 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 15 Aug 2026 22:51:21 +0000 Subject: [PATCH 1/2] generate: make layout more intuitive Instead of `com.example.App.toml` and `sources/com.example.App/*``, create `com.example.App/` with a `sources`, `patches`, and `build.toml` inside of it. Fixes: #40 --- flatpaker/actions/generate.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/flatpaker/actions/generate.py b/flatpaker/actions/generate.py index 94af8b1..13c4153 100644 --- a/flatpaker/actions/generate.py +++ b/flatpaker/actions/generate.py @@ -3,6 +3,7 @@ from __future__ import annotations +import os import pathlib import shutil import typing @@ -19,7 +20,9 @@ def generate(args: GenerateArguments) -> bool: name = f'{args.url}.{util.sanitize_name(args.appname)}' - sourcedir = pathlib.Path('sources') / name + projectdir = pathlib.Path(name) + sourcedir = projectdir / 'sources' + patchdir = projectdir / 'patches' doc = tomlkit.document() @@ -47,7 +50,7 @@ def add(table: tomlkit.items.Table, key: str, entry: object, archives: list[tomlkit.items.Table] = [] for src in [args.archive] + args.archives: archive = tomlkit.table() - add(archive, 'path', sourcedir.joinpath(pathlib.Path(src).name).as_posix()) + add(archive, 'path', os.path.join(sourcedir.name, os.path.basename(src))) add(archive, 'sha256', util.sha256(pathlib.Path(src))) archives.append(archive) @@ -58,7 +61,7 @@ def add(table: tomlkit.items.Table, key: str, entry: object, patches: list[tomlkit.items.Table] = [] for src in args.patches: patch = tomlkit.table() - add(patch, 'path', sourcedir.joinpath(pathlib.Path(src).name).as_posix()) + add(patch, 'path', os.path.join(patchdir.name, os.path.basename(src))) patches.append(patch) sources.add('patches', patches) @@ -66,7 +69,7 @@ def add(table: tomlkit.items.Table, key: str, entry: object, files: list[tomlkit.items.Table] = [] for src in args.patches: file = tomlkit.table() - add(file, 'path', sourcedir.joinpath(pathlib.Path(src).name).as_posix()) + add(file, 'path', os.path.join(sourcedir.name, os.path.basename(src))) files.append(file) sources.add('files', files) @@ -76,15 +79,18 @@ def add(table: tomlkit.items.Table, key: str, entry: object, # this ensures that even if the sources are not checked into git that the # folder will be sourcedir.joinpath('.gitkeep').touch() + patchdir.joinpath('.gitkeep').touch() - with open(f'{name}.toml', 'w') as f: + with projectdir.joinpath('build.toml').open('w', encoding='utf-8') as f: tomlkit.dump(doc, f) # move files after writing the toml, so we don't move things then fail - for src in [args.archive] + args.archives + args.patches + args.files: - srcp = pathlib.Path(src) - dest = sourcedir / srcp.name - if dest != srcp: - shutil.move(src, sourcedir) + for srcs, subdir in [([args.archive] + args.archives + args.files, sourcedir), + (args.patches, patchdir)]: + for src in srcs: + srcp = pathlib.Path(src) + dest = subdir / srcp.name + if dest != srcp: + shutil.move(src, subdir) return True From f5c7d3e89038290817095096557d248cad09ad51 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sun, 16 Aug 2026 00:12:56 +0000 Subject: [PATCH 2/2] generate: Add a .gitignore file into the sources directory --- flatpaker/actions/generate.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flatpaker/actions/generate.py b/flatpaker/actions/generate.py index 13c4153..8a28bf9 100644 --- a/flatpaker/actions/generate.py +++ b/flatpaker/actions/generate.py @@ -75,12 +75,18 @@ def add(table: tomlkit.items.Table, key: str, entry: object, doc.add('sources', sources) - sourcedir.mkdir(parents=True, exist_ok=True) - # this ensures that even if the sources are not checked into git that the + # this ensures that even if there are not patches checked into git that the # folder will be - sourcedir.joinpath('.gitkeep').touch() + patchdir.mkdir(parents=True, exist_ok=True) patchdir.joinpath('.gitkeep').touch() + # It's assumed that sources will not be checked into git but by writing a + # file in the directory, we ensure that the directory will be saved/restored + # by `git`. + sourcedir.mkdir(parents=True, exist_ok=True) + with sourcedir.joinpath('.gitignore').open('w', encoding='utf-8') as f: + f.write('*') + with projectdir.joinpath('build.toml').open('w', encoding='utf-8') as f: tomlkit.dump(doc, f)