1313# limitations under the License.
1414
1515from collections import defaultdict
16+ from os import path
1617from typing import Any , DefaultDict , Dict , FrozenSet , List , Optional , Tuple
1718
1819import dataclasses
@@ -95,13 +96,19 @@ def build(cls, opt_string: str) -> 'Options':
9596 # may be our default; perform that replacement.
9697 default_token = 'DEFAULT'
9798 templates = opts .pop ('templates' , [default_token ])
98- default_path = os .path .realpath (
99- os .path .join (os .path .dirname (__file__ ), '..' , 'templates' ),
100- )
101- templates = [
102- (default_path if path == default_token else path )
103- for path in templates
104- ]
99+ pwd = path .join (path .dirname (__file__ ), '..' )
100+ default_path = path .realpath (path .join (pwd , 'templates' ))
101+
102+ def tweak_path (p ):
103+ if p == default_token :
104+ return default_path
105+
106+ if path .isabs (p ):
107+ return path .normpath (p )
108+
109+ return path .normpath (path .join (pwd , p ))
110+
111+ templates = [tweak_path (p ) for p in templates ]
105112
106113 retry_cfg = None
107114 retry_paths = opts .pop ('retry-config' , None )
@@ -121,7 +128,7 @@ def build(cls, opt_string: str) -> 'Options':
121128 for s in sample_paths
122129 for cfg_path in samplegen_utils .generate_all_sample_fpaths (s )
123130 ),
124- templates = tuple (os . path .expanduser (i ) for i in templates ),
131+ templates = tuple (path .expanduser (i ) for i in templates ),
125132 lazy_import = bool (opts .pop ('lazy-import' , False )),
126133 old_naming = bool (opts .pop ('old-naming' , False )),
127134 )
0 commit comments