@@ -132,7 +132,7 @@ def report_execution_time():
132132
133133@click .command ()
134134@click .version_option (__version__ )
135- @click .argument ("source_dir " , type = click .Path (exists = True , file_okay = False ))
135+ @click .argument ("root_path " , type = click .Path (exists = True ))
136136@click .option (
137137 "-o" ,
138138 "--out-dir" ,
@@ -154,7 +154,7 @@ def report_execution_time():
154154@click .option ("-v" , "--verbose" , count = True , help = "Log more details." )
155155@click .help_option ("-h" , "--help" )
156156@report_execution_time ()
157- def main (source_dir , out_dir , config_path , group_errors , verbose ):
157+ def main (root_path , out_dir , config_path , group_errors , verbose ):
158158 """Generate Python stub files from docstrings.
159159 \f
160160
@@ -170,26 +170,29 @@ def main(source_dir, out_dir, config_path, group_errors, verbose):
170170
171171 _setup_logging (verbose = verbose )
172172
173- source_dir = Path (source_dir )
173+ root_path = Path (root_path )
174174 config = _load_configuration (config_path )
175- known_imports = _build_import_map (config , source_dir )
175+ known_imports = _build_import_map (config , root_path )
176176
177177 reporter = GroupedErrorReporter () if group_errors else ErrorReporter ()
178178 types_db = TypesDatabase (
179- source_pkgs = [source_dir .parent .resolve ()], known_imports = known_imports
179+ source_pkgs = [root_path .parent .resolve ()], known_imports = known_imports
180180 )
181181 stub_transformer = Py2StubTransformer (
182182 types_db = types_db , replace_doctypes = config .replace_doctypes , reporter = reporter
183183 )
184184
185185 if not out_dir :
186- out_dir = source_dir .parent / (source_dir .name + "-stubs" )
186+ if root_path .is_file ():
187+ out_dir = root_path .parent
188+ else :
189+ out_dir = root_path .parent / (root_path .name + "-stubs" )
187190 out_dir = Path (out_dir )
188191 out_dir .mkdir (parents = True , exist_ok = True )
189192
190193 # Stub generation ---------------------------------------------------------
191194
192- for source_path , stub_path in walk_source_and_targets (source_dir , out_dir ):
195+ for source_path , stub_path in walk_source_and_targets (root_path , out_dir ):
193196 if source_path .suffix .lower () == ".pyi" :
194197 logger .debug ("using existing stub file %s" , source_path )
195198 with source_path .open () as fo :
0 commit comments