feat: create omrf packer basic layout

This commit is contained in:
2026-08-01 22:31:39 +08:00
parent 003db65f9c
commit 8e92ceeabd
11 changed files with 101 additions and 7 deletions
-6
View File
@@ -1,6 +0,0 @@
def main():
print("Hello from sarasacw-omrf-packer!")
if __name__ == "__main__":
main()
+10
View File
@@ -3,7 +3,17 @@ name = "sarasacw-omrf-packer"
version = "0.1.0" version = "0.1.0"
description = "Add your description here" description = "Add your description here"
readme = "README.md" readme = "README.md"
authors = [
{ name = "yyc12345", email = "yyc12321@outlook.com" }
]
requires-python = ">=3.13" requires-python = ">=3.13"
dependencies = [ dependencies = [
"jinja2==3.1.6", "jinja2==3.1.6",
] ]
[project.scripts]
sarasacw-omrf-packer = "sarasacw_omrf_packer:main"
[build-system]
requires = ["uv_build>=0.8.0,<0.9"]
build-backend = "uv_build"
@@ -0,0 +1,13 @@
from .archiver import pack
from .cargo import get_artifacts
from .cli import Cli, parse
from .cmake import render as render_cmake
from .pkgconfig import render as render_pkgconfig
def main() -> None:
cli = parse()
get_artifacts(cli.manifest_path)
render_cmake(cli.output_dir)
render_pkgconfig(cli.output_dir)
pack(cli.output_dir, cli.output_dir + ".zip")
@@ -0,0 +1,10 @@
import zipfile
from pathlib import Path
def pack(dist_dir: str, output_zip: str) -> None:
dist = Path(dist_dir)
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zf:
for path in dist.rglob("*"):
if path.is_file():
zf.write(path, path.relative_to(dist))
+22
View File
@@ -0,0 +1,22 @@
import json
import subprocess
def get_metadata(manifest_path: str) -> dict:
cmd = [
"cargo",
"metadata",
"--format-version=1",
f"--manifest-path={manifest_path}",
]
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, _ = proc.communicate()
return json.loads(stdout)
def get_artifacts(manifest_path: str) -> list[str]:
metadata = get_metadata(manifest_path)
target_directory = metadata["target_directory"]
return [target_directory]
+19
View File
@@ -0,0 +1,19 @@
import argparse
from dataclasses import dataclass
@dataclass
class Cli:
manifest_path: str
output_dir: str
def parse() -> Cli:
parser = argparse.ArgumentParser(
prog="sarasacw-omrf-packer",
description="Create distribution and generate CMake and pkg-config files.",
)
parser.add_argument("--manifest-path", default="Cargo.toml")
parser.add_argument("--output-dir", default="dist")
args = parser.parse_args()
return Cli(manifest_path=args.manifest_path, output_dir=args.output_dir)
+13
View File
@@ -0,0 +1,13 @@
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, select_autoescape
def render(output_dir: str) -> None:
templates_dir = Path(__file__).parent / "templates"
env = Environment(
loader=FileSystemLoader(templates_dir),
autoescape=select_autoescape(),
)
out = Path(output_dir)
out.mkdir(parents=True, exist_ok=True)
@@ -0,0 +1,13 @@
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, select_autoescape
def render(output_dir: str) -> None:
templates_dir = Path(__file__).parent / "templates"
env = Environment(
loader=FileSystemLoader(templates_dir),
autoescape=select_autoescape(),
)
out = Path(output_dir)
out.mkdir(parents=True, exist_ok=True)
+1 -1
View File
@@ -69,7 +69,7 @@ wheels = [
[[package]] [[package]]
name = "sarasacw-omrf-packer" name = "sarasacw-omrf-packer"
version = "0.1.0" version = "0.1.0"
source = { virtual = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "jinja2" }, { name = "jinja2" },
] ]