mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 04:04:25 +08:00
Update pytype_test to be easier to run manually. (#2469)
* Moves the pytype installation to requirements-tests-py3.txt, now
that pytype can run under Python 3.5+.
* Changes tests/pytype_test.py to not require a --python{version}-exe
argument when it can automatically find the Python interpreter, and
cleans up a few typos and out-of-date things.
* Updates the appropriate documentation.
* Updates .travis.yml.
This commit is contained in:
@@ -6,20 +6,19 @@ matrix:
|
||||
- python: "3.6-dev"
|
||||
env: TEST_CMD="flake8"
|
||||
- python: "3.6"
|
||||
env: TEST_CMD="./tests/pytype_test.py --num-parallel=4"
|
||||
- python: "3.5-dev"
|
||||
env: TEST_CMD="./tests/mypy_selftest.py"
|
||||
- python: "3.5"
|
||||
env: TEST_CMD="./tests/mypy_test.py"
|
||||
- python: "3.4"
|
||||
env: TEST_CMD="./tests/check_consistent.py"
|
||||
- python: "2.7"
|
||||
env: TEST_CMD="./tests/pytype_test.py --num-parallel=4"
|
||||
sudo: true
|
||||
|
||||
install:
|
||||
# pytype needs py-2.7, mypy needs py-3.3+. Additional logic in runtests.py
|
||||
# pytype needs py-3.6, mypy needs py-3.3+. Additional logic in runtests.py
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.6-dev' ]]; then pip install -r requirements-tests-py3.txt; fi
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install -r requirements-tests-py3.txt; fi
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast; fi
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install -r requirements-tests-py2.txt; wget https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/14.04/x86_64/python-3.6.tar.bz2; sudo tar xjf python-3.6.tar.bz2 --directory /; fi
|
||||
|
||||
script:
|
||||
- $TEST_CMD
|
||||
|
||||
24
README.md
24
README.md
@@ -114,8 +114,8 @@ $ source .venv3/bin/activate
|
||||
(.venv3)$ pip3 install -r requirements-tests-py3.txt
|
||||
```
|
||||
This will install mypy (you need the latest master branch from GitHub),
|
||||
typed-ast, and flake8. You can then run mypy tests and flake8 tests by
|
||||
invoking:
|
||||
typed-ast, flake8, and pytype. You can then run mypy, flake8, and pytype tests
|
||||
by invoking:
|
||||
```
|
||||
(.venv3)$ python3 tests/mypy_test.py
|
||||
...
|
||||
@@ -123,21 +123,13 @@ invoking:
|
||||
...
|
||||
(.venv3)$ flake8
|
||||
...
|
||||
(.venv3)$ python3 tests/pytype_test.py
|
||||
...
|
||||
```
|
||||
(Note that flake8 only works with Python 3.6 or higher.)
|
||||
|
||||
To run the pytype tests, you need a separate virtual environment with
|
||||
Python 2.7, and a Python 3.6 interpreter somewhere you can point to. Run:
|
||||
```
|
||||
$ virtualenv --python=python2.7 .venv2
|
||||
$ source .venv2/bin/activate
|
||||
(.venv2)$ pip install -r requirements-tests-py2.txt
|
||||
```
|
||||
This will install pytype from its GitHub repo. You can then run pytype
|
||||
tests by running:
|
||||
```
|
||||
(.venv2)$ python tests/pytype_test.py --python36-exe=/path/to/python3.6
|
||||
```
|
||||
Note that flake8 only works with Python 3.6 or higher, and that to run the
|
||||
pytype tests, you will need Python 2.7 and Python 3.6 interpreters. Pytype will
|
||||
find these automatically if they're in `PATH`, but otherwise you must point to
|
||||
them with the `--python27-exe` and `--python36-exe` arguments, respectively.
|
||||
|
||||
For mypy, if you are in the typeshed repo that is submodule of the
|
||||
mypy repo (so `..` refers to the mypy repo), there's a shortcut to run
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pytype>=2018.6.19
|
||||
@@ -3,3 +3,4 @@ typed-ast>=1.0.4
|
||||
flake8==3.5.0
|
||||
flake8-bugbear==18.2.0
|
||||
flake8-pyi>=18.3.1
|
||||
pytype>=2018.9.19
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
r"""Test runner for typeshed.
|
||||
|
||||
Depends on mypy and pytype being installed.
|
||||
Depends on pytype being installed.
|
||||
|
||||
If pytype is installed:
|
||||
1. For every pyi, do nothing if it is in pytype_blacklist.txt.
|
||||
@@ -9,7 +9,7 @@ If pytype is installed:
|
||||
"pytd <foo.pyi>" in a separate process.
|
||||
3. If the file is not in the blacklist run
|
||||
"pytype --typeshed-location=typeshed_location --module-name=foo \
|
||||
--convert-to-pickle=tmp_file <foo.pyi>.
|
||||
--parse-pyi <foo.pyi>.
|
||||
Option two will parse the file, mostly syntactical correctness. Option three
|
||||
will load the file and all the builtins, typeshed dependencies. This will
|
||||
also discover incorrect usage of imported modules.
|
||||
@@ -37,9 +37,10 @@ parser.add_argument('--pytype-bin-dir', type=str, default='',
|
||||
# Set to true to print a stack trace every time an exception is thrown.
|
||||
parser.add_argument('--print-stderr', type=bool, default=False,
|
||||
help='Print stderr every time an error is encountered.')
|
||||
# We need to invoke python3.6. The default here works with our travis tests.
|
||||
parser.add_argument('--python36-exe', type=str,
|
||||
default='/opt/python/3.6/bin/python3.6',
|
||||
# We need to invoke python2.7 and 3.6.
|
||||
parser.add_argument('--python27-exe', type=str, default='python2.7',
|
||||
help='Path to a python 2.7 interpreter.')
|
||||
parser.add_argument('--python36-exe', type=str, default='python3.6',
|
||||
help='Path to a python 3.6 interpreter.')
|
||||
|
||||
Dirs = collections.namedtuple('Dirs', ['pytype', 'typeshed'])
|
||||
@@ -165,7 +166,7 @@ def pytype_test(args):
|
||||
for p in paths:
|
||||
if not os.path.isdir(p):
|
||||
print('Cannot find typeshed subdir at %s '
|
||||
'(specify parent dir via --typeshed_location)' % p)
|
||||
'(specify parent dir via --typeshed-location)' % p)
|
||||
return 0, 0
|
||||
|
||||
if can_run(dirs.pytype, 'pytd', '-h'):
|
||||
@@ -176,10 +177,14 @@ def pytype_test(args):
|
||||
print('Cannot run pytd. Did you install pytype?')
|
||||
return 0, 0
|
||||
|
||||
if not can_run('', args.python36_exe, '--version'):
|
||||
print('Cannot run python3.6 from %s. (point to a valid executable via '
|
||||
'--python36-exe)' % args.python36_exe)
|
||||
return 0, 0
|
||||
for python_version_str in ('27', '36'):
|
||||
dest = 'python%s_exe' % python_version_str
|
||||
version = '.'.join(list(python_version_str))
|
||||
arg = '--python%s-exe' % python_version_str
|
||||
if not can_run('', getattr(args, dest), '--version'):
|
||||
print('Cannot run Python {version}. (point to a valid executable '
|
||||
'via {arg})'.format(version=version, arg=arg))
|
||||
return 0, 0
|
||||
|
||||
# TODO(rchen152): Keep expanding our third_party/ coverage so we can move
|
||||
# to a small blacklist rather than an ever-growing whitelist.
|
||||
@@ -200,16 +205,19 @@ def pytype_test(args):
|
||||
bad = []
|
||||
|
||||
def _make_test(filename, major_version):
|
||||
if major_version == 3:
|
||||
version = '3.6'
|
||||
exe = args.python36_exe
|
||||
else:
|
||||
version = '2.7'
|
||||
exe = args.python27_exe
|
||||
run_cmd = [
|
||||
pytype_exe,
|
||||
'--module-name=%s' % _get_module_name(filename),
|
||||
'--parse-pyi',
|
||||
'-V %s' % version,
|
||||
'--python_exe=%s' % exe,
|
||||
]
|
||||
if major_version == 3:
|
||||
run_cmd += [
|
||||
'-V 3.6',
|
||||
'--python_exe=%s' % args.python36_exe,
|
||||
]
|
||||
return BinaryRun(run_cmd + [filename],
|
||||
dry_run=args.dry_run,
|
||||
env={"TYPESHED_HOME": dirs.typeshed})
|
||||
|
||||
Reference in New Issue
Block a user