@@ -202,15 +202,6 @@ def _assert_valid_key_value(k, v):
202202 help = "Ignore docstrings of functions starting with a single underscore" ,
203203)
204204@click .option ("-l" , "--follow-links" , is_flag = True , help = "Follow symlinks" )
205- @click .option (
206- "-d" ,
207- "--docstr-ignore-file" ,
208- "ignore_names_file" , # TODO: Remove after deprecating in favor of pyproject.toml `blacklist`
209- type = click .Path (exists = False , resolve_path = True ),
210- default = ".docstr_coverage" ,
211- help = "Filepath containing list of regex (file-pattern, name-pattern) pairs" ,
212- show_default = True ,
213- )
214205@click .option (
215206 "-F" ,
216207 "--fail-under" ,
@@ -262,25 +253,18 @@ def _assert_valid_key_value(k, v):
262253@click .option ("--skipclassdef" , is_flag = True , help = "Deprecated. Use --skip-class-def" )
263254@click .option ("--followlinks" , is_flag = True , help = "Deprecated. Use --follow-links" )
264255@click .option ("--failunder" , type = float , help = "Deprecated. Use --fail-under" )
256+ @click .option (
257+ "-d" ,
258+ "--docstr-ignore-file" ,
259+ "ignore_names_file" ,
260+ type = click .Path (exists = False , resolve_path = True ),
261+ default = ".docstr_coverage" ,
262+ help = "Deprecated. Use json config (--config / -C) instead" ,
263+ )
265264def execute (paths , ** kwargs ):
266265 """Measure docstring coverage for `PATHS`"""
267- for deprecated_name , name in [
268- ("skipmagic" , "skip_magic" ),
269- ("skipfiledoc" , "skip_file_doc" ),
270- ("skipinit" , "skip_init" ),
271- ("skipclassdef" , "skip_class_def" ),
272- ("followlinks" , "follow_links" ),
273- ]:
274- if kwargs .get (deprecated_name ):
275- new_flag = name .replace ("_" , "-" )
276- if kwargs .get (name ):
277- raise ValueError (
278- "Should not set deprecated --{} and new --{}" .format (deprecated_name , new_flag )
279- )
280- click .secho (
281- "Using deprecated --{}, should use --{}" .format (deprecated_name , new_flag ), fg = "red"
282- )
283- kwargs [name ] = kwargs .pop (deprecated_name )
266+
267+ _deprecation_alerts (kwargs )
284268
285269 # handle fail under
286270 if kwargs .get ("failunder" ) is not None :
@@ -317,7 +301,7 @@ def execute(paths, **kwargs):
317301 raise ValueError (
318302 (
319303 "The docstr-coverage configuration file {} contains ignore_patterns,"
320- " and at the same time an ignore file {} was found."
304+ " and at the same time a (deprecated) ignore file {} was found."
321305 " Ignore patterns must be specified in only one location at a time."
322306 ).format (kwargs ["config_file" ], kwargs ["ignore_names_file" ])
323307 )
@@ -366,5 +350,45 @@ def execute(paths, **kwargs):
366350 raise SystemExit (0 )
367351
368352
353+ def _deprecation_alerts (kwargs ):
354+ """Warns users if they are using deprecated flags"""
355+ for deprecated_name , name in [
356+ ("skipmagic" , "skip_magic" ),
357+ ("skipfiledoc" , "skip_file_doc" ),
358+ ("skipinit" , "skip_init" ),
359+ ("skipclassdef" , "skip_class_def" ),
360+ ("followlinks" , "follow_links" ),
361+ ]:
362+ if kwargs .get (deprecated_name ):
363+ new_flag = name .replace ("_" , "-" )
364+ if kwargs .get (name ):
365+ raise ValueError (
366+ "Should not set deprecated --{} and new --{}" .format (deprecated_name , new_flag )
367+ )
368+ click .secho (
369+ "Using deprecated --{}, should use --{}" .format (deprecated_name , new_flag ), fg = "red"
370+ )
371+ kwargs [name ] = kwargs .pop (deprecated_name )
372+
373+ # Deprecated old ignore files
374+ ignore_file_old_casing = kwargs .get ("docstr-ignore-file" )
375+ ignore_file_new_casing = kwargs .get ("ignore_names_file" )
376+
377+ def _nondefault_or_existing_file (path ):
378+ if path is None :
379+ return False
380+ return os .path .split (path )[- 1 ] != ".docstr_coverage" or os .path .isfile (path )
381+
382+ if _nondefault_or_existing_file (ignore_file_old_casing ) or _nondefault_or_existing_file (
383+ ignore_file_new_casing
384+ ):
385+ click .secho (
386+ "Using deprecated ignore files."
387+ "We'll keep them supported for a while, "
388+ "but we recommend switching to a proper config file "
389+ "(see commands -C / --config)"
390+ )
391+
392+
369393if __name__ == "__main__" :
370394 execute ()
0 commit comments