Skip to content

Commit

Permalink
Merge pull request #1514 from google/google_sync
Browse files Browse the repository at this point in the history
Google sync
  • Loading branch information
rchen152 authored Oct 10, 2023
2 parents 334f6e6 + 8eabac0 commit 416f121
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
platform:
- manylinux2014_x86_64
- manylinux2014_aarch64
pyver: ['cp38-cp38', 'cp39-cp39', 'cp310-cp310']
pyver: ['cp38-cp38', 'cp39-cp39', 'cp310-cp310', 'cp311-cp311']
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python_version: ['3.8', '3.9', '3.10']
python_version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v4
with:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04]
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11']
experimental: [false]
include:
- os: ubuntu-20.04
python-version: '3.11'
experimental: true
- os: ubuntu-20.04
python-version: '3.12'
experimental: true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ merge-pyi -i <filepath>.py .pytype/pyi/<filename>.pyi

## Requirements

You need a Python 3.8-3.10 interpreter to run pytype, as well as an
You need a Python 3.8-3.11 interpreter to run pytype, as well as an
interpreter in `$PATH` for the Python version of the code you're analyzing
(supported: 3.8-3.10).
(supported: 3.8-3.11).

Platform support:

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ merge-pyi -i <filepath>.py .pytype/pyi/<filename>.pyi

## Requirements

You need a Python 3.8-3.10 interpreter to run pytype, as well as an
You need a Python 3.8-3.11 interpreter to run pytype, as well as an
interpreter in `$PATH` for the Python version of the code you're analyzing
(supported: 3.8-3.10).
(supported: 3.8-3.11).

Platform support:

Expand Down
7 changes: 4 additions & 3 deletions docs/support.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ of pytype.
* [Third-Party Libraries](#third-party-libraries)

<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
<!-- Added by: rechen, at: Tue Aug 8 12:00:43 AM PDT 2023 -->
<!-- Added by: rechen, at: Tue Oct 10 01:57:19 PM PDT 2023 -->

<!--te-->

Expand All @@ -31,15 +31,16 @@ of pytype.
(upcoming versions), if applicable

Version | Analyzes | Runs In | Issue
:-----: | :--------: | :--------: | :------------:
:-----: | :--------: | :--------: | :----------:
2.7 | 2021.08.03 | 2020.04.01 | [#545][py27]
3.5 | 2021.09.09 | 2020.10.08 | [#677][py35]
3.6 | 2022.01.05 | 2022.01.05 |
3.7 | 2023.06.16 | 2023.06.16 |
3.8 | ✅ | ✅ |
3.9 | ✅ | ✅ |
3.10 | ✅ | ✅ |
3.11 | ❌ | ❌ | [#1308][py311]
3.11 | ✅ | ✅ |
3.12 | ❌ | ❌ |

## Features

Expand Down
16 changes: 16 additions & 0 deletions pytype/pyi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ toplevel_py_binary(
pytype.pytd.pytd_for_parser
)

toplevel_py_binary(
NAME
parse_pickle
SRCS
parse_pickle.py
MAIN
parse_pickle.py
DEPS
.types
pytype.config
pytype.load_pytd
pytype.utils
pytype.imports.imports
pytype.pytd.pytd
)

py_library(
NAME
parser_test_base
Expand Down
78 changes: 78 additions & 0 deletions pytype/pyi/parse_pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Testing code to print a pickled ast."""

import argparse
import sys
from typing import Optional

from pytype import config
from pytype import load_pytd
from pytype import module_utils
from pytype import utils
from pytype.imports import pickle_utils
from pytype.pyi import types
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import serialize_ast

_ParseError = types.ParseError


def _make_argument_parser() -> argparse.ArgumentParser:
"""Creates and returns an argument parser."""

o = argparse.ArgumentParser()
o.add_argument('pytd', nargs='?', default=None,
help='Serialized AST to diagnose.')
o.add_argument('--pyi', nargs='?', default=None,
help='An optional pyi file to pickle in lieu of an existing '
'serialized AST.')
return o


def _pickle(src_path: str) -> Optional[bytes]:
"""Run the serialization code on the pyi file at the given src_path."""

with open(src_path) as f:
src = f.read()
module_name = module_utils.path_to_module_name(src_path)
options = config.Options.create(module_name=module_name,
input_filename=src_path,
validate_version=False)
loader = load_pytd.Loader(options)
try:
ast: pytd.TypeDeclUnit = serialize_ast.SourceToExportableAst(
module_name, src, loader)
except _ParseError as e:
header = utils.COLOR_ERROR_NAME_TEMPLATE % 'ParseError:'
print(f'{header} Invalid type stub for module {module_name!r}:\n{e}',
file=sys.stderr)
return None

return pickle_utils.StoreAst(ast)


def main() -> None:
args = _make_argument_parser().parse_args()
if args.pyi:
data = _pickle(args.pyi)
if not data:
sys.exit(1)
else:
with open(args.pytd, 'rb') as f:
data = f.read()

try:
out: serialize_ast.SerializableAst = pickle_utils.LoadAst(data)
except _ParseError as e:
print(e)
sys.exit(1)

print('-------------pytd-------------')
print(out.ast)

print('-------------pyi--------------')
print(pytd_utils.Print(out.ast))


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions pytype/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def validate_version(python_version):
elif (3, 0) <= python_version <= (3, 7):
raise UsageError(
"Python versions 3.0 - 3.7 are not supported. Use 3.8 and higher.")
elif python_version > (3, 10) and _VALIDATE_PYTHON_VERSION_UPPER_BOUND:
elif python_version > (3, 11) and _VALIDATE_PYTHON_VERSION_UPPER_BOUND:
# We have an explicit per-minor-version mapping in opcodes.py
raise UsageError("Python versions > 3.10 are not yet supported.")
raise UsageError("Python versions > 3.11 are not yet supported.")


def strip_prefix(string, prefix):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ libcst>=1.0.1
networkx<3.2
ninja>=1.10.0.post2
pybind11>=2.10.1
pycnite>=2023.9.14
pycnite>=2023.10.5
pydot>=1.4.2
pylint>=2.14.4
tabulate>=0.8.10
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: Implementation :: CPython
Topic :: Software Development

Expand All @@ -36,7 +37,7 @@ install_requires =
libcst>=1.0.1
networkx<3.2
ninja>=1.10.0.post2
pycnite>=2023.9.14
pycnite>=2023.10.5
pydot>=1.4.2
tabulate>=0.8.10
toml>=0.10.2
Expand Down

0 comments on commit 416f121

Please sign in to comment.