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

Use ufmt to unify black and import sort order #515

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: exit 1
- run: flake8
- run: isort --check-only .
- run: black --check libcst/
- run: ufmt check .
- run: python3 -m fixit.cli.run_rules

# Run pyre typechecker
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## Coding Style
We use flake8, isort and black to enforce coding style.
We use flake8 and ufmt to enforce coding style.

## License
By contributing to LibCST, you agree that your contributions will be licensed
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ Start by setting up and activating a virtualenv:
# If you're done with the virtualenv, you can leave it by running:
deactivate

We use `isort <https://isort.readthedocs.io/en/stable/>`_ and `black <https://black.readthedocs.io/en/stable/>`_
to format code. To format changes to be conformant, run the following in the root:
We use `ufmt <https://ufmt.omnilib.dev/en/stable/>`_ to format code. To format
changes to be conformant, run the following in the root:

.. code-block:: shell

Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"source": [
"Generate Source Code\n",
"====================\n",
"Generating the source code from a cst tree is as easy as accessing the :attr:`~libcst.Module.code` attribute on :class:`~libcst.Module`. After the code generation, we often use `Black <https://black.readthedocs.io/en/stable/>`_ and `isort <https://isort.readthedocs.io/en/stable/>`_ to reformate the code to keep a consistent coding style."
"Generating the source code from a cst tree is as easy as accessing the :attr:`~libcst.Module.code` attribute on :class:`~libcst.Module`. After the code generation, we often use `ufmt <https://ufmt.omnilib.dev/en/stable/>`_ to reformate the code to keep a consistent coding style."
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions libcst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@
from libcst._removal_sentinel import RemovalSentinel, RemoveFromParent
from libcst._visitors import CSTNodeT, CSTTransformer, CSTVisitor, CSTVisitorT


try:
from libcst._version import version as LIBCST_VERSION
except ImportError:
Expand All @@ -207,7 +206,6 @@
)
from libcst.metadata.wrapper import MetadataWrapper


__all__ = [
"KNOWN_PYTHON_VERSION_STRINGS",
"LIBCST_VERSION",
Expand Down
1 change: 0 additions & 1 deletion libcst/_add_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dataclasses
from typing import Any, Mapping, Type, TypeVar


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_batched_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from libcst._typed_visitor import CSTTypedVisitorFunctions
from libcst._visitors import CSTNodeT, CSTVisitor


if TYPE_CHECKING:
from libcst._nodes.base import CSTNode # noqa: F401

Expand Down
1 change: 0 additions & 1 deletion libcst/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from libcst._parser.types.token import Token
from libcst._tabs import expand_tabs


_EOF_STR: str = "end of file (EOF)"
_INDENT_STR: str = "an indent"
_DEDENT_STR: str = "a dedent"
Expand Down
1 change: 0 additions & 1 deletion libcst/_flatten_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import sys


# PEP 585
if sys.version_info < (3, 9):
from typing import Iterable, Sequence
Expand Down
1 change: 0 additions & 1 deletion libcst/_metadata_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
cast,
)


if TYPE_CHECKING:
# Circular dependency for typing reasons only
from libcst._nodes.base import CSTNode # noqa: F401
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from libcst._types import CSTNodeT
from libcst._visitors import CSTTransformer, CSTVisitor, CSTVisitorT


_CSTNodeSelfT = TypeVar("_CSTNodeSelfT", bound="CSTNode")
_EMPTY_SEQUENCE: Sequence["CSTNode"] = ()

Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from libcst._removal_sentinel import RemovalSentinel
from libcst._types import CSTNodeT


if TYPE_CHECKING:
# These are circular dependencies only used for typing purposes
from libcst._nodes.base import CSTNode # noqa: F401
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from libcst._removal_sentinel import RemovalSentinel
from libcst._visitors import CSTVisitorT


if TYPE_CHECKING:
# This is circular, so import the type only in type checking
from libcst._parser.types.config import PartialParserConfig
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
)
from libcst._visitors import CSTVisitorT


_INDENT_WHITESPACE_RE: Pattern[str] = re.compile(r"[ \f\t]+", re.UNICODE)


Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/tests/test_cst_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from libcst._visitors import CSTTransformer
from libcst.testing.utils import UnitTest, data_provider, none_throws


