def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sources, options = process_options() if options.pdb: set_drop_into_pdb(True) if not options.dirty_stubs: git.verify_git_integrity_or_abort(build.default_data_dir(bin_dir)) f = sys.stdout try: if options.target == build.TYPE_CHECK: res = type_check_only(sources, bin_dir, options) a = res.errors else: raise RuntimeError("unsupported target %d" % options.target) except CompileError as e: a = e.messages if not e.use_stdout: f = sys.stderr if a: for m in a: f.write(m + "\n") sys.exit(1)
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sources, options = process_options() if options.pdb: set_drop_into_pdb(True) if not options.dirty_stubs: git.verify_git_integrity_or_abort(build.default_data_dir(bin_dir)) f = sys.stdout try: if options.target == build.TYPE_CHECK: res = type_check_only(sources, bin_dir, options) a = res.errors else: raise RuntimeError('unsupported target %d' % options.target) except CompileError as e: a = e.messages if not e.use_stdout: f = sys.stderr if a: for m in a: f.write(m + '\n') sys.exit(1)
def main() -> None: """Main entry point to the type checker. """ sources, options = process_options(sys.argv[1:]) if not options.dirty_stubs: git.verify_git_integrity_or_abort(build.default_data_dir()) try: if options.target == build.TYPE_CHECK: type_check_only(sources, options) else: raise RuntimeError('unsupported target %s' % options.target.name) except CompileError as e: for m in e.messages: sys.stderr.write(m + '\n') sys.exit(1)
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sources, options = process_options(sys.argv[1:]) if not options.dirty_stubs: git.verify_git_integrity_or_abort(build.default_data_dir(bin_dir)) try: if options.target == build.TYPE_CHECK: type_check_only(sources, bin_dir, options) else: raise RuntimeError('unsupported target %d' % options.target) except CompileError as e: for m in e.messages: sys.stderr.write(m + '\n') sys.exit(1)
import os.path import sys if sys.version_info < (3, 4, 0): sys.stderr.write("ERROR: You need Python 3.4 or later to use mypy.\n") exit(1) # This requires setuptools when building; setuptools is not needed # when installing from a wheel file (though it is still neeeded for # alternative forms of installing, as suggested by README.md). from setuptools import setup from setuptools.command.build_py import build_py from mypy.version import __version__ as version from mypy import git git.verify_git_integrity_or_abort(".") description = 'Optional static typing for Python' long_description = ''' Mypy -- Optional Static Typing for Python ========================================= Add type annotations to your Python programs, and use mypy to type check them. Mypy is essentially a Python linter on steroids, and it can catch many programming errors by analyzing your program, without actually having to run it. Mypy has a powerful type system with features such as type inference, gradual typing, generics and union types. '''.lstrip()
def main() -> None: sanity() verbosity = 0 whitelist = [] # type: List[str] blacklist = [] # type: List[str] arglist = [] # type: List[str] list_only = False xfail_only = False dirty_stubs = False allow_opts = True curlist = whitelist args = sys.argv[1:] for i, a in enumerate(args, 1): if curlist is not arglist and allow_opts and a.startswith('@'): with open(a[1:]) as f: args[i:i] = [x[:-1] for x in f] continue if curlist is not arglist and allow_opts and a.startswith('-'): if curlist is not whitelist: break if a == '--': allow_opts = False elif a == '-v' or a == '--verbose': verbosity += 1 elif a == '-q' or a == '--quiet': verbosity -= 1 elif a == '-x' or a == '--exclude': curlist = blacklist elif a == '-a' or a == '--argument': curlist = arglist elif a == '-l' or a == '--list': list_only = True elif a == '--xfail': xfail_only = True elif a == '-f' or a == '--dirty-stubs': dirty_stubs = True elif a == '-h' or a == '--help': usage(0) else: usage(1) else: curlist.append(a) curlist = whitelist if curlist is blacklist: sys.exit('-x must be followed by a filter') if curlist is arglist: sys.exit('-a must be followed by an argument') if xfail_only and whitelist: sys.exit('Sorry, --xfail can only be used with blacklist right now') # empty string is a substring of all names if not xfail_only and not whitelist: whitelist.append('') driver = Driver(whitelist=whitelist, blacklist=blacklist, arglist=arglist, verbosity=verbosity, xfail=[ 'check import test_typing', 'lint module test_typing', 'lint module typing', 'check stub (typeshed/third_party/2.7) module sqlalchemy', 'check stub (typeshed/third_party/2.7) module sqlalchemy.inspection', 'check stub (typeshed/third_party/2.7) module sqlalchemy.schema', 'check stub (typeshed/third_party/2.7) module sqlalchemy.types', 'check stub (typeshed/third_party/2.7) module sqlalchemy.pool', 'check stub (typeshed/third_party/2.7) module sqlalchemy.databases.mysql', 'check stub (typeshed/third_party/2.7) module sqlalchemy.exc', 'check stub (typeshed/third_party/2.7) module sqlalchemy.databases', 'check stub (typeshed/third_party/2.7) module sqlalchemy.dialects.mysql', 'check stub (typeshed/third_party/2.7) module sqlalchemy.dialects.mysql.base', 'check stub (typeshed/third_party/2.7) module sqlalchemy.dialects', 'check stub (typeshed/third_party/2.7) module sqlalchemy.util', 'check stub (typeshed/third_party/2.7) module sqlalchemy.sql', 'check stub (typeshed/third_party/2.7) module sqlalchemy.sql.expression', 'check stub (typeshed/third_party/2.7) module sqlalchemy.sql.visitors', 'check stub (typeshed/third_party/2.7) module sqlalchemy.util.langhelpers', 'check stub (typeshed/third_party/2.7) module sqlalchemy.util._collections', 'check stub (typeshed/third_party/2.7) module sqlalchemy.util.deprecations', 'check stub (typeshed/third_party/2.7) module sqlalchemy.util.compat', 'check stub (typeshed/third_party/2.7) module sqlalchemy.orm', 'check stub (typeshed/third_party/2.7) module sqlalchemy.orm.session', 'check stub (typeshed/third_party/2.7) module sqlalchemy.engine', 'check stub (typeshed/third_party/2.7) module sqlalchemy.engine.url', 'check stub (typeshed/third_party/2.7) module sqlalchemy.engine.strategies', ]) if not dirty_stubs: git.verify_git_integrity_or_abort(SOURCE_DIR) # Don't --use-python-path, only make mypy available. # Now that we're using setuptools and mypy is in an .egg directory, # this won't even catch other modules. for p in IMPLEMENTATION.python_path: if isdir(join(p, 'mypy')): # This must *not* be before stubs. driver.prepend_path('MYPYPATH_APPEND', [p]) break else: assert False, 'unable to find inferior mypy' if not is_installed(): driver.prepend_path('PATH', [join(driver.cwd, 'scripts')]) driver.prepend_path('PYTHONPATH', [driver.cwd]) if DIALECT.major != 2: v = '3.2' else: v = '2.7' driver.prepend_path('PYTHONPATH', [join(driver.cwd, 'lib-typing', v)]) for adder in [ add_basic, add_unittest, add_imports, add_stubs, add_libpython, add_samples, ]: before = driver.count adder(driver) if DIALECT.major == 2: if adder is add_libpython: continue assert driver.count != before, 'no tasks in %s' % adder.__name__ if not list_only: driver.waiter.run() else: driver.list_tasks()
def main() -> None: sanity() verbosity = 0 parallel_limit = 0 whitelist = [] # type: List[str] blacklist = [] # type: List[str] arglist = [] # type: List[str] list_only = False dirty_stubs = False allow_opts = True curlist = whitelist for a in sys.argv[1:]: if curlist is not arglist and allow_opts and a.startswith('-'): if curlist is not whitelist: break if a == '--': allow_opts = False elif a == '-v' or a == '--verbose': verbosity += 1 elif a == '-q' or a == '--quiet': verbosity -= 1 elif a.startswith('-j'): try: parallel_limit = int(a[2:]) except ValueError: usage(1) elif a == '-x' or a == '--exclude': curlist = blacklist elif a == '-a' or a == '--argument': curlist = arglist elif a == '-l' or a == '--list': list_only = True elif a == '-f' or a == '--dirty-stubs': dirty_stubs = True elif a == '-h' or a == '--help': usage(0) else: usage(1) else: curlist.append(a) curlist = whitelist if curlist is blacklist: sys.exit('-x must be followed by a filter') if curlist is arglist: sys.exit('-a must be followed by an argument') # empty string is a substring of all names if not whitelist: whitelist.append('') driver = Driver(whitelist=whitelist, blacklist=blacklist, arglist=arglist, verbosity=verbosity, parallel_limit=parallel_limit, xfail=[]) if not dirty_stubs: git.verify_git_integrity_or_abort(driver.cwd) driver.prepend_path('PATH', [join(driver.cwd, 'scripts')]) driver.prepend_path('MYPYPATH', [driver.cwd]) driver.prepend_path('PYTHONPATH', [driver.cwd]) driver.prepend_path('PYTHONPATH', [join(driver.cwd, 'lib-typing', v) for v in driver.versions]) add_pythoneval(driver) add_cmdline(driver) add_basic(driver) add_selftypecheck(driver) add_myunit(driver) add_imports(driver) add_stubs(driver) add_stdlibsamples(driver) add_samples(driver) if list_only: driver.list_tasks() return exit_code = driver.waiter.run() if verbosity >= 1: times = driver.waiter.times2 if verbosity >= 2 else driver.waiter.times1 times_sortable = ((t, tp) for (tp, t) in times.items()) for total_time, test_type in sorted(times_sortable, reverse=True): print('total time in %s: %f' % (test_type, total_time)) sys.exit(exit_code)
def main() -> None: sanity() verbosity = 0 parallel_limit = 0 whitelist = [] # type: List[str] blacklist = [] # type: List[str] arglist = [] # type: List[str] list_only = False dirty_stubs = False allow_opts = True curlist = whitelist for a in sys.argv[1:]: if curlist is not arglist and allow_opts and a.startswith('-'): if curlist is not whitelist: break if a == '--': allow_opts = False elif a == '-v' or a == '--verbose': verbosity += 1 elif a == '-q' or a == '--quiet': verbosity -= 1 elif a.startswith('-j'): try: parallel_limit = int(a[2:]) except ValueError: usage(1) elif a == '-x' or a == '--exclude': curlist = blacklist elif a == '-a' or a == '--argument': curlist = arglist elif a == '-l' or a == '--list': list_only = True elif a == '-f' or a == '--dirty-stubs': dirty_stubs = True elif a == '-h' or a == '--help': usage(0) else: usage(1) else: curlist.append(a) curlist = whitelist if curlist is blacklist: sys.exit('-x must be followed by a filter') if curlist is arglist: sys.exit('-a must be followed by an argument') # empty string is a substring of all names if not whitelist: whitelist.append('') driver = Driver(whitelist=whitelist, blacklist=blacklist, arglist=arglist, verbosity=verbosity, parallel_limit=parallel_limit, xfail=[]) if not dirty_stubs: git.verify_git_integrity_or_abort(driver.cwd) driver.prepend_path('PATH', [join(driver.cwd, 'scripts')]) driver.prepend_path('MYPYPATH', [driver.cwd]) driver.prepend_path('PYTHONPATH', [driver.cwd]) driver.prepend_path('PYTHONPATH', [join(driver.cwd, 'lib-typing', v) for v in driver.versions]) add_basic(driver) add_myunit(driver) add_imports(driver) add_stubs(driver) add_libpython(driver) add_samples(driver) if not list_only: driver.waiter.run() else: driver.list_tasks()
#!/usr/bin/env python import glob import os import os.path import sys from distutils.core import setup from mypy.version import __version__ from mypy import git if sys.version_info < (3, 2, 0): sys.stderr.write("ERROR: You need Python 3.2 or later to use mypy.\n") exit(1) git.verify_git_integrity_or_abort(".") version = __version__ description = 'Optional static typing for Python' long_description = ''' Mypy -- Optional Static Typing for Python ========================================= Add type annotations to your Python programs, and use mypy to type check them. Mypy is essentially a Python linter on steroids, and it can catch many programming errors by analyzing your program, without actually having to run it. Mypy has a powerful type system with features such as type inference, gradual typing, generics and union types. '''.lstrip()