Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a way to exclude directories from files or ignore errors in certain directories #8309

Closed
brianmaissy opened this issue Jan 21, 2020 · 12 comments

Comments

@brianmaissy
Copy link

I have a use case for which I am having trouble finding a way to configure my mypy.ini.

I have a project which includes (for whatever legacy reason) a directory containing nested subdirectories (not modules) of python scripts inside my codebase.

The directory structure is something like this:

myproject/
    __init__.py
    submodule/
        __init__.py
        ...
    another_submodule/
        __init__.py
        ...
    scripts/
        __init__.py
        dir1/
            script1.py
        dir2/
            script2.py

These files are included in my files=myproject/**/*.py wildcard, but I would like to find a way to exclude them from mypy (or to ignore errors found in them).

I can define ignore_errors = True for specific submodules, but the scripts are not part the myproject.scripts module because the subdirectories aren't modules.

Obviously the correct solution is to move the scripts directory outside of the myproject module, but let's say that isn't within my power.

I could also create __init__.py files in all of the subdirectories (and nested subdirectories), turning them into artificial modules, but let's also that that isn't within my power.

What I'm looking for is a way to define a wildcard of files to be excluded from the files= configuration parameter, or a way to define a subsection in the configuration file based on a files wildcard rather than a module wildcard, and then I can configure ignore_errors = True.

Is there some other suggested solution, or could something along the lines of one of these be implemented?

@ilevkivskyi
Copy link
Member

or a way to define a subsection in the configuration file based on a files wildcard rather than a module wildcard, and then I can configure ignore_errors = True.

It is unlikely mypy will support file wildcards in foreseeable future, since module is a "fundamental" build unit. For such complex cases you can have a short script to calculate exact list of files to check and pass it to mypy using @filelist.txt, see https://mypy.readthedocs.io/en/stable/running_mypy.html#reading-a-list-of-files-from-a-file

@brianmaissy
Copy link
Author

That works for CI, now all of the other developers on my projects need to know that they need to run some script that I write to wrap mypy, and sort of breaks the elegance of pre-configuring a mypy.ini file and then just being able to run mypy.

I understand your explanation of why you wouldn't want to support sections based on file wildcards, but why not an exclude configuration option to complement the files option?

@ilevkivskyi
Copy link
Member

but why not an exclude configuration option to complement the files option?

IMO this would be really low priority, since this is a rare case and there is already one way to do it. However, if anyone else on the team thinks this may be useful, they will re-open the issue.

@brianmaissy
Copy link
Author

Would it help if I were to volunteer to implement it?

@ilevkivskyi
Copy link
Member

Would it help if I were to volunteer to implement it?

Most likely yes, I will leave this up to @JukkaL to decide.

@brianmaissy
Copy link
Author

@JukkaL did you get a chance to consider this use case?

@Adamantish
Copy link

Adamantish commented Jan 15, 2021

I don't think it's such a rare use case. flake8 and black both have --exclude options. Black even has two. I guess it comes down to a question of philosophy. One could take the unixy approach of having the smallest possible interface for a library (thinking of it as a machine component) or one can treat it as a piece of software for soft humans with a clean core interface plus extras to suit human foibles. The fact that it's a rich developer tool rather than a system component speaks for the latter.

@Borda
Copy link

Borda commented Jan 23, 2021

Hi, +1 for exclude option, we fall into this problem too with update from 0.790 to 0.800 and it annoying... :]

@hauntsaninja
Copy link
Collaborator

Basically a dupe of #4675, which I re-opened

@shaunc
Copy link

shaunc commented Jan 29, 2021

@hauntsaninja -- but perhaps helpful if you answer @brianmaissy 's question as to whether he could contribute a PR here -- IMHO no reason for him to have to run around to different threads with his offer to help...

@hithwen
Copy link

hithwen commented May 4, 2021

Isn't an exclude option documented on https://mypy.readthedocs.io/en/latest/command_line.html#cmdoption-mypy-exclude ?

@brianmaissy
Copy link
Author

Maybe that would have covered my use case if it had existed then; honestly in the last year and a half I've forgotten exactly what my original use case was. Apparently I found an acceptable workaround. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants