From 7059c98ab5ff67d5d9533edd0cc2d1925a8dfafc Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 4 Jan 2024 12:54:21 -0800 Subject: [PATCH] pkgs/sage-setup/pyproject.toml: Add script sage-generate-meson --- pkgs/sage-setup/pyproject.toml | 4 +++ src/sage_setup/autogen/meson/__init__.py | 33 +++++++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pkgs/sage-setup/pyproject.toml b/pkgs/sage-setup/pyproject.toml index 1499fe4c9ba..a9062aa38e9 100644 --- a/pkgs/sage-setup/pyproject.toml +++ b/pkgs/sage-setup/pyproject.toml @@ -33,12 +33,16 @@ content-type = "text/x-rst" [project.optional-dependencies] autogen = ["jinja2"] +[project.scripts] +sage-generate-meson = "sage_setup.autogen.meson:generate_meson" + [tool.setuptools] packages = [ "sage_setup", "sage_setup.autogen", "sage_setup.autogen.interpreters", "sage_setup.autogen.interpreters.specs", + "sage_setup.autogen.meson", "sage_setup.command", ] include-package-data = false diff --git a/src/sage_setup/autogen/meson/__init__.py b/src/sage_setup/autogen/meson/__init__.py index 1bcb7fc3871..666d9493bc9 100644 --- a/src/sage_setup/autogen/meson/__init__.py +++ b/src/sage_setup/autogen/meson/__init__.py @@ -1,24 +1,12 @@ # Small script that generates a meson.build file in the given folder. # The generated build file contains all python files as `install_sources` and all cython files as `extension_module` -import argparse import sys from pathlib import Path from types import SimpleNamespace -parser = argparse.ArgumentParser(description='Generate meson.build file for a given folder.') -parser.add_argument('folder', type=str, nargs='?', default='.', - help='folder for which the meson.build file will be generated') -parser.add_argument('--dry-run', '-n', action='store_true', - help='do not write any files, just print the output') -parser.add_argument('--force', '-f', action='store_true', - help='overwrite existing meson.build file') -args = parser.parse_args() - -def run(folder: Path): - dry_run = args.dry_run - force = args.force +def run(folder: Path, dry_run=False, force=False): if not folder.is_dir(): print(f'Error: {folder} is not a directory') @@ -194,5 +182,20 @@ def get_metadata(path: Path): meson_build.write(f"subdir('{subdir.name}')\n") run(subdir) -folder = Path(args.folder) -run(folder) + +def generate_meson(): + import argparse + + parser = argparse.ArgumentParser(description='Generate meson.build file for a given folder.') + parser.add_argument('folder', type=str, nargs='?', default='.', + help='folder for which the meson.build file will be generated') + parser.add_argument('--dry-run', '-n', action='store_true', + help='do not write any files, just print the output') + parser.add_argument('--force', '-f', action='store_true', + help='overwrite existing meson.build file') + + args = parser.parse_args() + + folder = Path(args.folder) + run(folder, dry_run=args.dry_run, force=args.force) + return 0