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

ylib2to3 -- Fork lib2to3 with some blib2to3 backports; add structured pattern matching (match) and parenthesized-context-managers statement support #1067

Merged
merged 103 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
a0b51d2
Add ylib2to3
char101 Dec 18, 2021
881000e
Yapf modifications to support match statement
char101 Dec 18, 2021
586c299
Disable double indent when splitting parameters after keyword
char101 Dec 18, 2021
d17eb60
Update readme
char101 Dec 18, 2021
49609c1
sync with blib2to3
char101 Jan 14, 2022
bf0c816
Fix comment indent inside match
char101 Feb 26, 2023
36a32e6
Sync with blib2to3
char101 Feb 26, 2023
a2b9464
Misc changes
char101 Feb 26, 2023
3f5df6c
Fix imports
char101 Feb 26, 2023
c749435
Fix typo
char101 Feb 26, 2023
b6c2342
yapf ylib2to3
Spitfire1900 Apr 19, 2023
df8eaff
Remove YAPF fork message
Spitfire1900 Apr 19, 2023
f88d351
Merge branch 'main' into 3.10
Spitfire1900 Apr 25, 2023
bfe6887
fix imports
Spitfire1900 Apr 25, 2023
e38ced1
add vscode settings to gitignore
Spitfire1900 Apr 25, 2023
e8e01ee
remove pickles
Spitfire1900 Apr 25, 2023
5e81cf4
Merge remote-tracking branch 'google/main' into 3.10
Spitfire1900 Apr 28, 2023
9595044
run yapf over the workspace
Spitfire1900 Apr 28, 2023
ced0d69
remove E501 errors
Spitfire1900 May 2, 2023
10e2c45
no more flake8 errors in yapf prime
Spitfire1900 May 2, 2023
ccab2d7
no E266 in ylib2to3
Spitfire1900 May 2, 2023
2979c5e
Revert "Disable double indent when splitting parameters after keyword"
Spitfire1900 May 2, 2023
ba1aa28
E265
Spitfire1900 May 2, 2023
faf3f92
E127
Spitfire1900 May 2, 2023
d302940
F841
Spitfire1900 May 2, 2023
e1dfeae
E722
Spitfire1900 May 2, 2023
8f6c59d
E721
Spitfire1900 May 2, 2023
fc10524
E741
Spitfire1900 May 2, 2023
d589534
E502
Spitfire1900 May 2, 2023
2dd4abb
Remove unused copy
Spitfire1900 May 2, 2023
9e1b23d
pygram - remove unused imports
Spitfire1900 May 2, 2023
75bef18
strstart and endprog
Spitfire1900 May 2, 2023
561a124
Need to add pickle txt files
Spitfire1900 May 2, 2023
af26198
F401
Spitfire1900 May 2, 2023
6cee88b
Add testMatchStatementRemoveSpacesInCaseBracket
Spitfire1900 May 2, 2023
8d7740c
Revert "Add testMatchStatementRemoveSpacesInCaseBracket"
Spitfire1900 May 2, 2023
03adcc7
testPatternMatching
Spitfire1900 May 2, 2023
c64b152
run yapf on setup.py
Spitfire1900 May 2, 2023
153df0c
format_token was still installing lib2to3
Spitfire1900 May 2, 2023
ccd5205
testpatternMatching should expect spaces between case and bracket
Spitfire1900 May 2, 2023
0331784
add credit to black
Spitfire1900 May 2, 2023
926233b
Merge branch 'main' into 3.10
Spitfire1900 May 2, 2023
4c10c07
Merge remote-tracking branch 'google/main' into 3.10
Spitfire1900 May 3, 2023
d622bf6
Merge remote-tracking branch 'google/main' into 3.10
Spitfire1900 May 5, 2023
c4b26b9
move ylib2to3 to third_party
Spitfire1900 May 5, 2023
f1cf3ca
fix package_data
Spitfire1900 May 5, 2023
89c46b6
add LICENSE
Spitfire1900 May 5, 2023
8edbbbb
different keys for each third_party package
Spitfire1900 May 5, 2023
155e560
remove trailing comma
Spitfire1900 May 5, 2023
0e86a24
place *.pickle files in tmp dir
Spitfire1900 May 5, 2023
71deeb2
try to fix PyZipFile case
Spitfire1900 May 5, 2023
96ec816
add compiled pickles to package output
Spitfire1900 May 5, 2023
16bbedf
add comments
Spitfire1900 May 5, 2023
1a6b718
use post develop and install commands in setup.py
Spitfire1900 May 5, 2023
4813200
Decided that an unclean uninstall with package_data support was the b…
Spitfire1900 May 8, 2023
45d8724
finish revert of tempfile logic
Spitfire1900 May 8, 2023
1e1c9aa
Clean up some typing
Spitfire1900 May 8, 2023
279a640
refactor to yapf.third_party
Spitfire1900 May 9, 2023
6ef2507
rename testPatternMatching to testStructuredPatternMatching
Spitfire1900 May 11, 2023
68e9e2d
add test for testParenthesizedContextManagers
Spitfire1900 May 11, 2023
da30fae
E501
Spitfire1900 May 11, 2023
6338c5b
move to _ylib2to3
Spitfire1900 May 11, 2023
7a9214b
update readme
Spitfire1900 May 11, 2023
4ccee1b
add some additional notes to readme, still requires a list of backpor…
Spitfire1900 May 11, 2023
e346da8
undo changes to load_packaged_grammar and call load_grammar instead
Spitfire1900 May 12, 2023
6403ffc
add some pydoc to _generate_pickle_name()
Spitfire1900 May 15, 2023
ec5e4e7
add summary.
Spitfire1900 May 15, 2023
c7368e2
PoC impl. -- write pickle files to user-specific cache dir
Spitfire1900 May 15, 2023
ace0391
pydoc cleanup
Spitfire1900 May 15, 2023
ea23c1b
ci was passing because tomli was installed by pytest
Spitfire1900 May 15, 2023
c8363ab
for now install dependencies manually
Spitfire1900 May 15, 2023
d46f501
use PKG_INFO.ini
Spitfire1900 May 15, 2023
7fa40a5
get package data from including config ini file
Spitfire1900 May 15, 2023
5df77a8
Revert "for now install dependencies manually"
Spitfire1900 May 15, 2023
b56ccb3
install workdir before running pytest
Spitfire1900 May 15, 2023
30d4eac
github ci debugging
Spitfire1900 May 15, 2023
909e149
do not do fancy things with modules
Spitfire1900 May 15, 2023
787d3b1
fixup
Spitfire1900 May 15, 2023
c40eb35
use https://pypi.org/project/importlib-metadata
Spitfire1900 May 15, 2023
04ec7c0
do not use __cache_dir__ as only one function cares about it
Spitfire1900 May 16, 2023
2fd1b44
use metadata for yapf.__version__
Spitfire1900 May 16, 2023
ff7b2da
install YAPF as it's own step in GitHub CI
Spitfire1900 May 16, 2023
f409564
remove PKG_INFO.ini, using importlib_metadata
Spitfire1900 May 16, 2023
1600deb
correct _ylib2to3 package pydoc
Spitfire1900 May 16, 2023
6803b52
_ylib2to3, not ylib2to3 in get_data() call
Spitfire1900 May 16, 2023
e4ed3ec
accidentally removed importlib-metadata from install_requires
Spitfire1900 May 16, 2023
b53b22d
apply isort config from #1093
Spitfire1900 May 16, 2023
b05cf2e
Only exclude .vscode/settings.json in the git root directory (#1)
Spitfire1900 May 18, 2023
203c6da
Merge google/yapf#1067, treat yapf.third_party as a third_party in is…
Spitfire1900 May 19, 2023
f9a4d25
Merge remote-tracking branch 'google/main' into 3.10
Spitfire1900 May 19, 2023
5f3e560
move known_third_party ahead of known_yapftests
Spitfire1900 May 19, 2023
e55ab26
yapf is being installed twice
Spitfire1900 May 19, 2023
44703f4
no verbose output
Spitfire1900 May 19, 2023
b3efc3a
Merge remote-tracking branch 'google/main' into 3.10
Spitfire1900 May 26, 2023
5ea5b92
Move yapf.third_party to third_party, install at yapf_third_party though
Spitfire1900 May 26, 2023
2cf7cb7
Merge remote-tracking branch 'google/main' into 3.10
Spitfire1900 May 27, 2023
3b1883b
fixup ci.yml
Spitfire1900 May 27, 2023
bcb78ad
dedent yaml
Spitfire1900 May 27, 2023
1c8616e
install to system instead of user
Spitfire1900 May 27, 2023
1b85529
if pip is going to be upgraded it needs to be upgraded first
Spitfire1900 May 27, 2023
a522ce3
better GH workflow naming
Spitfire1900 May 27, 2023
8066d4e
Revert "better GH workflow naming"
Spitfire1900 May 27, 2023
59760c3
better GH workflow naming
Spitfire1900 May 27, 2023
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ jobs:
uses: actions/setup-python@57ded4d7d5e986d7296eab16560982c6dd7c923b # v4.6.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Update pip
run: |
python -m pip install --upgrade pip
- name: Install YAPF
run: |
pip install .
- name: Lint with flake8
run: |
python -m pip install flake8
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
.sw?
# OS X specific files.
.DS_store
*.pickle

#==============================================================================#
# Files to ignore
Expand All @@ -34,4 +35,5 @@
/yapf.egg-info

/.idea
.vscode/settings.json
Spitfire1900 marked this conversation as resolved.
Show resolved Hide resolved
/.venv*/
25 changes: 19 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import sys
import unittest

from setuptools import find_packages, setup, Command

import yapf
from setuptools import Command
from setuptools import find_packages
from setuptools import setup


class RunTests(Command):
Expand All @@ -42,7 +42,7 @@ def run(self):
with codecs.open('README.rst', 'r', 'utf-8') as fd:
setup(
name='yapf',
version=yapf.__version__,
version='0.33.0',
description='A formatter for Python code.',
url='https://github.com/google/yapf',
long_description=fd.read(),
Expand Down Expand Up @@ -74,12 +74,25 @@ def run(self):
entry_points={
'console_scripts': [
'yapf = yapf:run_main',
'yapf-diff = third_party.yapf_diff.yapf_diff:main',
'yapf-diff = yapf.third_party.yapf_diff.yapf_diff:main',
],
},
cmdclass={
'test': RunTests,
},
package_data={
'yapf': [
'third_party/yapf_diff/LICENSE',
'third_party/_ylib2to3/Grammar.txt',
'third_party/_ylib2to3/PatternGrammar.txt',
'third_party/_ylib2to3/LICENSE',
]
},
include_package_data=True,
python_requires='>=3.7',
install_requires=['tomli>=2.0.1'],
install_requires=[
'importlib-metadata>=6.6.0',
'platformdirs>=3.5.1',
'tomli>=2.0.1',
],
)
6 changes: 4 additions & 2 deletions yapf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
import os
import sys

from importlib_metadata import metadata

from yapf.yapflib import errors
from yapf.yapflib import file_resources
from yapf.yapflib import style
from yapf.yapflib import yapf_api

__version__ = '0.33.0'
__version__ = metadata('yapf')['Version']


def _raw_input():
Expand Down Expand Up @@ -200,8 +202,8 @@ def FormatFiles(filenames,
"""
changed = False
if parallel:
import multiprocessing # pylint: disable=g-import-not-at-top
import concurrent.futures # pylint: disable=g-import-not-at-top
import multiprocessing # pylint: disable=g-import-not-at-top
workers = min(multiprocessing.cpu_count(), len(filenames))
with concurrent.futures.ProcessPoolExecutor(workers) as executor:
future_formats = [
Expand Down
6 changes: 2 additions & 4 deletions yapf/pytree/blank_line_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
newlines: The number of newlines required before the node.
"""

from lib2to3.pgen2 import token as grammar_token

from yapf.pytree import pytree_utils
from yapf.pytree import pytree_visitor
from yapf.third_party._ylib2to3.pgen2 import token as grammar_token
from yapf.yapflib import style

_NO_BLANK_LINES = 1
Expand Down Expand Up @@ -174,5 +173,4 @@ def _StartsInZerothColumn(node):


def _AsyncFunction(node):
return (node.prev_sibling and
node.prev_sibling.type == grammar_token.ASYNC)
return (node.prev_sibling and node.prev_sibling.type == grammar_token.ASYNC)
7 changes: 3 additions & 4 deletions yapf/pytree/comment_splicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
SpliceComments(): the main function exported by this module.
"""

from lib2to3 import pygram
from lib2to3 import pytree
from lib2to3.pgen2 import token

from yapf.pytree import pytree_utils
from yapf.third_party._ylib2to3 import pygram
from yapf.third_party._ylib2to3 import pytree
from yapf.third_party._ylib2to3.pgen2 import token


def SpliceComments(tree):
Expand Down
3 changes: 1 addition & 2 deletions yapf/pytree/continuation_splicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
SpliceContinuations(): the main function exported by this module.
"""

from lib2to3 import pytree

from yapf.third_party._ylib2to3 import pytree
from yapf.yapflib import format_token


Expand Down
31 changes: 24 additions & 7 deletions yapf/pytree/pytree_unwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
For most uses, the convenience function UnwrapPyTree should be sufficient.
"""

# The word "token" is overloaded within this module, so for clarity rename
# the imported pgen2.token module.
from lib2to3 import pytree
from lib2to3.pgen2 import token as grammar_token

from yapf.pytree import pytree_utils
from yapf.pytree import pytree_visitor
from yapf.pytree import split_penalty
# The word "token" is overloaded within this module, so for clarity rename
# the imported pgen2.token module.
from yapf.third_party._ylib2to3 import pytree
from yapf.third_party._ylib2to3.pgen2 import token as grammar_token
from yapf.yapflib import format_token
from yapf.yapflib import logical_line
from yapf.yapflib import object_state
Expand Down Expand Up @@ -125,6 +124,8 @@ def _StartNewLine(self):
'try_stmt',
'expect_clause',
'with_stmt',
'match_stmt',
'case_block',
'funcdef',
'classdef',
})
Expand All @@ -144,11 +145,13 @@ def Visit_simple_stmt(self, node):
single_stmt_suite = (
node.parent and pytree_utils.NodeName(node.parent) in self._STMT_TYPES)
is_comment_stmt = pytree_utils.IsCommentStatement(node)
if single_stmt_suite and not is_comment_stmt:
is_inside_match = node.parent and pytree_utils.NodeName(
node.parent) == 'match_stmt'
if (single_stmt_suite and not is_comment_stmt) or is_inside_match:
self._cur_depth += 1
self._StartNewLine()
self.DefaultNodeVisit(node)
if single_stmt_suite and not is_comment_stmt:
if (single_stmt_suite and not is_comment_stmt) or is_inside_match:
self._cur_depth -= 1

def _VisitCompoundStatement(self, node, substatement_names):
Expand Down Expand Up @@ -253,6 +256,20 @@ def Visit_decorated(self, node): # pylint: disable=invalid-name
def Visit_with_stmt(self, node): # pylint: disable=invalid-name
self._VisitCompoundStatement(node, self._WITH_STMT_ELEMS)

_MATCH_STMT_ELEMS = frozenset({'match', 'case'})

def Visit_match_stmt(self, node): # pylint: disable=invalid-name
self._VisitCompoundStatement(node, self._MATCH_STMT_ELEMS)

# case_block refers to the grammar element name in Grammar.txt
_CASE_BLOCK_ELEMS = frozenset({'case'})

def Visit_case_block(self, node):
self._cur_depth += 1
self._StartNewLine()
self._VisitCompoundStatement(node, self._CASE_BLOCK_ELEMS)
self._cur_depth -= 1

def Visit_suite(self, node): # pylint: disable=invalid-name
# A 'suite' starts a new indentation level in Python.
self._cur_depth += 1
Expand Down
10 changes: 5 additions & 5 deletions yapf/pytree/pytree_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import ast
import os

from lib2to3 import pygram
from lib2to3 import pytree
from lib2to3.pgen2 import driver
from lib2to3.pgen2 import parse
from lib2to3.pgen2 import token
from yapf.third_party._ylib2to3 import pygram
from yapf.third_party._ylib2to3 import pytree
from yapf.third_party._ylib2to3.pgen2 import driver
from yapf.third_party._ylib2to3.pgen2 import parse
from yapf.third_party._ylib2to3.pgen2 import token

# TODO(eliben): We may want to get rid of this filtering at some point once we
# have a better understanding of what information we need from the tree. Then,
Expand Down
3 changes: 1 addition & 2 deletions yapf/pytree/pytree_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@

import sys

from lib2to3 import pytree

from yapf.pytree import pytree_utils
from yapf.third_party._ylib2to3 import pytree


class PyTreeVisitor(object):
Expand Down
5 changes: 2 additions & 3 deletions yapf/pytree/split_penalty.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

import re

from lib2to3 import pytree
from lib2to3.pgen2 import token as grammar_token

from yapf.pytree import pytree_utils
from yapf.pytree import pytree_visitor
from yapf.third_party._ylib2to3 import pytree
from yapf.third_party._ylib2to3.pgen2 import token as grammar_token
from yapf.yapflib import style
from yapf.yapflib import subtypes

Expand Down
7 changes: 3 additions & 4 deletions yapf/pytree/subtype_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
subtypes.
"""

from lib2to3 import pytree
from lib2to3.pgen2 import token as grammar_token
from lib2to3.pygram import python_symbols as syms

from yapf.pytree import pytree_utils
from yapf.pytree import pytree_visitor
from yapf.third_party._ylib2to3 import pytree
from yapf.third_party._ylib2to3.pgen2 import token as grammar_token
from yapf.third_party._ylib2to3.pygram import python_symbols as syms
from yapf.yapflib import style
from yapf.yapflib import subtypes

Expand Down
File renamed without changes.
Loading