Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c024b58

Browse files
gh-294: Vendor lib2to3 (gh-302)
Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent 9085d3a commit c024b58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+8687
-1
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ include pyperformance/data-files/benchmarks/bm_*/*.toml
1616
include pyperformance/data-files/benchmarks/bm_*/*.py
1717
include pyperformance/data-files/benchmarks/bm_*/requirements.txt
1818
include pyperformance/data-files/benchmarks/bm_*/*.pem
19+
recursive-include pyperformance/data-files/benchmarks/bm_*/vendor *
1920
recursive-include pyperformance/data-files/benchmarks/bm_*/data *
2021
recursive-exclude pyperformance/tests *

pyperformance/data-files/benchmarks/bm_2to3/pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[build-system]
2+
requires = ["setuptools>=61"]
3+
build-backend = "setuptools.build_meta"
4+
15
[project]
26
name = "pyperformance_bm_2to3"
37
requires-python = ">=3.8"

pyperformance/data-files/benchmarks/bm_2to3/run_benchmark.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import glob
22
import os.path
33
import sys
4+
import subprocess
45

56
import pyperf
67

@@ -13,6 +14,12 @@
1314

1415
datadir = os.path.join(os.path.dirname(__file__), 'data', '2to3')
1516
pyfiles = glob.glob(os.path.join(datadir, '*.py.txt'))
16-
1717
command = [sys.executable, "-m", "lib2to3", "-f", "all"] + pyfiles
18+
19+
try:
20+
import lib2to3
21+
except ModuleNotFoundError:
22+
vendor = os.path.join(os.path.dirname(__file__), 'vendor')
23+
subprocess.run([sys.executable, "-m", "pip", "install", vendor], check=True)
24+
1825
runner.bench_command('2to3', command)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
2+
--------------------------------------------
3+
4+
1. This LICENSE AGREEMENT is between the Python Software Foundation
5+
("PSF"), and the Individual or Organization ("Licensee") accessing and
6+
otherwise using this software ("Python") in source or binary form and
7+
its associated documentation.
8+
9+
2. Subject to the terms and conditions of this License Agreement, PSF hereby
10+
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
11+
analyze, test, perform and/or display publicly, prepare derivative works,
12+
distribute, and otherwise use Python alone or in any derivative version,
13+
provided, however, that PSF's License Agreement and PSF's notice of copyright,
14+
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
15+
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
16+
All Rights Reserved" are retained in Python alone or in any derivative version
17+
prepared by Licensee.
18+
19+
3. In the event Licensee prepares a derivative work that is based on
20+
or incorporates Python or any part thereof, and wants to make
21+
the derivative work available to others as provided herein, then
22+
Licensee hereby agrees to include in any such work a brief summary of
23+
the changes made to Python.
24+
25+
4. PSF is making Python available to Licensee on an "AS IS"
26+
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
27+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
28+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
29+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
30+
INFRINGE ANY THIRD PARTY RIGHTS.
31+
32+
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
33+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
34+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
35+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
36+
37+
6. This License Agreement will automatically terminate upon a material
38+
breach of its terms and conditions.
39+
40+
7. Nothing in this License Agreement shall be deemed to create any
41+
relationship of agency, partnership, or joint venture between PSF and
42+
Licensee. This License Agreement does not grant permission to use PSF
43+
trademarks or trade name in a trademark sense to endorse or promote
44+
products or services of Licensee, or any third party.
45+
46+
8. By copying, installing or otherwise using Python, Licensee
47+
agrees to be bound by the terms and conditions of this License
48+
Agreement.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[build-system]
2+
requires = ["setuptools>=61"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "lib2to3"
7+
version = "3.12"
8+
description = "lib2to3 for Python 3.13+"
9+
requires-python = ">=3.13.0a0"
10+
license = {text = "PSF-2.0"}
11+
classifiers = [
12+
"License :: OSI Approved :: Python Software Foundation License",
13+
]
14+
15+
[tool.setuptools.package-data]
16+
"*" = ["*.txt"]
17+
18+
[tool.setuptools.packages.find]
19+
where = ["src"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Grammar for 2to3. This grammar supports Python 2.x and 3.x.
2+
3+
# NOTE WELL: You should also follow all the steps listed at
4+
# https://devguide.python.org/grammar/
5+
6+
# Start symbols for the grammar:
7+
# file_input is a module or sequence of commands read from an input file;
8+
# single_input is a single interactive statement;
9+
# eval_input is the input for the eval() and input() functions.
10+
# NB: compound_stmt in single_input is followed by extra NEWLINE!
11+
file_input: (NEWLINE | stmt)* ENDMARKER
12+
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
13+
eval_input: testlist NEWLINE* ENDMARKER
14+
15+
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
16+
decorators: decorator+
17+
decorated: decorators (classdef | funcdef | async_funcdef)
18+
async_funcdef: ASYNC funcdef
19+
funcdef: 'def' NAME parameters ['->' test] ':' suite
20+
parameters: '(' [typedargslist] ')'
21+
22+
# The following definition for typedarglist is equivalent to this set of rules:
23+
#
24+
# arguments = argument (',' argument)*
25+
# argument = tfpdef ['=' test]
26+
# kwargs = '**' tname [',']
27+
# args = '*' [tname]
28+
# kwonly_kwargs = (',' argument)* [',' [kwargs]]
29+
# args_kwonly_kwargs = args kwonly_kwargs | kwargs
30+
# poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]]
31+
# typedargslist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs
32+
# typedarglist = arguments ',' '/' [',' [typedargslist_no_posonly]])|(typedargslist_no_posonly)"
33+
#
34+
# It needs to be fully expanded to allow our LL(1) parser to work on it.
35+
36+
typedargslist: tfpdef ['=' test] (',' tfpdef ['=' test])* ',' '/' [
37+
',' [((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])*
38+
[',' ['**' tname [',']]] | '**' tname [','])
39+
| tfpdef ['=' test] (',' tfpdef ['=' test])* [','])]
40+
] | ((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])*
41+
[',' ['**' tname [',']]] | '**' tname [','])
42+
| tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
43+
44+
tname: NAME [':' test]
45+
tfpdef: tname | '(' tfplist ')'
46+
tfplist: tfpdef (',' tfpdef)* [',']
47+
48+
# The following definition for varargslist is equivalent to this set of rules:
49+
#
50+
# arguments = argument (',' argument )*
51+
# argument = vfpdef ['=' test]
52+
# kwargs = '**' vname [',']
53+
# args = '*' [vname]
54+
# kwonly_kwargs = (',' argument )* [',' [kwargs]]
55+
# args_kwonly_kwargs = args kwonly_kwargs | kwargs
56+
# poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]]
57+
# vararglist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs
58+
# varargslist = arguments ',' '/' [','[(vararglist_no_posonly)]] | (vararglist_no_posonly)
59+
#
60+
# It needs to be fully expanded to allow our LL(1) parser to work on it.
61+
62+
varargslist: vfpdef ['=' test ](',' vfpdef ['=' test])* ',' '/' [',' [
63+
((vfpdef ['=' test] ',')* ('*' [vname] (',' vname ['=' test])*
64+
[',' ['**' vname [',']]] | '**' vname [','])
65+
| vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
66+
]] | ((vfpdef ['=' test] ',')*
67+
('*' [vname] (',' vname ['=' test])* [',' ['**' vname [',']]]| '**' vname [','])
68+
| vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
69+
70+
vname: NAME
71+
vfpdef: vname | '(' vfplist ')'
72+
vfplist: vfpdef (',' vfpdef)* [',']
73+
74+
stmt: simple_stmt | compound_stmt
75+
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
76+
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
77+
import_stmt | global_stmt | exec_stmt | assert_stmt)
78+
expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
79+
('=' (yield_expr|testlist_star_expr))*)
80+
annassign: ':' test ['=' test]
81+
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
82+
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
83+
'<<=' | '>>=' | '**=' | '//=')
84+
# For normal and annotated assignments, additional restrictions enforced by the interpreter
85+
print_stmt: 'print' ( [ test (',' test)* [','] ] |
86+
'>>' test [ (',' test)+ [','] ] )
87+
del_stmt: 'del' exprlist
88+
pass_stmt: 'pass'
89+
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
90+
break_stmt: 'break'
91+
continue_stmt: 'continue'
92+
return_stmt: 'return' [testlist_star_expr]
93+
yield_stmt: yield_expr
94+
raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]
95+
import_stmt: import_name | import_from
96+
import_name: 'import' dotted_as_names
97+
import_from: ('from' ('.'* dotted_name | '.'+)
98+
'import' ('*' | '(' import_as_names ')' | import_as_names))
99+
import_as_name: NAME ['as' NAME]
100+
dotted_as_name: dotted_name ['as' NAME]
101+
import_as_names: import_as_name (',' import_as_name)* [',']
102+
dotted_as_names: dotted_as_name (',' dotted_as_name)*
103+
dotted_name: NAME ('.' NAME)*
104+
global_stmt: ('global' | 'nonlocal') NAME (',' NAME)*
105+
exec_stmt: 'exec' expr ['in' test [',' test]]
106+
assert_stmt: 'assert' test [',' test]
107+
108+
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
109+
async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
110+
if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite]
111+
while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite]
112+
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
113+
try_stmt: ('try' ':' suite
114+
((except_clause ':' suite)+
115+
['else' ':' suite]
116+
['finally' ':' suite] |
117+
'finally' ':' suite))
118+
with_stmt: 'with' with_item (',' with_item)* ':' suite
119+
with_item: test ['as' expr]
120+
with_var: 'as' expr
121+
# NB compile.c makes sure that the default except clause is last
122+
except_clause: 'except' [test [(',' | 'as') test]]
123+
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
124+
125+
# Backward compatibility cruft to support:
126+
# [ x for x in lambda: True, lambda: False if x() ]
127+
# even while also allowing:
128+
# lambda x: 5 if x else 2
129+
# (But not a mix of the two)
130+
testlist_safe: old_test [(',' old_test)+ [',']]
131+
old_test: or_test | old_lambdef
132+
old_lambdef: 'lambda' [varargslist] ':' old_test
133+
134+
namedexpr_test: test [':=' test]
135+
test: or_test ['if' or_test 'else' test] | lambdef
136+
or_test: and_test ('or' and_test)*
137+
and_test: not_test ('and' not_test)*
138+
not_test: 'not' not_test | comparison
139+
comparison: expr (comp_op expr)*
140+
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
141+
star_expr: '*' expr
142+
expr: xor_expr ('|' xor_expr)*
143+
xor_expr: and_expr ('^' and_expr)*
144+
and_expr: shift_expr ('&' shift_expr)*
145+
shift_expr: arith_expr (('<<'|'>>') arith_expr)*
146+
arith_expr: term (('+'|'-') term)*
147+
term: factor (('*'|'@'|'/'|'%'|'//') factor)*
148+
factor: ('+'|'-'|'~') factor | power
149+
power: [AWAIT] atom trailer* ['**' factor]
150+
atom: ('(' [yield_expr|testlist_gexp] ')' |
151+
'[' [listmaker] ']' |
152+
'{' [dictsetmaker] '}' |
153+
'`' testlist1 '`' |
154+
NAME | NUMBER | STRING+ | '.' '.' '.')
155+
listmaker: (namedexpr_test|star_expr) ( comp_for | (',' (namedexpr_test|star_expr))* [','] )
156+
testlist_gexp: (namedexpr_test|star_expr) ( comp_for | (',' (namedexpr_test|star_expr))* [','] )
157+
lambdef: 'lambda' [varargslist] ':' test
158+
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
159+
subscriptlist: subscript (',' subscript)* [',']
160+
subscript: test | [test] ':' [test] [sliceop]
161+
sliceop: ':' [test]
162+
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
163+
testlist: test (',' test)* [',']
164+
dictsetmaker: ( ((test ':' test | '**' expr)
165+
(comp_for | (',' (test ':' test | '**' expr))* [','])) |
166+
((test | star_expr)
167+
(comp_for | (',' (test | star_expr))* [','])) )
168+
169+
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
170+
171+
arglist: argument (',' argument)* [',']
172+
173+
# "test '=' test" is really "keyword '=' test", but we have no such token.
174+
# These need to be in a single rule to avoid grammar that is ambiguous
175+
# to our LL(1) parser. Even though 'test' includes '*expr' in star_expr,
176+
# we explicitly match '*' here, too, to give it proper precedence.
177+
# Illegal combinations and orderings are blocked in ast.c:
178+
# multiple (test comp_for) arguments are blocked; keyword unpackings
179+
# that precede iterable unpackings are blocked; etc.
180+
argument: ( test [comp_for] |
181+
test ':=' test |
182+
test '=' test |
183+
'**' test |
184+
'*' test )
185+
186+
comp_iter: comp_for | comp_if
187+
comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter]
188+
comp_if: 'if' old_test [comp_iter]
189+
190+
testlist1: test (',' test)*
191+
192+
# not used in grammar, but may appear in "node" passed from Parser to Compiler
193+
encoding_decl: NAME
194+
195+
yield_expr: 'yield' [yield_arg]
196+
yield_arg: 'from' test | testlist_star_expr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2006 Google, Inc. All Rights Reserved.
2+
# Licensed to PSF under a Contributor Agreement.
3+
4+
# A grammar to describe tree matching patterns.
5+
# Not shown here:
6+
# - 'TOKEN' stands for any token (leaf node)
7+
# - 'any' stands for any node (leaf or interior)
8+
# With 'any' we can still specify the sub-structure.
9+
10+
# The start symbol is 'Matcher'.
11+
12+
Matcher: Alternatives ENDMARKER
13+
14+
Alternatives: Alternative ('|' Alternative)*
15+
16+
Alternative: (Unit | NegatedUnit)+
17+
18+
Unit: [NAME '='] ( STRING [Repeater]
19+
| NAME [Details] [Repeater]
20+
| '(' Alternatives ')' [Repeater]
21+
| '[' Alternatives ']'
22+
)
23+
24+
NegatedUnit: 'not' (STRING | NAME [Details] | '(' Alternatives ')')
25+
26+
Repeater: '*' | '+' | '{' NUMBER [',' NUMBER] '}'
27+
28+
Details: '<' Alternatives '>'

pyperformance/data-files/benchmarks/bm_2to3/vendor/src/lib2to3/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
from .main import main
3+
4+
sys.exit(main("lib2to3.fixes"))

0 commit comments

Comments
 (0)