Commit 85ada63a by nzy

dependencies in order of appearence

parent f7a00c05
__pycache__/*
js/node_modules/*
\ No newline at end of file
js/node_modules/*
node_modules/*
descriptions/*.json
\ No newline at end of file
......@@ -6,6 +6,7 @@ import os
import tempfile
import asyncio
from pathlib import Path
import re
dest_lib = Path("./descriptions")
fun_lib = Path("./js")
......@@ -37,10 +38,15 @@ def input_content(content):
content = f.read()
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):
if (path := fun_lib / f"{fun_name}.js").exists():
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:
content = sketch_template(fun_name)
code = input_content(content)
......
......@@ -40,8 +40,7 @@ def create_sketch(fun_name, code):
for hole in holes:
final_code.append(f"const {{ {hole} }} = require('./{hole}.js');")
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)
with open(fun_lib / f"{fun_name}.js", "w") as f:
......
......@@ -7,7 +7,7 @@ def find_holes(fun_name):
result = subprocess.run(cmd, capture_output=True, text=True, shell=True)
holes = set()
holes = []
eslint_output = json.loads(result.stdout)
for item in eslint_output:
messages = item.get('messages', [])
......@@ -15,7 +15,9 @@ def find_holes(fun_name):
if message.get('ruleId') == 'no-undef':
m = re.search(r"'(.*?)' is not defined", message.get("message"))
if m:
holes.add(m.group(1))
name = m.group(1)
if name not in holes:
holes.append(name)
return holes
if __name__ == "__main__":
......
......@@ -30,4 +30,12 @@ async def synthesis():
dest = json.load(f)
if dest["state"] == "x":
names.append(dest_path.stem)
await asyncio.gather(*[synthesis_1(fun) for fun in names])
\ No newline at end of file
await asyncio.gather(*[synthesis_1(fun) for fun in names])
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