Commit 85ada63a by nzy

dependencies in order of appearence

parent f7a00c05
__pycache__/* __pycache__/*
js/node_modules/* js/node_modules/*
\ No newline at end of file node_modules/*
descriptions/*.json
\ No newline at end of file
...@@ -6,6 +6,7 @@ import os ...@@ -6,6 +6,7 @@ import os
import tempfile import tempfile
import asyncio import asyncio
from pathlib import Path from pathlib import Path
import re
dest_lib = Path("./descriptions") dest_lib = Path("./descriptions")
fun_lib = Path("./js") fun_lib = Path("./js")
...@@ -37,10 +38,15 @@ def input_content(content): ...@@ -37,10 +38,15 @@ def input_content(content):
content = f.read() content = f.read()
return content return content
require_pattern = r"const \{ ([^}]+) \} = require\('\.\/\1\.js'\);"
exports_pattern = r"exports\.(?P<hole2>[a-zA-Z_]\w*) = \1;\s*"
def sketch(fun_name): def sketch(fun_name):
if (path := fun_lib / f"{fun_name}.js").exists(): if (path := fun_lib / f"{fun_name}.js").exists():
with open(path, "r") as f: with open(path, "r") as f:
content = f.read() raw_content = f.read()
content = re.sub(require_pattern, '', raw_content)
content = re.sub(exports_pattern, '', content)
content = content.strip()
else: else:
content = sketch_template(fun_name) content = sketch_template(fun_name)
code = input_content(content) code = input_content(content)
......
...@@ -40,8 +40,7 @@ def create_sketch(fun_name, code): ...@@ -40,8 +40,7 @@ def create_sketch(fun_name, code):
for hole in holes: for hole in holes:
final_code.append(f"const {{ {hole} }} = require('./{hole}.js');") final_code.append(f"const {{ {hole} }} = require('./{hole}.js');")
final_code.append(code) final_code.append(code)
if not code.split("\n")[-1].startswith("exports"): final_code.append(f"exports.{fun_name} = {fun_name};")
final_code.append(f"exports.{fun_name} = {fun_name};")
final_code = "\n".join(final_code) final_code = "\n".join(final_code)
with open(fun_lib / f"{fun_name}.js", "w") as f: with open(fun_lib / f"{fun_name}.js", "w") as f:
......
...@@ -7,7 +7,7 @@ def find_holes(fun_name): ...@@ -7,7 +7,7 @@ def find_holes(fun_name):
result = subprocess.run(cmd, capture_output=True, text=True, shell=True) result = subprocess.run(cmd, capture_output=True, text=True, shell=True)
holes = set() holes = []
eslint_output = json.loads(result.stdout) eslint_output = json.loads(result.stdout)
for item in eslint_output: for item in eslint_output:
messages = item.get('messages', []) messages = item.get('messages', [])
...@@ -15,7 +15,9 @@ def find_holes(fun_name): ...@@ -15,7 +15,9 @@ def find_holes(fun_name):
if message.get('ruleId') == 'no-undef': if message.get('ruleId') == 'no-undef':
m = re.search(r"'(.*?)' is not defined", message.get("message")) m = re.search(r"'(.*?)' is not defined", message.get("message"))
if m: if m:
holes.add(m.group(1)) name = m.group(1)
if name not in holes:
holes.append(name)
return holes return holes
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -30,4 +30,12 @@ async def synthesis(): ...@@ -30,4 +30,12 @@ async def synthesis():
dest = json.load(f) dest = json.load(f)
if dest["state"] == "x": if dest["state"] == "x":
names.append(dest_path.stem) names.append(dest_path.stem)
await asyncio.gather(*[synthesis_1(fun) for fun in names]) await asyncio.gather(*[synthesis_1(fun) for fun in names])
\ No newline at end of file
async def synthesis_1_inorder(fun_name):
dest_path = dest_lib / f"{fun_name}.json"
with open(dest_path, "r") as f:
dependencies = json.load(f)["dependencies"]
for name in dependencies:
await synthesis_1(name)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment