Skip to content

Commit

Permalink
Draft: transonic/init_meson.py
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Feb 19, 2024
1 parent 3abd3fd commit e000288
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mpi = ["mpi4py"]

[project.scripts]
transonic = "transonic.run:run"
transonic-init-meson = "transonic.init_meson:main"

[tool.pdm]
package-dir = "src"
Expand Down
52 changes: 52 additions & 0 deletions src/transonic/init_meson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from pathlib import Path


template = """
python_sources = [
{sources}
]
py.install_sources(
python_sources,
subdir: '{subdir}'
)
"""


def process_directory(path_dir):

print(f"Process {path_dir}")

names_py = sorted(path.name for path in path_dir.glob("*.py"))
print(f"{names_py = }")
paths_subdirs = [
path
for path in path_dir.glob("*")
if path.is_dir() and not path.name.startswith("__")
]

names_subdirs = sorted(path.name for path in paths_subdirs)
print(f"{names_subdirs = }")

if names_py:
code = template.format(
sources="\n".join(f" '{name}'," for name in names_py), subdir=path_dir
)
else:
code = ""

if names_subdirs:
code += "\n" + "\n".join(f"subdir('{name}')" for name in names_subdirs) + "\n"

if not code:
return

with open(path_dir / "meson.build", "w", encoding="utf-8") as file:
file.write(code)

for path_subdir in paths_subdirs:
process_directory(path_subdir)


def main():
raise NotImplementedError()

0 comments on commit e000288

Please sign in to comment.