You can install mypy without the binaries, but it's going to be slower.
python3 -m pip install --no-binary mypy -U mypy
Once this is installed, you can create a patch, say mypy-custom.py like so:
import sys
from typing import List, Optional, Sequence
import mypy.main
from mypy.modulefinder import BuildSource
from mypy.fscache import FileSystemCache
from mypy.options import Options
orig_create_source_list = mypy.main.create_source_list
def create_source_list(paths: Sequence[str], options: Options,
fscache: Optional[FileSystemCache] = None,
allow_empty_dir: bool = True) -> List[BuildSource]:
return orig_create_source_list(paths, options, fscache, allow_empty_dir)
mypy.main.create_source_list = create_source_list
mypy.main.main(None, sys.stdout, sys.stderr)
The patched version should be called with:
python mypy-custom.py [<options>] <path>
If you pass a folder without any .py files, you should get an exit code of 0 with the following output:
Nothing to do?!
Success: no issues found in 0 source files
As suggested by @Numerlor, the patch can also be written like so:
import sys
from functools import partial
import mypy.find_sources
from mypy import api
orig_create_source_list = mypy.find_sources.create_source_list
create_source_list = partial(orig_create_source_list, allow_empty_dir=True)
mypy.find_sources.create_source_list = create_source_list
result = api.run(sys.argv[1:])
if result[0]:
print(result[0])
if result[1]:
print(result[1])
exit(result[2])
With this patch, the allow_empty_dir=False option becomes unavailable to the rest of the module, but it doesn't seem to break anything... yet!