Skip to content

Add ability to ignore a file or directory without modifying it #4675

Closed
@adamtheturtle

Description

@adamtheturtle

In a project I maintain, we vendor some third party Python code and the project includes generated files such as files created by python-versioneer.

What I'd like to do is type check all files, including any new files, apart from those that I have explicitly ignored.

Right now I have the following hack workaround:

import subprocess
import sys


def main() -> None:
    args = ['mypy', '.']
    ignore_paths = {
        'src/dcos_e2e/_vendor',
        'src/dcos_e2e/_version.py',
        'versioneer.py',
    }
    result = subprocess.run(args=args, stdout=subprocess.PIPE)
    result_lines = result.stdout.decode().strip().split('\n')
    error_lines = [
        line for line in result_lines
        if not any(line.startswith(path) for path in ignore_paths)
    ]
    print('\n'.join(error_lines))
    sys.exit(int(bool(error_lines)))


if __name__ == '__main__':
    main()

Various tools have mechanisms for doing this, for example:

Adam@MacBook-Pro ~/D/m/d/dcos-e2e> cat .isort.cfg 
[settings]
skip=_vendor,
     src/dcos_e2e/__init__.py,
     versioneer.py,
     setup.py,
[flake8]
exclude=./src/dcos_e2e/_vendor/,
        ./src/dcos_e2e/_version.py,
        ./versioneer.py,
Adam@MacBook-Pro ~/D/m/d/dcos-e2e> cat pylintrc | grep ignore= -A 3
ignore=CVS,
       _vendor,
      versioneer.py,
      _version.py,

Thank you for the software.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions