Skip to content

Commit

Permalink
incorporate review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
apwojcik committed Oct 9, 2023
1 parent 26237b4 commit df72a4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
20 changes: 6 additions & 14 deletions tools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,6 @@ def add_function(name: str, *args, **kwargs) -> Function:
return f


def register_functions(path: Union[Path, str]) -> None:
runpy.run_path(path if isinstance(path, str) else str(path))


def once(f: Callable) -> Any:
@wraps(f)
def decorated(*args, **kwargs):
Expand Down Expand Up @@ -1286,21 +1282,17 @@ def template_eval(template, **kwargs):
return template


def invoke(path: Union[Path, str]) -> str:
def run(path: Union[Path, str]) -> str:
return template_eval(open(path).read())


def run(args: List[str]) -> None:
register_functions(args[0])
if len(args) > 1:
r = invoke(args[1])
if __name__ == "__main__":
sys.modules['api'] = sys.modules['__main__']
runpy.run_path(sys.argv[1])
if len(sys.argv) > 2:
r = run(sys.argv[2])
sys.stdout.write(r)
else:
sys.stdout.write(generate_c_header())
sys.stdout.write(generate_c_api_body())
# sys.stdout.write(generate_cpp_header())


if __name__ == "__main__":
sys.modules['api'] = sys.modules['__main__']
run(sys.argv[1:])
13 changes: 6 additions & 7 deletions tools/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################
import os, sys, argparse, subprocess, te, api
import api, argparse, os, runpy, subprocess, sys, te
from pathlib import Path

clang_format_path = Path('clang-format.exe' if os.name ==
Expand All @@ -43,12 +43,12 @@ def clang_format(buffer, **kwargs):

def api_generate(input_path: Path, output_path: Path):
with open(output_path, 'w') as f:
f.write(clang_format(api.invoke(input_path)))
f.write(clang_format(api.run(input_path)))


def te_generate(input_path: Path, output_path: Path):
with open(output_path, 'w') as f:
f.write(clang_format(te.invoke(input_path)))
f.write(clang_format(te.run(input_path)))


def main():
Expand All @@ -66,11 +66,10 @@ def main():
return

try:
for f in [
f for f in Path('include').absolute().iterdir() if f.is_file()
]:
files = Path('include').absolute().iterdir()
for f in [f for f in files if f.is_file()]:
te_generate(f, src_dir / f'include/migraphx/{f.name}')
api.register_functions(str(migraphx_py_path))
runpy.run_path(str(migraphx_py_path))
api_generate(work_dir / 'api/migraphx.h',
src_dir / 'api/include/migraphx/migraphx.h')
print('Finished generating header migraphx.h')
Expand Down
4 changes: 2 additions & 2 deletions tools/te.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ def template_eval(template, **kwargs):
return template


def invoke(p):
def run(p):
return template_eval(open(p).read())


if __name__ == '__main__':
sys.stdout.write(invoke(sys.argv[1]))
sys.stdout.write(run(sys.argv[1]))

0 comments on commit df72a4c

Please sign in to comment.