Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add option to change metadata output location #141

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()