_EMPTY_SIMPLE_WHITESPACE = cst.SimpleWhitespace("")


Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)
from libcst._visitors import CSTVisitorT


# SimpleWhitespace includes continuation characters, which must be followed immediately
# by a newline. SimpleWhitespace does not include other kinds of newlines, because those
# may have semantic significance.
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from libcst._parser.parso.python.token import TokenType
from libcst._parser.types.token import Token


_NodeT = TypeVar("_NodeT")
_TokenTypeT = TypeVar("_TokenTypeT", bound=TokenType)
_TokenT = TypeVar("_TokenT", bound=Token)
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/conversions/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
from libcst._parser.types.token import Token
from libcst._parser.whitespace_parser import parse_parenthesizable_whitespace


BINOP_TOKEN_LUT: typing.Dict[str, typing.Type[BaseBinaryOp]] = {
"*": Multiply,
"@": MatrixMultiply,
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/conversions/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
parse_simple_whitespace,
)


AUGOP_TOKEN_LUT: Dict[str, Type[BaseAugOp]] = {
"+=": AddAssign,
"-=": SubtractAssign,
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/custom_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from itertools import zip_longest
from typing import Iterable, Iterator, TypeVar


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/detect_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from libcst._parser.types.token import Token
from libcst._parser.wrapped_tokenize import tokenize_lines


_INDENT: TokenType = PythonTokenTypes.INDENT
_NAME: TokenType = PythonTokenTypes.NAME
_NEWLINE: TokenType = PythonTokenTypes.NEWLINE
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from libcst._parser.python_parser import PythonCSTParser
from libcst._parser.types.config import PartialParserConfig


_DEFAULT_PARTIAL_PARSER_CONFIG: PartialParserConfig = PartialParserConfig()


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
from libcst._parser.types.conversions import NonterminalConversion, TerminalConversion
from libcst._parser.types.production import Production


# Keep this sorted alphabetically
_TERMINAL_CONVERSIONS_SEQUENCE: Tuple[TerminalConversion, ...] = (
convert_DEDENT,
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/pgen2/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

from libcst._parser.parso.pgen2.grammar_parser import GrammarParser, NFAState


_TokenTypeT = TypeVar("_TokenTypeT")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/python/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from libcst._parser.parso.python.token import PythonTokenTypes
from libcst._parser.parso.utils import PythonVersionInfo, split_lines


# Maximum code point of Unicode 6.0: 0x10ffff (1,114,111)
MAX_UNICODE = "\U0010ffff"
BOM_UTF8_STRING = BOM_UTF8.decode("utf-8")
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/tests/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from libcst._parser.parso.utils import parse_version_string, split_lines
from libcst.testing.utils import UnitTest, data_provider


# To make it easier to access some of the token types, just put them here.
NAME = PythonTokenTypes.NAME
NEWLINE = PythonTokenTypes.NEWLINE
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from dataclasses import dataclass
from typing import Optional, Sequence, Tuple, Union


# The following is a list in Python that are line breaks in str.splitlines, but
# not in Python. In Python only \r (Carriage Return, 0xD) and \n (Line Feed,
# 0xA) are allowed to split lines.
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/production_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from libcst._parser.types.conversions import NonterminalConversion
from libcst._parser.types.production import Production


_NonterminalConversionT = TypeVar(
"_NonterminalConversionT", bound=NonterminalConversion
)
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/tests/test_whitespace_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
)
from libcst.testing.utils import UnitTest, data_provider


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/tests/test_wrapped_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from libcst._parser.wrapped_tokenize import Token, tokenize
from libcst.testing.utils import UnitTest, data_provider


_PY38 = parse_version_string("3.8.0")
_PY37 = parse_version_string("3.7.0")
_PY36 = parse_version_string("3.6.0")
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from libcst._nodes.whitespace import NEWLINE_RE
from libcst._parser.parso.utils import PythonVersionInfo, parse_version_string


_INDENT_RE: Pattern[str] = re.compile(r"[ \t]+")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/types/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from libcst._parser.types.config import ParserConfig
from libcst._parser.types.token import Token


# pyre-fixme[33]: Aliased annotation cannot contain `Any`.
NonterminalConversion = Callable[[ParserConfig, Sequence[Any]], Any]
# pyre-fixme[33]: Aliased annotation cannot contain `Any`.
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/types/partials.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from libcst._nodes.whitespace import EmptyLine, SimpleWhitespace, TrailingWhitespace
from libcst._parser.types.whitespace_state import WhitespaceState


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/whitespace_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from libcst._parser.types.config import BaseWhitespaceParserConfig
from libcst._parser.types.whitespace_state import WhitespaceState as State


# BEGIN PARSER ENTRYPOINTS


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/wrapped_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from libcst._parser.types.token import Token
from libcst._parser.types.whitespace_state import WhitespaceState


_ERRORTOKEN: TokenType = PythonTokenTypes.ERRORTOKEN
_ERROR_DEDENT: TokenType = PythonTokenTypes.ERROR_DEDENT

Expand Down
1 change: 0 additions & 1 deletion libcst/_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from libcst._add_slots import add_slots


_CodePositionT = Union[Tuple[int, int], "CodePosition"]


Expand Down
1 change: 0 additions & 1 deletion libcst/_type_enforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing_extensions import Literal
from typing_inspect import get_args, get_origin, is_classvar, is_typevar, is_union_type


try: # py37+
from typing import ForwardRef
except ImportError: # py36
Expand Down
8 changes: 4 additions & 4 deletions libcst/_typed_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# This file was generated by libcst.codegen.gen_matcher_classes
from typing import TYPE_CHECKING, Optional, Union
from typing import Optional, Union, TYPE_CHECKING

from libcst._flatten_sentinel import FlattenSentinel
from libcst._maybe_sentinel import MaybeSentinel
Expand All @@ -28,10 +28,10 @@
BinaryOperation,
BooleanOperation,
Call,
Comparison,
ComparisonTarget,
CompFor,
CompIf,
Comparison,
ComparisonTarget,
ConcatenatedString,
Dict,
DictComp,
Expand All @@ -57,9 +57,9 @@
Name,
NamedExpr,
Param,
Parameters,
ParamSlash,
ParamStar,
Parameters,
RightCurlyBrace,
RightParen,
RightSquareBracket,
Expand Down
1 change: 0 additions & 1 deletion libcst/_typed_visitor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast


if TYPE_CHECKING:
from libcst._typed_visitor import CSTTypedBaseFunctions # noqa: F401

Expand Down
1 change: 0 additions & 1 deletion libcst/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from typing import TYPE_CHECKING, TypeVar


if TYPE_CHECKING:
from libcst._nodes.base import CSTNode # noqa: F401

Expand Down
1 change: 0 additions & 1 deletion libcst/_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from libcst._typed_visitor import CSTTypedTransformerFunctions, CSTTypedVisitorFunctions
from libcst._types import CSTNodeT


if TYPE_CHECKING:
# Circular dependency for typing reasons only
from libcst._nodes.base import CSTNode # noqa: F401
Expand Down
1 change: 0 additions & 1 deletion libcst/codegen/gen_matcher_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from libcst import ensure_type, parse_expression
from libcst.codegen.gather import all_libcst_nodes, typeclasses


CST_DIR: Set[str] = set(dir(cst))
CLASS_RE = r"<class \'(.*?)\'>"
OPTIONAL_RE = r"typing\.Union\[([^,]*?), NoneType]"
Expand Down
1 change: 0 additions & 1 deletion libcst/codegen/gen_type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from libcst.codegen.gather import imports, nodebases, nodeuses


generated_code: List[str] = []
generated_code.append("# Copyright (c) Facebook, Inc. and its affiliates.")
generated_code.append("#")
Expand Down
1 change: 0 additions & 1 deletion libcst/codegen/gen_visitor_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from libcst.codegen.gather import imports, nodebases, nodeuses


generated_code: List[str] = []
generated_code.append("# Copyright (c) Facebook, Inc. and its affiliates.")
generated_code.append("#")
Expand Down
Loading