Skip to content

Commit

Permalink
Add option to change metadata output location (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
theacodes committed Nov 20, 2018
1 parent 59393a6 commit c239da8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 10 additions & 4 deletions synthtool/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@

import importlib
import os
import sys

import click

from synthtool import log
import synthtool.log
import synthtool.metadata


@click.command()
@click.version_option(message="%(version)s")
@click.argument("synthfile", default="synth.py")
def main(synthfile):
@click.option("--metadata", default="synth.metadata")
def main(synthfile, metadata):
synthtool.metadata.register_exit_hook(outfile=metadata)

synth_file = os.path.abspath(synthfile)

if os.path.lexists(synth_file):
log.debug(f"Executing {synth_file}.")
synthtool.log.debug(f"Executing {synth_file}.")
# https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
spec = importlib.util.spec_from_file_location("synth", synth_file)
synth_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(synth_module)
else:
log.exception(f"{synth_file} not found.")
synthtool.log.exception(f"{synth_file} not found.")
sys.exit(1)


if __name__ == "__main__":
Expand Down
6 changes: 0 additions & 6 deletions synthtool/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import atexit
import functools
import sys

import google.protobuf.json_format

Expand Down Expand Up @@ -57,8 +56,3 @@ def write(outfile: str = "synth.metadata") -> None:

def register_exit_hook(**kwargs) -> None:
atexit.register(functools.partial(write, **kwargs))


# Only register this hook if pytest is not active.
if "pytest" not in sys.modules: # pragma: no cover
register_exit_hook()

0 comments on commit c239da8

Please sign in to comment.