-
-
Notifications
You must be signed in to change notification settings - Fork 185
gh-294: Vendor lib2to3 #302
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8439c96
gh-294: Vendoring lib2to3
corona10 5c460cb
remove deprecated warning
corona10 9876b41
Minor fix
corona10 af97e40
Address code review
corona10 01aa6ff
Update pyperformance/data-files/benchmarks/bm_2to3/vendor/pyproject.toml
corona10 bf5ffe2
Address code review
corona10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
pyperformance/data-files/benchmarks/bm_2to3/vendor/LICENSE.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 | ||
-------------------------------------------- | ||
|
||
1. This LICENSE AGREEMENT is between the Python Software Foundation | ||
("PSF"), and the Individual or Organization ("Licensee") accessing and | ||
otherwise using this software ("Python") in source or binary form and | ||
its associated documentation. | ||
|
||
2. Subject to the terms and conditions of this License Agreement, PSF hereby | ||
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, | ||
analyze, test, perform and/or display publicly, prepare derivative works, | ||
distribute, and otherwise use Python alone or in any derivative version, | ||
provided, however, that PSF's License Agreement and PSF's notice of copyright, | ||
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, | ||
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation; | ||
All Rights Reserved" are retained in Python alone or in any derivative version | ||
prepared by Licensee. | ||
|
||
3. In the event Licensee prepares a derivative work that is based on | ||
or incorporates Python or any part thereof, and wants to make | ||
the derivative work available to others as provided herein, then | ||
Licensee hereby agrees to include in any such work a brief summary of | ||
the changes made to Python. | ||
|
||
4. PSF is making Python available to Licensee on an "AS IS" | ||
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR | ||
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND | ||
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS | ||
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT | ||
INFRINGE ANY THIRD PARTY RIGHTS. | ||
|
||
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON | ||
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS | ||
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, | ||
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. | ||
|
||
6. This License Agreement will automatically terminate upon a material | ||
breach of its terms and conditions. | ||
|
||
7. Nothing in this License Agreement shall be deemed to create any | ||
relationship of agency, partnership, or joint venture between PSF and | ||
Licensee. This License Agreement does not grant permission to use PSF | ||
trademarks or trade name in a trademark sense to endorse or promote | ||
products or services of Licensee, or any third party. | ||
|
||
8. By copying, installing or otherwise using Python, Licensee | ||
agrees to be bound by the terms and conditions of this License | ||
Agreement. |
19 changes: 19 additions & 0 deletions
19
pyperformance/data-files/benchmarks/bm_2to3/vendor/pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[build-system] | ||
requires = ["setuptools>=61"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "lib2to3" | ||
version = "3.12" | ||
description = "lib2to3 for Python 3.13+" | ||
corona10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requires-python = ">=3.13.0a0" | ||
license = {text = "PSF-2.0"} | ||
classifiers = [ | ||
"License :: OSI Approved :: Python Software Foundation License", | ||
] | ||
|
||
[tool.setuptools.package-data] | ||
"*" = ["*.txt"] | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] |
196 changes: 196 additions & 0 deletions
196
pyperformance/data-files/benchmarks/bm_2to3/vendor/src/lib2to3/Grammar.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
# Grammar for 2to3. This grammar supports Python 2.x and 3.x. | ||
|
||
# NOTE WELL: You should also follow all the steps listed at | ||
# https://devguide.python.org/grammar/ | ||
|
||
# Start symbols for the grammar: | ||
# file_input is a module or sequence of commands read from an input file; | ||
# single_input is a single interactive statement; | ||
# eval_input is the input for the eval() and input() functions. | ||
# NB: compound_stmt in single_input is followed by extra NEWLINE! | ||
file_input: (NEWLINE | stmt)* ENDMARKER | ||
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE | ||
eval_input: testlist NEWLINE* ENDMARKER | ||
|
||
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE | ||
decorators: decorator+ | ||
decorated: decorators (classdef | funcdef | async_funcdef) | ||
async_funcdef: ASYNC funcdef | ||
funcdef: 'def' NAME parameters ['->' test] ':' suite | ||
parameters: '(' [typedargslist] ')' | ||
|
||
# The following definition for typedarglist is equivalent to this set of rules: | ||
# | ||
# arguments = argument (',' argument)* | ||
# argument = tfpdef ['=' test] | ||
# kwargs = '**' tname [','] | ||
# args = '*' [tname] | ||
# kwonly_kwargs = (',' argument)* [',' [kwargs]] | ||
# args_kwonly_kwargs = args kwonly_kwargs | kwargs | ||
# poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]] | ||
# typedargslist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs | ||
# typedarglist = arguments ',' '/' [',' [typedargslist_no_posonly]])|(typedargslist_no_posonly)" | ||
# | ||
# It needs to be fully expanded to allow our LL(1) parser to work on it. | ||
|
||
typedargslist: tfpdef ['=' test] (',' tfpdef ['=' test])* ',' '/' [ | ||
',' [((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])* | ||
[',' ['**' tname [',']]] | '**' tname [',']) | ||
| tfpdef ['=' test] (',' tfpdef ['=' test])* [','])] | ||
] | ((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])* | ||
[',' ['**' tname [',']]] | '**' tname [',']) | ||
| tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) | ||
|
||
tname: NAME [':' test] | ||
tfpdef: tname | '(' tfplist ')' | ||
tfplist: tfpdef (',' tfpdef)* [','] | ||
|
||
# The following definition for varargslist is equivalent to this set of rules: | ||
# | ||
# arguments = argument (',' argument )* | ||
# argument = vfpdef ['=' test] | ||
# kwargs = '**' vname [','] | ||
# args = '*' [vname] | ||
# kwonly_kwargs = (',' argument )* [',' [kwargs]] | ||
# args_kwonly_kwargs = args kwonly_kwargs | kwargs | ||
# poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]] | ||
# vararglist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs | ||
# varargslist = arguments ',' '/' [','[(vararglist_no_posonly)]] | (vararglist_no_posonly) | ||
# | ||
# It needs to be fully expanded to allow our LL(1) parser to work on it. | ||
|
||
varargslist: vfpdef ['=' test ](',' vfpdef ['=' test])* ',' '/' [',' [ | ||
((vfpdef ['=' test] ',')* ('*' [vname] (',' vname ['=' test])* | ||
[',' ['**' vname [',']]] | '**' vname [',']) | ||
| vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) | ||
]] | ((vfpdef ['=' test] ',')* | ||
('*' [vname] (',' vname ['=' test])* [',' ['**' vname [',']]]| '**' vname [',']) | ||
| vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) | ||
|
||
vname: NAME | ||
vfpdef: vname | '(' vfplist ')' | ||
vfplist: vfpdef (',' vfpdef)* [','] | ||
|
||
stmt: simple_stmt | compound_stmt | ||
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE | ||
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | | ||
import_stmt | global_stmt | exec_stmt | assert_stmt) | ||
expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) | | ||
('=' (yield_expr|testlist_star_expr))*) | ||
annassign: ':' test ['=' test] | ||
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [','] | ||
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' | | ||
'<<=' | '>>=' | '**=' | '//=') | ||
# For normal and annotated assignments, additional restrictions enforced by the interpreter | ||
print_stmt: 'print' ( [ test (',' test)* [','] ] | | ||
'>>' test [ (',' test)+ [','] ] ) | ||
del_stmt: 'del' exprlist | ||
pass_stmt: 'pass' | ||
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt | ||
break_stmt: 'break' | ||
continue_stmt: 'continue' | ||
return_stmt: 'return' [testlist_star_expr] | ||
yield_stmt: yield_expr | ||
raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]] | ||
import_stmt: import_name | import_from | ||
import_name: 'import' dotted_as_names | ||
import_from: ('from' ('.'* dotted_name | '.'+) | ||
'import' ('*' | '(' import_as_names ')' | import_as_names)) | ||
import_as_name: NAME ['as' NAME] | ||
dotted_as_name: dotted_name ['as' NAME] | ||
import_as_names: import_as_name (',' import_as_name)* [','] | ||
dotted_as_names: dotted_as_name (',' dotted_as_name)* | ||
dotted_name: NAME ('.' NAME)* | ||
global_stmt: ('global' | 'nonlocal') NAME (',' NAME)* | ||
exec_stmt: 'exec' expr ['in' test [',' test]] | ||
assert_stmt: 'assert' test [',' test] | ||
|
||
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt | ||
async_stmt: ASYNC (funcdef | with_stmt | for_stmt) | ||
if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite] | ||
while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite] | ||
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] | ||
try_stmt: ('try' ':' suite | ||
((except_clause ':' suite)+ | ||
['else' ':' suite] | ||
['finally' ':' suite] | | ||
'finally' ':' suite)) | ||
with_stmt: 'with' with_item (',' with_item)* ':' suite | ||
with_item: test ['as' expr] | ||
with_var: 'as' expr | ||
# NB compile.c makes sure that the default except clause is last | ||
except_clause: 'except' [test [(',' | 'as') test]] | ||
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT | ||
|
||
# Backward compatibility cruft to support: | ||
# [ x for x in lambda: True, lambda: False if x() ] | ||
# even while also allowing: | ||
# lambda x: 5 if x else 2 | ||
# (But not a mix of the two) | ||
testlist_safe: old_test [(',' old_test)+ [',']] | ||
old_test: or_test | old_lambdef | ||
old_lambdef: 'lambda' [varargslist] ':' old_test | ||
|
||
namedexpr_test: test [':=' test] | ||
test: or_test ['if' or_test 'else' test] | lambdef | ||
or_test: and_test ('or' and_test)* | ||
and_test: not_test ('and' not_test)* | ||
not_test: 'not' not_test | comparison | ||
comparison: expr (comp_op expr)* | ||
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' | ||
star_expr: '*' expr | ||
expr: xor_expr ('|' xor_expr)* | ||
xor_expr: and_expr ('^' and_expr)* | ||
and_expr: shift_expr ('&' shift_expr)* | ||
shift_expr: arith_expr (('<<'|'>>') arith_expr)* | ||
arith_expr: term (('+'|'-') term)* | ||
term: factor (('*'|'@'|'/'|'%'|'//') factor)* | ||
factor: ('+'|'-'|'~') factor | power | ||
power: [AWAIT] atom trailer* ['**' factor] | ||
atom: ('(' [yield_expr|testlist_gexp] ')' | | ||
'[' [listmaker] ']' | | ||
'{' [dictsetmaker] '}' | | ||
'`' testlist1 '`' | | ||
NAME | NUMBER | STRING+ | '.' '.' '.') | ||
listmaker: (namedexpr_test|star_expr) ( comp_for | (',' (namedexpr_test|star_expr))* [','] ) | ||
testlist_gexp: (namedexpr_test|star_expr) ( comp_for | (',' (namedexpr_test|star_expr))* [','] ) | ||
lambdef: 'lambda' [varargslist] ':' test | ||
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME | ||
subscriptlist: subscript (',' subscript)* [','] | ||
subscript: test | [test] ':' [test] [sliceop] | ||
sliceop: ':' [test] | ||
exprlist: (expr|star_expr) (',' (expr|star_expr))* [','] | ||
testlist: test (',' test)* [','] | ||
dictsetmaker: ( ((test ':' test | '**' expr) | ||
(comp_for | (',' (test ':' test | '**' expr))* [','])) | | ||
((test | star_expr) | ||
(comp_for | (',' (test | star_expr))* [','])) ) | ||
|
||
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite | ||
|
||
arglist: argument (',' argument)* [','] | ||
|
||
# "test '=' test" is really "keyword '=' test", but we have no such token. | ||
# These need to be in a single rule to avoid grammar that is ambiguous | ||
# to our LL(1) parser. Even though 'test' includes '*expr' in star_expr, | ||
# we explicitly match '*' here, too, to give it proper precedence. | ||
# Illegal combinations and orderings are blocked in ast.c: | ||
# multiple (test comp_for) arguments are blocked; keyword unpackings | ||
# that precede iterable unpackings are blocked; etc. | ||
argument: ( test [comp_for] | | ||
test ':=' test | | ||
test '=' test | | ||
'**' test | | ||
'*' test ) | ||
|
||
comp_iter: comp_for | comp_if | ||
comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter] | ||
comp_if: 'if' old_test [comp_iter] | ||
|
||
testlist1: test (',' test)* | ||
|
||
# not used in grammar, but may appear in "node" passed from Parser to Compiler | ||
encoding_decl: NAME | ||
|
||
yield_expr: 'yield' [yield_arg] | ||
yield_arg: 'from' test | testlist_star_expr |
28 changes: 28 additions & 0 deletions
28
pyperformance/data-files/benchmarks/bm_2to3/vendor/src/lib2to3/PatternGrammar.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2006 Google, Inc. All Rights Reserved. | ||
# Licensed to PSF under a Contributor Agreement. | ||
|
||
# A grammar to describe tree matching patterns. | ||
# Not shown here: | ||
# - 'TOKEN' stands for any token (leaf node) | ||
# - 'any' stands for any node (leaf or interior) | ||
# With 'any' we can still specify the sub-structure. | ||
|
||
# The start symbol is 'Matcher'. | ||
|
||
Matcher: Alternatives ENDMARKER | ||
|
||
Alternatives: Alternative ('|' Alternative)* | ||
|
||
Alternative: (Unit | NegatedUnit)+ | ||
|
||
Unit: [NAME '='] ( STRING [Repeater] | ||
| NAME [Details] [Repeater] | ||
| '(' Alternatives ')' [Repeater] | ||
| '[' Alternatives ']' | ||
) | ||
|
||
NegatedUnit: 'not' (STRING | NAME [Details] | '(' Alternatives ')') | ||
|
||
Repeater: '*' | '+' | '{' NUMBER [',' NUMBER] '}' | ||
|
||
Details: '<' Alternatives '>' |
Empty file.
4 changes: 4 additions & 0 deletions
4
pyperformance/data-files/benchmarks/bm_2to3/vendor/src/lib2to3/__main__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import sys | ||
from .main import main | ||
|
||
sys.exit(main("lib2to3.fixes")) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you mentioned wanting to avoid this hack and wanting to install it with
pyproject.toml
instead, I thought some more about this and left a comment below explaining how you should be able to avoid all the changes to this file and instead just addlib2to3
it as a dependency to thebm_2to3/pyproject.toml
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What he said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented on the discord, VCS approach is the most approximated way to handle this, but I will keep the current approach since managing the VCS URL has some issues when we want to modify the codes and the bootstrap(?) problem.