git.iko.soy/rowtype-yoga/purescm
on bytevector help sign in
54 lines 1.4 kB history raw
1#!/usr/bin/env python
3import os
4import re
5import subprocess
6import shutil
7from pathlib import Path
10PURESCRIPT_PATH = Path("test/resources/purescript")
11SOURCE_PATH = PURESCRIPT_PATH / "src"
12OUTPUT_PATH = PURESCRIPT_PATH / "output"
13SCHEME_PATH = Path("test/resources/scheme")
14MODULE_REGEX = re.compile("\s*module\s+([\w\.]+)", re.MULTILINE)
17def run(cmd: list[str], path: str, env=None):
18 old_dir = os.getcwd()
19 os.chdir(path)
20 subprocess.run(cmd, env=env)
21 os.chdir(old_dir)
24def get_source_files(base_path: Path) -> list[Path]:
25 return Path(base_path).glob("**/*.purs")
28def read_module_name(path: Path) -> str:
29 text = path.read_text()
30 match = MODULE_REGEX.match(text)
31 return match.group(1)
34def copy_module(output_path: Path, scheme_path: Path, module_name: str):
35 from_file = output_path / module_name / "lib.sls"
36 to_dir = scheme_path / module_name
37 to_file = to_dir / "lib.sls"
38 os.makedirs(to_dir, exist_ok=True)
39 print(f"{from_file} -> {to_file}")
40 shutil.copy2(from_file, to_file)
43if __name__ == "__main__":
44 run(["stack", "install", "--fast", "--local-bin-path", "/tmp"],
45 PURESCRIPT_PATH)
46 run(["spago", "build"],
47 PURESCRIPT_PATH,
48 {'PATH': "/tmp:" + os.environ["PATH"]})
50 files = get_source_files(SOURCE_PATH)
51 modules = [read_module_name(f) for f in files]
53 for module in modules:
54 copy_module(OUTPUT_PATH, SCHEME_PATH, module)