Skip to content

Commit 472001a

Browse files
Merge pull request #87 from MiWeiss/deprecate-ignore-file
Deprecate old config file
2 parents 3e559e9 + af44e87 commit 472001a

File tree

2 files changed

+55
-39
lines changed

2 files changed

+55
-39
lines changed

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ docstr-coverage some_project/src
9292
- 3 - Also print missing docstrings (function names, class names, etc.)
9393
- 4 - Also print information about present docstrings
9494
- _--fail-under=<int|float>, -F <int|float>_ - Fail if under a certain percentage of coverage (default: 100.0)
95-
- _--docstr-ignore-file=\<filepath\>, -d \<filepath\>_ - Filepath containing list of patterns to ignore. Patterns are (file-pattern, name-pattern) pairs
96-
- File content example:
97-
98-
```
99-
SomeFile method_to_ignore1 method_to_ignore2 method_to_ignore3
100-
FileWhereWeWantToIgnoreAllSpecialMethods __.+__
101-
.* method_to_ignore_in_all_files
102-
a_very_important_view_file ^get$ ^set$ ^post$
103-
detect_.* get_val.*
104-
```
10595
- _--badge=\<filepath\>, -b \<filepath\>_ - Generate a docstring coverage percent badge as an SVG saved to a given filepath
10696
- Include the badge in a repo's README using
10797
```[![docstr_coverage](<filepath/of/your/saved/badge.svg>)](https://github.com/HunterMcGushion/docstr_coverage)```,
@@ -152,8 +142,10 @@ docstr-coverage docstr_coverage -e ".*/test" --skip-magic --skip-init --badge="d
152142

153143
Note that options passed as command line arguments have precedence over options
154144
configured in a config file.
155-
Exception: If a `--docstr-ignore-file` is present and the yml config contains `ignore_patterns`,
156-
a `ValueError` is raised.
145+
146+
#### Ignoring by Regex
147+
In your config files, using `ignore_patterns`, you can specify regex patterns for files names and nodes (methods, ...)
148+
which should be ignored. See config file example above.
157149

158150
#### Overriding by Comments
159151
Note that `docstr-coverage` can not parse

docstr_coverage/cli.py

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)
265264
def 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+
369393
if __name__ == "__main__":
370394
execute()

0 commit comments

Comments
 (0)