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

Better error on empty typeshed directory #3862

Merged
merged 4 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from mypy.types import Type
from mypy.version import __version__
from mypy.plugin import Plugin, DefaultPlugin, ChainedPlugin
from mypy.defaults import PYTHON3_VERSION_MIN


# We need to know the location of this file to load data, but
Expand Down Expand Up @@ -279,12 +280,15 @@ def default_lib_path(data_dir: str,
if os.path.isdir(auto):
data_dir = auto
typeshed_dir = os.path.join(data_dir, "typeshed")
# We allow a module for e.g. version 3.5 to be in 3.4/. The assumption
# is that a module added with 3.4 will still be present in Python 3.5.
versions = ["%d.%d" % (pyversion[0], minor)
for minor in reversed(range(pyversion[1] + 1))]
# E.g. for Python 3.2, try 3.2/, 3.1/, 3.0/, 3/, 2and3/.
# (Note that 3.1 and 3.0 aren't really supported, but we don't care.)
if pyversion[0] == 3:
# We allow a module for e.g. version 3.5 to be in 3.4/. The assumption
# is that a module added with 3.4 will still be present in Python 3.5.
versions = ["%d.%d" % (pyversion[0], minor)
for minor in reversed(range(PYTHON3_VERSION_MIN[1], pyversion[1] + 1))]
else:
# For Python 2, we only have stubs for 2.7
versions = ["2.7"]
# E.g. for Python 3.5, try 3.5/, 3.4/, 3.3/, 3/, 2and3/.
for v in versions + [str(pyversion[0]), '2and3']:
for lib_type in ['stdlib', 'third_party']:
stubdir = os.path.join(typeshed_dir, lib_type, v)
Expand All @@ -294,7 +298,11 @@ def default_lib_path(data_dir: str,
# Add fallback path that can be used if we have a broken installation.
if sys.platform != 'win32':
path.append('/usr/local/lib/mypy')

if not path:
print("Could not resolve typeshed subdirectories. If you are using MyPy"
"from source, you need to run \"git submodule --init update\"."
"Otherwise your MyPy install is broken.", file=sys.stderr)
sys.exit(1)
return path


Expand Down
1 change: 1 addition & 0 deletions mypy/defaults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PYTHON2_VERSION = (2, 7)
PYTHON3_VERSION = (3, 6)
PYTHON3_VERSION_MIN = (3, 3)
CACHE_DIR = '.mypy_cache'
CONFIG_FILE = 'mypy.ini'