Allow main as well as __main__.

This commit is contained in:
Romain Dorgueil
2017-06-08 21:47:13 +02:00
parent 1ca48d885d
commit 89104af3a0
2 changed files with 13 additions and 4 deletions

View File

@ -1,4 +1,4 @@
def execute(name):
def execute(name, branch):
try:
from cookiecutter.main import cookiecutter
except ImportError as exc:
@ -7,10 +7,12 @@ def execute(name):
) from exc
return cookiecutter(
'https://github.com/python-bonobo/cookiecutter-bonobo.git', extra_context={'name': name}, no_input=True
'https://github.com/python-bonobo/cookiecutter-bonobo.git', extra_context={'name': name}, no_input=True,
checkout=branch
)
def register(parser):
parser.add_argument('name')
parser.add_argument('--branch', '-b', default='master')
return execute

View File

@ -3,7 +3,7 @@ import os
DEFAULT_SERVICES_FILENAME = '_services.py'
DEFAULT_SERVICES_ATTR = 'get_services'
DEFAULT_GRAPH_FILENAME = '__main__.py'
DEFAULT_GRAPH_FILENAMES = ('__main__.py', 'main.py',)
DEFAULT_GRAPH_ATTR = 'get_graph'
@ -49,7 +49,14 @@ def execute(filename, module, install=False, quiet=False, verbose=False):
pip.utils.pkg_resources = importlib.reload(pip.utils.pkg_resources)
import site
importlib.reload(site)
filename = os.path.join(filename, DEFAULT_GRAPH_FILENAME)
pathname = filename
for filename in DEFAULT_GRAPH_FILENAMES:
filename = os.path.join(pathname, filename)
if os.path.exists(filename):
break
if not os.path.exists(filename):
raise IOError('Could not find entrypoint (candidates: {}).'.format(', '.join(DEFAULT_GRAPH_FILENAMES)))
elif install:
raise RuntimeError('Cannot --install on a file (only available for dirs containing requirements.txt).')
context = runpy.run_path(filename, run_name='__bonobo__')