4747TEMPLATE_PARTIALS = [
4848 'partial_header'
4949]
50- TemplateInfo = namedtuple ('TemplateInfo' , 'dest_fmt vars' )
50+ TemplateInfo = namedtuple ('TemplateInfo' , 'dest_fmt vars options ' )
5151TEMPLATES = dict ( # (ordering is significant)
52- model = TemplateInfo ('{packageName}/{model_package}/' , dict (hasMore = True )),
53- __init__model = TemplateInfo ('{packageName}/{model_package}/__init__.py' , {}),
54- api = TemplateInfo ('{packageName}/{api_package}/' , dict (operations = True , hasMore = True )),
55- __init__api = TemplateInfo ('{packageName}/{api_package}/__init__.py' , {}),
56- __init__package = TemplateInfo ('{packageName}/__init__.py' , {}),
57- api_client = TemplateInfo ('{packageName}/api_client.py' , dict (writeBinary = True )),
58- configuration = TemplateInfo ('{packageName}/configuration.py' , {}),
59- rest = TemplateInfo ('{packageName}/rest.py' , {}),
60- requirements = TemplateInfo ('requirements.txt' , {}),
61- setup = TemplateInfo ('setup.py' , {}),
52+ model = TemplateInfo ('{packageName}/{model_package}/' , dict (hasMore = True ), {} ),
53+ __init__model = TemplateInfo ('{packageName}/{model_package}/__init__.py' , {}, {} ),
54+ api = TemplateInfo ('{packageName}/{api_package}/' , dict (operations = True , hasMore = True ), {} ),
55+ __init__api = TemplateInfo ('{packageName}/{api_package}/__init__.py' , {}, {} ),
56+ __init__package = TemplateInfo ('{packageName}/__init__.py' , {}, {} ),
57+ api_client = TemplateInfo ('{packageName}/api_client.py' , dict (writeBinary = True ), {} ),
58+ configuration = TemplateInfo ('{packageName}/configuration.py' , {}, {} ),
59+ rest = TemplateInfo ('{packageName}/rest.py' , {}, {} ),
60+ requirements = TemplateInfo ('requirements.txt' , {}, {} ),
61+ setup = TemplateInfo ('setup.py' , {}, {} ),
6262)
6363TEMPLATES_OPTIONAL = dict ( # (optional templates processed by '--generate' specification)
6464 docs = {
65- 'api_doc' : TemplateInfo ('docs/' , {}),
66- 'model_doc' : TemplateInfo ('docs/' , {}),
65+ 'api_doc' : TemplateInfo ('docs/' , {}, {} ),
66+ 'model_doc' : TemplateInfo ('docs/' , {}, {} ),
6767 'README' : TemplateInfo ('README.md' , dict (gitUserId = "GIT_USER_ID" ,
6868 gitRepoId = "GIT_REPO_ID" ,
6969 generatedDate = datetime .isoformat (datetime .now (), sep = ' ' ,
7272 appVersion = '{packageVersion}' ,
7373 infoUrl = '{packageUrl}' ,
7474 hasMore = True ,
75- )),
75+ ), {} ),
7676 },
7777 tests = {
78- '__init__test' : TemplateInfo ('test/__init__.py' , {}),
79- 'api_test' : TemplateInfo ('test/' , {}),
80- 'model_test' : TemplateInfo ('test/' , {}),
81- 'test-requirements' : TemplateInfo ('test-requirements.txt' , {}),
78+ '__init__test' : TemplateInfo ('test/__init__.py' , {}, {} ),
79+ 'api_test' : TemplateInfo ('test/' , {}, {} ),
80+ 'model_test' : TemplateInfo ('test/' , {}, {} ),
81+ 'test-requirements' : TemplateInfo ('test-requirements.txt' , {}, {} ),
8282 },
8383 git = {
84- 'gitignore' : TemplateInfo ('.gitignore' , {}),
84+ 'gitignore' : TemplateInfo ('.gitignore' , {}, {} ),
8585 'git_push.sh' : TemplateInfo ('git_push.sh' , dict (gitUserId = "GIT_USER_ID" ,
8686 gitRepoId = "GIT_REPO_ID" ,
87- releaseNote = "Minor update" )),
88- 'tox' : TemplateInfo ('tox.ini' , {}),
87+ releaseNote = "Minor update" ), {} ),
88+ 'tox' : TemplateInfo ('tox.ini' , {}, {} ),
8989 },
9090 travis = {
91- 'travis' : TemplateInfo ('.travis.yml' , {}),
91+ 'travis' : TemplateInfo ('.travis.yml' , {}, {} ),
9292 },
9393)
9494TEMPLATES_ASYNC = { # (optional templates processed by '--async_library' option)
95- 'asyncio/rest' : TemplateInfo ('{packageName}/rest.py' , dict (asyncio = True )),
96- 'tornado/rest' : TemplateInfo ('{packageName}/rest.py' , dict (tornado = True )),
95+ 'asyncio/rest' : TemplateInfo ('{packageName}/rest.py' , dict (asyncio = True ), {} ),
96+ 'tornado/rest' : TemplateInfo ('{packageName}/rest.py' , dict (tornado = True ), {} ),
9797}
9898
9999
@@ -127,12 +127,12 @@ def __init__(self, location, alternate=None): # pylint:disable=unused-argument
127127 jar = None
128128 setattr (self , src , self .TemplateSource (src_path , base_path , jar ))
129129
130- def read (self , filename ):
130+ def read (self , filename , ** options ):
131131 """ Reads template file content from a directory or JAR, subject to override. """
132132 # noinspection PyUnusedLocal
133133 content , read_ok = None , False
134134 # First look for template in alternate (override) location, then in default location.
135- for src in ( ' alternate' , 'location' ):
135+ for src in options . get ( 'sources' , ( ' alternate' , 'location' ) ):
136136 with suppress (Exception ):
137137 template_source = getattr (self , src )
138138 path = Path (str (template_source .base_path .joinpath (filename )) + TEMPLATE_EXT ) # (not .with_suffix())
@@ -189,6 +189,10 @@ def __init__(self, settings, params):
189189 if template_info :
190190 TEMPLATES .update ({template_name : template_info })
191191 other_vars .update (template_info .vars )
192+ else :
193+ library = self .settings .get ('library' )
194+ if library == GENERATOR_SETTINGS ['library' ]['default' ]:
195+ TEMPLATES ['rest' ] = TEMPLATES ['rest' ]._replace (options = dict (sources = ('location' ,)))
192196 self .common_vars = {** vars (self .params ), ** self .settings , ** self .info , ** other_vars }
193197 TEMPLATES .update ({t : d for g in self .params .generate for t , d in TEMPLATES_OPTIONAL .get (g , {}).items ()})
194198 self .template_dests = {k : v .dest_fmt .format (** self .common_vars ) for k , v in TEMPLATES .items ()}
@@ -211,7 +215,8 @@ def __init__(self, settings, params):
211215 # Read all templates and partials.
212216 self .template_reader = TemplateReader (params .template_dir , alternate = TEMPLATE_OVERRIDE_DIR )
213217 partials = {template_file : self .template_reader .read (template_file ) for template_file in TEMPLATE_PARTIALS }
214- self .templates = {template_file : self .template_reader .read (template_file ) for template_file in TEMPLATES }
218+ self .templates = {template_file : self .template_reader .read (template_file , ** template_entry .options )
219+ for template_file , template_entry in TEMPLATES .items ()}
215220
216221 # Resolve all settings and parameters passed in common to all renderers.
217222 package_name = self .settings .get ('packageName' , '' )
0 commit comments