Skip to content

Commit

Permalink
pkgs/sage-setup/pyproject.toml: Add script sage-generate-meson
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jan 16, 2024
1 parent 903eed0 commit 7059c98
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
4 changes: 4 additions & 0 deletions pkgs/sage-setup/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 18 additions & 15 deletions src/sage_setup/autogen/meson/__init__.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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

0 comments on commit 7059c98

Please sign in to comment.