Skip to content

Commit

Permalink
Make synthtool an executable (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 authored and theacodes committed Sep 19, 2018
1 parent ad9774b commit d2d2ba0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
version = '0.8.0'
release_status = 'Development Status :: 3 - Alpha'
dependencies = [
"click",
"colorlog",
"jinja2",
"packaging",
"requests",
]

packages = setuptools.find_packages()

scripts = [
'synthtool=synthtool.__main__:main'
]

setuptools.setup(
name=name,
Expand All @@ -50,4 +53,7 @@
install_requires=dependencies,
include_package_data=True,
zip_safe=False,
entry_points={
'console_scripts': scripts,
},
)
35 changes: 35 additions & 0 deletions synthtool/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib
import os

import click

from synthtool import log


@click.command()
@click.version_option(message="%(version)s")
def main():
synth_file = os.path.join(os.getcwd(), "synth.py")

if os.path.lexists(synth_file):
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.")

0 comments on commit d2d2ba0

Please sign in to comment.