mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-init-py-trap
25 lines
701 B
Python
25 lines
701 B
Python
import os
|
|
from argparse import ArgumentParser
|
|
from typing import Optional
|
|
from typing import Sequence
|
|
|
|
|
|
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
|
parser = ArgumentParser()
|
|
parser.add_argument('filenames', nargs='*', help='Filenames to check')
|
|
args = parser.parse_args(argv)
|
|
|
|
directories = {os.path.dirname(f) for f in args.filenames}
|
|
missing_dirs = set()
|
|
for d in directories:
|
|
if not os.path.exists(os.path.join(d, '__init__.py')):
|
|
missing_dirs.add(d)
|
|
|
|
for d in sorted(missing_dirs):
|
|
print('No __init__.py file found in: {}'.format(d))
|
|
|
|
return 1 if len(missing_dirs) else 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
exit(main())
|