pax_global_header00006660000000000000000000000064143460662440014523gustar00rootroot0000000000000052 comment=868b41554a6b57d74e916d33c37469e0d0b4b9cc flake8-black-0.3.6/000077500000000000000000000000001434606624400137555ustar00rootroot00000000000000flake8-black-0.3.6/.flake8000066400000000000000000000021121434606624400151240ustar00rootroot00000000000000[flake8] # Recommend matching the black line length (default 88), # rather than using the flake8 default of 79: max-line-length = 88 extend-ignore = # See https://github.com/PyCQA/pycodestyle/issues/373 # flake8/pycodechecker give false positives on black code E203, # Most of our test cases deliberately violate style checks: per-file-ignores = # These are meant to trigger black changes: tests/test_changes/hello_world.py: E201,E202,E211,W391,BLK100 tests/test_changes/hello_world_EOF.py: W292,BLK100 tests/without_pyproject_toml/ordinary_quotes.py: Q000,BLK100 # These are not meant to trigger black changes: tests/test_cases/no_closing_bracket.py: E902 tests/test_fail/mixed_tab_spaces.py: E101,E999,W191 tests/with_pyproject_toml/ordinary_quotes.py: Q000 tests/test_cases/mixed_tab_spaces.py: E101,E999,W191 # The bad TOML file breaks black checking this file: tests/with_bad_toml/hello_world.py: BLK997, # ===================== # flake-quote settings: # ===================== # Set this to match black style: inline-quotes = double flake8-black-0.3.6/.github/000077500000000000000000000000001434606624400153155ustar00rootroot00000000000000flake8-black-0.3.6/.github/workflows/000077500000000000000000000000001434606624400173525ustar00rootroot00000000000000flake8-black-0.3.6/.github/workflows/test.yml000066400000000000000000000022071434606624400210550ustar00rootroot00000000000000name: test on: [push, pull_request] jobs: run-tests: runs-on: ${{ matrix.os }} defaults: run: shell: bash strategy: fail-fast: false matrix: os: [windows-latest, macos-latest, ubuntu-latest] python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Git configuration run: | git config core.autocrlf false git reset --hard - name: Build packages, and install the wheel run: | pip install build python -m build cd dist python -m pip install flake8_black-*.whl cd .. # Wheel should now be installed flake8 --version - name: Run tests run: | # Unpack the tests from the sdist tar-ball # (want to confirm the manifest was complete) tar -zxvf dist/flake8-black-*.tar.gz cd flake8-black-*/tests/ WIN="$([ "$RUNNER_OS" == "Windows" ];echo $?)" bash ./run_tests.sh flake8-black-0.3.6/.gitignore000066400000000000000000000006601434606624400157470ustar00rootroot00000000000000#Ignore the build directory (and its sub-directories): build #Ignore the distribution directory dist #Ignore another Python specific build folder: flake8_black.egg-info/ #Ignore backup files from some Unix editors, *~ *.swp *.bak #Ignore patches and any original files created by patch command *.diff *.orig *.rej #Ignore these hidden files from Mac OS X .DS_Store #Ignore hidden files from Dolphin window manager .directory flake8-black-0.3.6/.pre-commit-config.yaml000066400000000000000000000036501434606624400202420ustar00rootroot00000000000000# pre-commit run --all-files repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - id: check-added-large-files - id: check-case-conflict - id: check-executables-have-shebangs - id: check-merge-conflict - id: check-shebang-scripts-are-executable - id: check-symlinks - id: check-yaml - id: debug-statements exclude: tests/ - id: destroyed-symlinks - id: end-of-file-fixer exclude: tests/test_changes/ files: \.(py|sh|rst|yml|yaml)$ - id: mixed-line-ending - id: trailing-whitespace files: \.(py|sh|rst|yml|yaml)$ - repo: https://github.com/psf/black rev: 22.10.0 hooks: - id: black exclude: tests/ args: [--check] - repo: https://github.com/PyCQA/flake8 rev: 6.0.0 hooks: - id: flake8 additional_dependencies: [ 'flake8-blind-except', 'flake8-docstrings', 'flake8-bugbear', 'flake8-comprehensions', 'flake8-docstrings', 'flake8-implicit-str-concat', 'pydocstyle>=5.0.0', ] exclude: ^tests/test_cases/no_closing_bracket\.py$ - repo: https://github.com/asottile/blacken-docs rev: v1.12.1 hooks: - id: blacken-docs additional_dependencies: [black==22.10.0] exclude: ^.github/ - repo: https://github.com/rstcheck/rstcheck rev: v6.1.1 hooks: - id: rstcheck args: [ --report-level=warning, ] - repo: https://github.com/codespell-project/codespell rev: v2.2.2 hooks: - id: codespell files: \.(py|sh|rst|yml|yaml)$ ci: # Settings for the https://pre-commit.ci/ continuous integration service autofix_prs: false # Default message is more verbose autoupdate_commit_msg: '[pre-commit.ci] autoupdate' # Default is weekly autoupdate_schedule: monthly flake8-black-0.3.6/LICENSE.rst000066400000000000000000000020741434606624400155740ustar00rootroot00000000000000Copyright 2019, Peter Cock, The James Hutton Institute, UK. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. flake8-black-0.3.6/MANIFEST.in000066400000000000000000000001571434606624400155160ustar00rootroot00000000000000include README.rst include LICENSE.rst include requirements.txt recursive-include tests *.py *.txt *.sh *.toml flake8-black-0.3.6/README.rst000066400000000000000000000254301434606624400154500ustar00rootroot00000000000000flake8-black ============ .. image:: https://img.shields.io/pypi/v/flake8-black.svg :alt: Released on the Python Package Index (PyPI) :target: https://pypi.org/project/flake8-black/ .. image:: https://img.shields.io/conda/vn/conda-forge/flake8-black.svg :alt: Released on Conda :target: https://anaconda.org/conda-forge/flake8-black .. image:: https://results.pre-commit.ci/badge/github/peterjc/flake8-black/master.svg :target: https://results.pre-commit.ci/latest/github/peterjc/flake8-black/master :alt: pre-commit.ci status .. image:: https://img.shields.io/github/workflow/status/peterjc/flake8-black/test?logo=github-actions :alt: GitHub workflow status :target: https://github.com/peterjc/flake8-black/actions .. image:: https://img.shields.io/pypi/dm/flake8-black.svg :alt: PyPI downloads :target: https://pypistats.org/packages/flake8-black .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :alt: Code style: black :target: https://github.com/python/black Introduction ------------ This is an MIT licensed `flake8 `_ plugin for validating Python code style with the command line code formatting tool `black `_. It is available to install from the `Python Package Index (PyPI) `_. Black, *"The Uncompromising Code Formatter"*, is normally run to edit your Python code in place to match their coding style, a strict subset of the `PEP 8 style guide `_. The point of this plugin is to be able to run ``black --check ...`` from within the ``flake8`` plugin ecosystem. You might use this via a ``git`` pre-commit hook, or as part of your continuous integration testing. If you are using `pre-commit `_ configure it to call black and/or flake8 directly - you do not need flake8-black at all. Flake8 Validation codes ----------------------- Early versions of flake8 assumed a single character prefix for the validation codes, which became problematic with collisions in the plugin ecosystem. Since v3.0, flake8 has supported longer prefixes, therefore this plugin uses ``BLK`` as its prefix. ====== ======================================================================= Code Description (*and notes*) ------ ----------------------------------------------------------------------- BLK100 Black would make changes. BLK9## Internal error (*various, listed below*): BLK900 Failed to load file: ... BLK901 Invalid input. BLK997 Invalid TOML file: ... BLK998 Could not access flake8 line length setting (*no longer used*). BLK999 Unexpected exception. ====== ======================================================================= Note that if your Python code has a syntax error, ``black --check ...`` would report this as an error. Likewise ``flake8 ...`` will by default report the syntax error, but importantly it does not seem to then call the plugins, so you will *not* get an additional ``BLK`` error. Installation ------------ Python 3.7 or later is required, but ``black`` can be used on Python code written for older versions of Python. You can install ``flake8-black`` using ``pip``, which should install ``flake8`` and ``black`` as well if not already present:: $ pip install flake8-black Alternatively, if you are using the Anaconda packaging system, the following command will install the plugin with its dependencies:: $ conda install -c conda-forge flake8-black The new validator should be automatically included when using ``flake8`` which may now report additional validation codes starting with ``BLK`` (as defined above). For example:: $ flake8 example.py You can request only the ``BLK`` codes be shown using:: $ flake8 --select BLK example.py Python package management ------------------------- We covered using pip or conda by hand above. If you are using a PyPI based Python dependency system like pipenv or poetry, you may run into complications because at the time of writing all the black releases to PyPI have been tagged as pre-releases (beta code). `PEP440 Handling of pre-releases `_ could be more explicit here. For pipenv, flake8-black v0.2.0 onwards should just work. For poetry, include this in your ``pyproject.toml`` configuration file:: [tool.poetry.dev-dependencies] ... black = { version = "*", allow-prereleases = true } ... In either case, for large projects you should consider pinning the exact version of black you want to use as their updates do sometimes introduce changes which would show up as new ``BLK100`` violations via flake8. Configuration ------------- We assume you are familiar with `flake8 configuration `_ and `black configuration `_. We recommend using the following settings in your ``flake8`` configuration, for example in your ``.flake8``, ``setup.cfg``, or ``tox.ini`` file:: [flake8] # Recommend matching the black line length (default 88), # rather than using the flake8 default of 79: max-line-length = 88 extend-ignore = # See https://github.com/PyCQA/pycodestyle/issues/373 E203, Note currently ``pycodestyle`` gives false positives on the spaces ``black`` uses for slices, which ``flake8`` reports as ``E203: whitespace before ':'``. Until `pyflakes issue 373 `_ is fixed, and ``flake8`` is updated, we suggest disabling this style check. Separately ``pyproject.toml`` is used for ``black`` configuration - if this file is found, the plugin will look at the following ``black`` settings: * ``target_version`` * ``skip_string_normalization`` * ``line_length`` You can specify a particular path for the ``pyproject.toml`` file (e.g. global development settings) using ``--black-config FILENAME`` at the command line, or using ``black-config = FILENAME`` in your ``flake8`` configuration file. Ignoring validation codes ------------------------- Using the flake8 no-quality-assurance pragma comment is not recommended (e.g. adding ``# noqa: BLK100`` to the first line black would change). Instead use the black pragma comments ``# fmt: off`` at the start, and ``# fmt: on`` at the end, of any region of your code which should not be changed. Or, add ``# fmt: skip`` to single lines. Or, exclude the entire file by name (see below). Ignoring files -------------- The plugin does *NOT* currently consider the ``black`` settings ``include`` and ``exclude``, so if you have certain Python files which you do not use with ``black`` and have told it to ignore, you will *also* need to tell ``flake8`` to ignore them (e.g. using ``exclude`` or ``per-file-ignores``). Version History --------------- ======= ============ =========================================================== Version Release date Changes ------- ------------ ----------------------------------------------------------- v0.3.6 2022-12-13 - Use standard library ``tomllib`` on Python 3.11 onwards, contribution from `Ganden Schaffner `_. v0.3.5 2022-11-21 - Fix regression clashing with ``flake8-rst-docstrings``. v0.3.4 2022-11-17 - Replaces ``setup.py`` with ``pyproject.toml`` for build. v0.3.3 2022-05-16 - Cope with line-length as string in pyproject.toml config. v0.3.2 2022-02-25 - Use ``tomli`` library to match black, contribution from `Brian Helba `_. - Adopted GitHub Actions to replace TravisCI testing. - Python 3.7 or later required. v0.3.0 2022-02-25 - Requires black v22.1.0 (first non-beta release) or later. - Support options "preview", "skip-magic-trailing-comma" in the black TOML file, contribution from `Ferdy `_. v0.2.4 2022-01-30 - Support black v22.1.0 which changed a function call, contribution from `Raffaele Salmaso `_. v0.2.3 2021-07-16 - Made ``toml`` dependency explicit in ``setup.py``. v0.2.2 2021-07-16 - Declared ``toml`` dependency (for black 21.7b0). v0.2.1 2020-07-25 - Detect ``*.pyi`` files via extension. v0.2.0 2020-05-20 - Minimum requirement on black 19.3b0 or later is now implicit. This is a workaround for `pipenv issue 3928 `_. Upgrade black if running flake8 gives an error like this: ``Flake8 failed to load plugin "BLK" due to __call__() got an unexpected keyword argument 'target_versions'.`` v0.1.2 2020-05-18 - Removed test broken by flake8 v3.8 change to resolve configuration files relative to current directory. v0.1.1 2019-08-26 - Option to use a (global) black configuration file, contribution from `Tomasz Grining `_. - New ``BLK997`` if can't parse ``pyproject.toml`` file. - Logs configuration files, use ``-v`` or ``--verbose``. - Fixed flake8 "builtins" parameter warning. - Now requires black 19.3b0 or later. v0.1.0 2019-06-03 - Uses main black settings from ``pyproject.toml``, contribution from `Alex `_. - WARNING: Now ignores flake8 ``max-line-length`` setting. v0.0.4 2019-03-15 - Supports black 19.3b0 which changed a function call. v0.0.3 2019-02-21 - Bug fix when ``W292 no newline at end of file`` applies, contribution from `Sapphire Becker `_. v0.0.2 2019-02-15 - Document syntax error behaviour (no BLK error reported). v0.0.1 2019-01-10 - Initial public release. - Passes flake8 ``max-line-length`` setting to black. ======= ============ =========================================================== Developers ---------- This plugin is on GitHub at https://github.com/peterjc/flake8-black Developers may install the plugin from the git repository with optional build dependencies:: $ pip install -e .[develop] To make a new release once tested locally and online:: $ git tag vX.Y.Z $ python -m build $ git push origin master --tags $ twine upload dist/flake8?black-X.Y.Z* The PyPI upload should trigger an automated pull request updating the `flake8-black conda-forge recipe `_. flake8-black-0.3.6/flake8_black.py000066400000000000000000000213301434606624400166340ustar00rootroot00000000000000"""Check Python code passes black style validation via flake8. This is a plugin for the tool flake8 tool for checking Python source code using the tool black. """ import sys from os import path from pathlib import Path if sys.version_info >= (3, 11): import tomllib else: import tomli as tomllib import black from flake8 import utils as stdin_utils from flake8 import LOG __version__ = "0.3.6" black_prefix = "BLK" def find_diff_start(old_src, new_src): """Find line number and column number where text first differs.""" old_lines = old_src.split("\n") new_lines = new_src.split("\n") for line in range(min(len(old_lines), len(new_lines))): old = old_lines[line] new = new_lines[line] if old == new: continue for col in range(min(len(old), len(new))): if old[col] != new[col]: return line, col # Difference at the end of the line... return line, min(len(old), len(new)) # Difference at the end of the file... return min(len(old_lines), len(new_lines)), 0 class BadBlackConfig(ValueError): """Bad black TOML configuration file.""" pass def load_black_mode(toml_filename=None): """Load a black configuration TOML file (or return defaults) as FileMode.""" if not toml_filename: return black.FileMode( target_versions=set(), line_length=black.DEFAULT_LINE_LENGTH, # Expect to be 88 string_normalization=True, magic_trailing_comma=True, preview=False, ) LOG.info("flake8-black: loading black settings from %s", toml_filename) try: with toml_filename.open(mode="rb") as toml_file: pyproject_toml = tomllib.load(toml_file) except ValueError: LOG.info("flake8-black: invalid TOML file %s", toml_filename) raise BadBlackConfig(path.relpath(toml_filename)) config = pyproject_toml.get("tool", {}).get("black", {}) black_config = {k.replace("--", "").replace("-", "_"): v for k, v in config.items()} # Extract the fields we care about, # cast to int explicitly otherwise line length could be a string return black.FileMode( target_versions={ black.TargetVersion[val.upper()] for val in black_config.get("target_version", []) }, line_length=int(black_config.get("line_length", black.DEFAULT_LINE_LENGTH)), string_normalization=not black_config.get("skip_string_normalization", False), magic_trailing_comma=not black_config.get("skip_magic_trailing_comma", False), preview=bool(black_config.get("preview", False)), ) black_config = {None: load_black_mode()} # None key's value is default config class BlackStyleChecker: """Checker of Python code using black.""" name = "black" version = __version__ override_config = None STDIN_NAMES = {"stdin", "-", "(none)", None} def __init__(self, tree, filename="(none)"): """Initialise.""" self.tree = tree self.filename = filename @property def _file_mode(self): """Return black.FileMode object, using local pyproject.toml as needed.""" if self.override_config: return self.override_config # Unless using override, we look for pyproject.toml project_root = black.find_project_root( ("." if self.filename in self.STDIN_NAMES else self.filename,) ) if isinstance(project_root, tuple): # black stable 22.1.0 update find_project_root return value # from Path to Tuple[Path, str] project_root = project_root[0] path = project_root / "pyproject.toml" if path in black_config: # Already loaded LOG.debug("flake8-black: %s using pre-loaded %s", self.filename, path) return black_config[path] elif path.is_file(): # Use this pyproject.toml for this python file, # (unless configured with global override config) # This should be thread safe - does not matter even if # two workers load and cache this file at the same time black_config[path] = load_black_mode(path) LOG.debug("flake8-black: %s using newly loaded %s", self.filename, path) return black_config[path] else: # No project specific file, use default LOG.debug("flake8-black: %s using defaults", self.filename) return black_config[None] @classmethod def add_options(cls, parser): """Adding black-config option.""" parser.add_option( "--black-config", metavar="TOML_FILENAME", default=None, action="store", # type="string", <- breaks using None as a sentinel # normalize_paths=True, <- broken and breaks None as a sentinel # https://gitlab.com/pycqa/flake8/issues/562 # https://gitlab.com/pycqa/flake8/merge_requests/337 parse_from_config=True, help="Path to black TOML configuration file (overrides the " "default 'pyproject.toml' detection; use empty string '' to mean " "ignore all 'pyproject.toml' files).", ) @classmethod def parse_options(cls, optmanager, options, extra_args): """Adding black-config option.""" # We have one and only one flake8 plugin configuration if options.black_config is None: LOG.info("flake8-black: No black configuration set") cls.override_config = None return elif not options.black_config: LOG.info("flake8-black: Explicitly using no black configuration file") cls.override_config = black_config[None] # explicitly use defaults return # Validate the path setting - handling relative paths ourselves, # see https://gitlab.com/pycqa/flake8/issues/562 black_config_path = Path(options.black_config) if options.config: # Assume black config path was via flake8 config file base_path = Path(path.dirname(path.abspath(options.config))) black_config_path = base_path / black_config_path if not black_config_path.is_file(): # Want flake8 to abort, see: # https://gitlab.com/pycqa/flake8/issues/559 raise ValueError( "Plugin flake8-black could not find specified black config file: " "--black-config %s" % black_config_path ) # Now load the TOML file, and the black section within it # This configuration is to override any local pyproject.toml try: cls.override_config = black_config[black_config_path] = load_black_mode( black_config_path ) except BadBlackConfig: # Could raise BLK997, but view this as an abort condition raise ValueError( "Plugin flake8-black could not parse specified black config file: " "--black-config %s" % black_config_path ) def run(self): """Use black to check code style.""" msg = None line = 0 col = 0 try: if self.filename in self.STDIN_NAMES: self.filename = "stdin" source = stdin_utils.stdin_get_value() else: with open(self.filename, "rb") as buf: source, _, _ = black.decode_bytes(buf.read()) except Exception as e: source = "" msg = "900 Failed to load file: %s" % e if not source and not msg: # Empty file (good) return elif source: # Call black... try: file_mode = self._file_mode file_mode.is_pyi = self.filename and self.filename.endswith(".pyi") new_code = black.format_file_contents( source, mode=file_mode, fast=False ) except black.NothingChanged: return except black.InvalidInput: msg = "901 Invalid input." except BadBlackConfig as err: msg = "997 Invalid TOML file: %s" % err except Exception as err: msg = "999 Unexpected exception: %r" % err else: assert ( new_code != source ), "Black made changes without raising NothingChanged" line, col = find_diff_start(source, new_code) line += 1 # Strange as col seems to be zero based? msg = "100 Black would make changes." # If we don't know the line or column numbers, leaving as zero. yield line, col, black_prefix + msg, type(self) flake8-black-0.3.6/pyproject.toml000066400000000000000000000030111434606624400166640ustar00rootroot00000000000000[build-system] requires = ['pip>=21.3', 'setuptools>=61', 'wheel'] build-backend = 'setuptools.build_meta' [project] name = 'flake8-black' description = 'flake8 plugin to call black as a code style validator' keywords = ['black', 'formatting', 'style', 'flake8'] license = {text = 'MIT'} readme = 'README.rst' authors = [ {name = 'Peter J. A. Cock'} ] maintainers = [ {name = 'Peter J. A. Cock', email = 'p.j.a.cock@googlemail.com'} ] classifiers = [ 'Intended Audience :: Developers', 'Framework :: Flake8', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Quality Assurance', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only' ] requires-python = '>=3.7' dependencies = [ 'flake8>=3', 'black>=22.1.0', 'tomli ; python_version < "3.11"', ] dynamic = ['version'] [project.entry-points] 'flake8.extension' = {BLK = 'flake8_black:BlackStyleChecker'} [project.optional-dependencies] develop = ['build', 'twine'] [project.urls] Homepage = 'https://github.com/peterjc/flake8-black' 'Source Code' = 'https://github.com/peterjc/flake8-black/' 'Bug Tracker' = 'https://github.com/peterjc/flake8-black/issues' Documentation = 'https://github.com/peterjc/flake8-black/blob/master/README.rst' [tool.setuptools] py-modules = ['flake8_black'] zip-safe = true [tool.setuptools.dynamic] version = {attr = 'flake8_black.__version__'} flake8-black-0.3.6/requirements.txt000066400000000000000000000003151434606624400172400ustar00rootroot00000000000000# This is a plugin for flake8, so we require that. # Our prefix is not single letter, so we need v3: flake8 >= 3.0.0 # We need black, which in turn needs Python 3.6+ black tomli ; python_version < "3.11" flake8-black-0.3.6/tests/000077500000000000000000000000001434606624400151175ustar00rootroot00000000000000flake8-black-0.3.6/tests/conflicting_configurations/000077500000000000000000000000001434606624400225305ustar00rootroot00000000000000flake8-black-0.3.6/tests/conflicting_configurations/.flake8000066400000000000000000000003471434606624400237070ustar00rootroot00000000000000[flake8] # Plugin flake8-black will pass this value to black max-line-length = 120 extend-ignore = # See https://github.com/PyCQA/pycodestyle/issues/373 # flake8/pycodechecker give false positives on black code E203, flake8-black-0.3.6/tests/conflicting_configurations/goodbye.py000066400000000000000000000001351434606624400245310ustar00rootroot00000000000000"""Print 'Au revoir' to the terminal. This is a simple test script. """ print("Au revoir") flake8-black-0.3.6/tests/conflicting_configurations/hello.py000077500000000000000000000003001434606624400242010ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. """ print("Hello world") flake8-black-0.3.6/tests/conflicting_configurations/pyproject.toml000066400000000000000000000000361434606624400254430ustar00rootroot00000000000000[tool.black] line-length = 90 flake8-black-0.3.6/tests/non_conflicting_configurations/000077500000000000000000000000001434606624400234025ustar00rootroot00000000000000flake8-black-0.3.6/tests/non_conflicting_configurations/.flake8000066400000000000000000000003471434606624400245610ustar00rootroot00000000000000[flake8] # Plugin flake8-black will pass this value to black max-line-length = 120 extend-ignore = # See https://github.com/PyCQA/pycodestyle/issues/373 # flake8/pycodechecker give false positives on black code E203, flake8-black-0.3.6/tests/non_conflicting_configurations/hello.py000077500000000000000000000003001434606624400250530ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. """ print("Hello world") flake8-black-0.3.6/tests/non_conflicting_configurations/pyproject.toml000066400000000000000000000000371434606624400263160ustar00rootroot00000000000000[tool.black] line-length = 120 flake8-black-0.3.6/tests/run_tests.sh000077500000000000000000000052641434606624400175130ustar00rootroot00000000000000#!/bin/bash set -euo pipefail IFS=$'\n\t' # Assumes in the tests/ directory echo "Checking our configuration option appears in help" flake8 -h 2>&1 | grep "black-config" set +o pipefail echo "Checking we report an error when can't find specified config file" flake8 --black-config does_not_exist.toml 2>&1 | grep -i "could not find" echo "Checking failure with mal-formed TOML file" flake8 --select BLK test_cases/ --black-config with_bad_toml/pyproject.toml 2>&1 | grep -i "could not parse" set -o pipefail echo "Checking we report no errors on these test cases" # Must explicitly include *.pyi or flake8 ignores them flake8 --select BLK test_cases/*.py* # Adding --black-config '' meaning ignore any pyproject.toml should have no effect: flake8 --select BLK test_cases/*.py --black-config '' flake8 --select BLK --max-line-length 50 test_cases/*.py flake8 --select BLK --max-line-length 90 test_cases/*.py flake8 --select BLK with_pyproject_toml/*.py flake8 --select BLK with_pyproject_toml/*.py --black-config with_pyproject_toml/pyproject.toml flake8 --select BLK --max-line-length 88 with_pyproject_toml/ flake8 --select BLK without_pyproject_toml/*.py --black-config with_pyproject_toml/pyproject.toml # Adding --black-config '' should have no effect: #flake8 --select BLK --max-line-length 88 with_pyproject_toml/ --black-config '' flake8 --select BLK non_conflicting_configurations/*.py flake8 --select BLK conflicting_configurations/*.py # Here using --black-config '' meaning ignore any (bad) pyproject.toml files: flake8 --select BLK with_bad_toml/hello_world.py --black-config '' echo "Checking we report expected black changes" diff test_changes/hello_world.txt <(flake8 --select BLK test_changes/hello_world.py) diff test_changes/hello_world_EOF.txt <(flake8 --select BLK test_changes/hello_world_EOF.py) diff test_changes/hello_world_EOF.txt <(flake8 --select BLK test_changes/hello_world_EOF.py --black-config '') diff <( if [ "${WIN:-1}" = 0 ]; then sed 's_/_\\_2' with_bad_toml/hello_world.txt else cat with_bad_toml/hello_world.txt fi ) <(flake8 --select BLK with_bad_toml/hello_world.py) diff with_pyproject_toml/ignoring_toml.txt <(flake8 with_pyproject_toml/ --select BLK --black-config '') # no changes by default, flake8 --select BLK test_changes/commas.py tests/black_preview.py # will make changes if we ignore the magic trailing comma: diff test_changes/commas.txt <(flake8 --select BLK test_changes/commas.py --black-config with_pyproject_toml/pyproject.toml) # will make changes if we enable future functionality preview mode: diff test_changes/black_preview.txt <(flake8 --select BLK test_changes/black_preview.py --black-config with_pyproject_toml/pyproject.toml) echo "Tests passed." flake8-black-0.3.6/tests/test_cases/000077500000000000000000000000001434606624400172545ustar00rootroot00000000000000flake8-black-0.3.6/tests/test_cases/hello_world.py000077500000000000000000000003001434606624400221340ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. """ print("Hello world") flake8-black-0.3.6/tests/test_cases/mixed_tab_spaces.py000066400000000000000000000004001434606624400231120ustar00rootroot00000000000000"""Invalid under Python 3, example with mixed indentation.""" if True: print("This line was indented with four spaces!") if True: print("This line was indented with eight spaces.") if True: print("This line was indented with a tab!") flake8-black-0.3.6/tests/test_cases/no_closing_bracket.py000077500000000000000000000016621434606624400234630ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal (with syntax error). This is a simple test script using a hashbang line and a PEP263 encoding line. There is a deliberate syntax error (missing closing bracket). Black will fail to parse this file: $ black --check no_closing_bracket.py ; echo "Return code $?" error: cannot format no_closing_bracket.py: ('EOF in multi-line statement', (31, 0)) All done! ð ð ð 1 file would fail to reformat. Return code 123 It seems in this case the plugin never gets the chance to report: $ flake8 --select BLK no_closing_bracket.py ; echo "Return code $?" Return code 0 This doesn't really matter, as it would be redundant with the flake8 syntax errors: $ flake8 no_closing_bracket.py ; echo "Return code $?" no_closing_bracket.py:30:19: E999 SyntaxError: unexpected EOF while parsing Return code 1 """ print("Hello world" flake8-black-0.3.6/tests/test_cases/stub.pyi000066400000000000000000000000521434606624400207510ustar00rootroot00000000000000def my_function(): ... class Wibble: ... flake8-black-0.3.6/tests/test_changes/000077500000000000000000000000001434606624400175665ustar00rootroot00000000000000flake8-black-0.3.6/tests/test_changes/black_preview.py000066400000000000000000000004641434606624400227610ustar00rootroot00000000000000"""Example showing future black string reformatting.""" def hello(): """Print variations on 'Hello World'.""" # black v22.1.0 (first stable release) does not edit string literals, # so the following is untouched unless enable preview mode: print("hello " "world") # noqa: ISC001 hello() flake8-black-0.3.6/tests/test_changes/black_preview.txt000066400000000000000000000001051434606624400231400ustar00rootroot00000000000000test_changes/black_preview.py:8:18: BLK100 Black would make changes. flake8-black-0.3.6/tests/test_changes/commas.py000066400000000000000000000007361434606624400214250ustar00rootroot00000000000000"""Example of black and magic commas.""" vegetables = { "carrot", "parsnip", "potato", "swede", "leak", "aubergine", "tomato", "peas", "beans", } # This set would easily fit on one line, but a trailing comma # after the final entry tells black (by default) to leave this # with one entry per line: yucky = { "aubergine", "squid", "snails", } print("I dislike these vegetables: %s." % ", ".join(vegetables.intersection(yucky))) flake8-black-0.3.6/tests/test_changes/commas.txt000066400000000000000000000000771434606624400216120ustar00rootroot00000000000000test_changes/commas.py:18:10: BLK100 Black would make changes. flake8-black-0.3.6/tests/test_changes/hello_world.py000077500000000000000000000004711434606624400224570ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. In the original format, there excess spaces in the print call, and unwanted blank lines - which black will remove. """ print ( "Hello world" ) flake8-black-0.3.6/tests/test_changes/hello_world.txt000066400000000000000000000001031434606624400226330ustar00rootroot00000000000000test_changes/hello_world.py:12:6: BLK100 Black would make changes. flake8-black-0.3.6/tests/test_changes/hello_world_EOF.py000066400000000000000000000004251434606624400231440ustar00rootroot00000000000000"""Print 'Hello world' to the terminal. This is a simple test script which in the formal form has a missing final line break - which black will add. The point of this is the edit position will be at the very end of the file, which is a corner case. """ print("Hello world")flake8-black-0.3.6/tests/test_changes/hello_world_EOF.txt000066400000000000000000000001071434606624400233300ustar00rootroot00000000000000test_changes/hello_world_EOF.py:12:1: BLK100 Black would make changes. flake8-black-0.3.6/tests/with_bad_toml/000077500000000000000000000000001434606624400177335ustar00rootroot00000000000000flake8-black-0.3.6/tests/with_bad_toml/hello_world.py000077500000000000000000000003001434606624400226130ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. """ print("Hello world") flake8-black-0.3.6/tests/with_bad_toml/hello_world.txt000066400000000000000000000001311434606624400230010ustar00rootroot00000000000000with_bad_toml/hello_world.py:0:1: BLK997 Invalid TOML file: with_bad_toml/pyproject.toml flake8-black-0.3.6/tests/with_bad_toml/pyproject.toml000066400000000000000000000001711434606624400226460ustar00rootroot00000000000000[tool.black] skip-string-normalization = true # This line is (a) in the wrong file, and (b) invalid syntax black-config= flake8-black-0.3.6/tests/with_pyproject_toml/000077500000000000000000000000001434606624400212245ustar00rootroot00000000000000flake8-black-0.3.6/tests/with_pyproject_toml/ignoring_toml.txt000066400000000000000000000001161434606624400246320ustar00rootroot00000000000000with_pyproject_toml/ordinary_quotes.py:10:7: BLK100 Black would make changes. flake8-black-0.3.6/tests/with_pyproject_toml/ordinary_quotes.py000077500000000000000000000003451434606624400250320ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. We use ordinary quotes in this test. """ print('Hello world') flake8-black-0.3.6/tests/with_pyproject_toml/pyproject.toml000066400000000000000000000003031434606624400241340ustar00rootroot00000000000000[tool.black] # This is probably better as an integer, # but reasonable to cope with it as str: line-length = "88" skip-string-normalization = true skip-magic-trailing-comma = true preview = true flake8-black-0.3.6/tests/without_pyproject_toml/000077500000000000000000000000001434606624400217545ustar00rootroot00000000000000flake8-black-0.3.6/tests/without_pyproject_toml/ordinary_quotes.py000077500000000000000000000003451434606624400255620ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Print 'Hello world' to the terminal. This is a simple test script using a hashbang line and a PEP263 encoding line. We use ordinary quotes in this test. """ print('Hello world')