HunterMcGushion / docstr_coverage

Docstring coverage analysis and rating for Python
MIT License
95 stars 19 forks source link

pre-commit hook with `stages: [commit]` #144

Open LeskoIam opened 4 months ago

LeskoIam commented 4 months ago

When using docstr-coverage with pre-commit and using stages: [commit] e.g.:

  - repo: https://github.com/HunterMcGushion/docstr_coverage
    rev: v2.3.2
    hooks:
      - id: docstr-coverage
        args: ["--verbose", "3", "--percentage-only"]
        verbose: true
        stages: [commit]

.docstr.yaml

# --skip-file-doc, -f - Ignore module docstrings (at the top of files)
skip_file_doc: True
# --skip-class-def, -c - Ignore docstrings of class definitions
skip_class_def: True
# --follow-links, -l - Follow symlinks
follow_links: False
# --skip-magic, -m - Ignore all magic methods (except __init__)
skip_magic: True
# --skip-private, -P - Ignore private functions (starting with a single underscore)
# skip_private: True
accept_empty: True

even though *.py files are present in commit

identity.................................................................Passed
- hook id: identity
- duration: 0.06s
.pre-commit-config.yaml
tests/smth/test_smth_model.py

docstr-coverage passes with warning

docstr-coverage..........................................................Passed
- hook id: docstr-coverage
- duration: 0.19s
C:\Users\...\...\Lib\site-packages\docstr_coverage\cli.py:288: UserWarning: No Python files found in specified paths. Processing aborted
  warnings.warn("No Python files found in specified paths. Processing aborted")

Any input on this? Thank you!

HunterMcGushion commented 4 months ago

Hi, @LeskoIam, thanks for reporting this. Are you able to reproduce this problem when running docstr-coverage manually (outside of pre-commit hooks)?

LeskoIam commented 4 months ago

Hi @HunterMcGushion and thanks for looking into this!

I can reproduce this by manually running the hook, e.g.:


(.venv) ~\workspace\...\ git:[LeskoIam/reproduce-docstr-coverage-issue]
pre-commit run identity
identity.................................................................Passed
- hook id: identity
- duration: 0.06s

.pre-commit-config.yaml
src/my_tests/smth2.py

(.venv) ~\workspace\...\ git:[LeskoIam/reproduce-docstr-coverage-issue]
pre-commit run docstr-coverage
docstr-coverage..........................................................Failed
- hook id: docstr-coverage
- duration: 0.25s
- exit code: 1

No Python files found. Use `--accept-empty` to exit with code 0 if you expect this case, or specify the paths you'd like to check via command line arguments or the config file.

A few details

docstr-coverage==2.3.2
pre-commit==3.7.1
# .pre-commit-config.yaml

repos:
  - repo: meta
    hooks:
      - id: identity

  - repo: https://github.com/HunterMcGushion/docstr_coverage
    rev: v2.3.2
    hooks:
      - id: docstr-coverage
        args: ["--verbose", "3", "--percentage-only"]
        verbose: true
        stages: [commit]
LeskoIam commented 3 months ago

Hey! I forked the repo and added test for single .py file in directory which is passing without a problem.

So I think the problem is with pre-commit package. I'll try to add specific tests for pre-commit hooks.