[
  {
    "path": ".flake8",
    "content": "[flake8]\n\n# Recommend matching the black line length (default 88),\n# rather than using the flake8 default of 79:\nmax-line-length = 88\n\nextend-ignore =\n    # See https://github.com/PyCQA/pycodestyle/issues/373\n    # flake8/pycodechecker give false positives on black code\n    E203,\n\n# Most of our test cases deliberately violate style checks:\nper-file-ignores =\n    # These are meant to trigger black changes:\n    tests/test_changes/hello_world.py: E201,E202,E211,W391,BLK100\n    tests/test_changes/hello_world_EOF.py: W292,BLK100\n    tests/without_pyproject_toml/ordinary_quotes.py: Q000,BLK100\n    # These are not meant to trigger black changes:\n    tests/test_cases/no_closing_bracket.py: E902\n    tests/test_fail/mixed_tab_spaces.py: E101,E999,W191\n    tests/with_pyproject_toml/ordinary_quotes.py: Q000\n    tests/test_cases/mixed_tab_spaces.py: E101,E999,W191\n    # The bad TOML file breaks black checking this file:\n    tests/with_bad_toml/hello_world.py: BLK997,\n\n# =====================\n# flake-quote settings:\n# =====================\n# Set this to match black style:\ninline-quotes = double\n"
  },
  {
    "path": ".github/workflows/test.yml",
    "content": "name: test\n\non: [push, pull_request]\n\njobs:\n  run-tests:\n    runs-on: ${{ matrix.os }}\n    defaults:\n      run:\n        shell: bash\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [windows-latest, macos-latest, ubuntu-latest]\n        python-version: [\"3.9\", \"3.10\", \"3.11\", \"3.12\", \"3.13\"]\n        black-version: [\"23.9.1\", \"25.9.0\"]\n    steps:\n    - uses: actions/checkout@v2\n    - name: Set up Python ${{ matrix.python-version }}\n      uses: actions/setup-python@v2\n      with:\n        python-version: ${{ matrix.python-version }}\n    - name: Git configuration\n      run: |\n        git config core.autocrlf false\n        git reset --hard\n    - name: Build packages, and install the wheel\n      run: |\n        pip install build black==${{ matrix.black-version }}\n        python -m build\n        cd dist\n        python -m pip install flake8_black-*.whl\n        cd ..\n        # Wheel should now be installed\n        flake8 --version\n    - name: Run tests\n      run: |\n        # Unpack the tests from the sdist tar-ball\n        # (want to confirm the manifest was complete)\n        tar -zxvf dist/flake8_black-*.tar.gz\n        cd flake8_black-*/tests/\n        WIN=\"$([ \"$RUNNER_OS\" == \"Windows\" ];echo $?)\" bash ./run_tests.sh\n"
  },
  {
    "path": ".gitignore",
    "content": "#Ignore the build directory (and its sub-directories):\nbuild\n\n#Ignore the distribution directory\ndist\n\n#Ignore another Python specific build folder:\nflake8_black.egg-info/\n \n#Ignore backup files from some Unix editors,\n*~\n*.swp\n*.bak\n\n#Ignore patches and any original files created by patch command\n*.diff\n*.orig\n*.rej\n\n#Ignore these hidden files from Mac OS X\n.DS_Store\n\n#Ignore hidden files from Dolphin window manager\n.directory\n"
  },
  {
    "path": ".pre-commit-config.yaml",
    "content": "# pre-commit run --all-files\nrepos:\n-   repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v6.0.0\n    hooks:\n    -   id: check-added-large-files\n    -   id: check-case-conflict\n    -   id: check-executables-have-shebangs\n    -   id: check-merge-conflict\n    -   id: check-shebang-scripts-are-executable\n    -   id: check-symlinks\n    -   id: check-yaml\n    -   id: debug-statements\n        exclude: tests/\n    -   id: destroyed-symlinks\n    -   id: end-of-file-fixer\n        exclude: tests/test_changes/\n        files: \\.(py|sh|rst|yml|yaml)$\n    -   id: mixed-line-ending\n    -   id: trailing-whitespace\n        files: \\.(py|sh|rst|yml|yaml)$\n-   repo: https://github.com/psf/black-pre-commit-mirror\n    rev: 26.3.1\n    hooks:\n    -   id: black\n        exclude: tests/\n        args: [--check]\n-   repo: https://github.com/PyCQA/flake8\n    rev: 7.3.0\n    hooks:\n    -   id: flake8\n        additional_dependencies: [\n            'flake8-blind-except',\n            'flake8-docstrings',\n            'flake8-bugbear',\n            'flake8-comprehensions',\n            'flake8-docstrings',\n            'flake8-implicit-str-concat',\n            'pydocstyle>=5.0.0',\n        ]\n        exclude: ^tests/test_cases/no_closing_bracket\\.py$\n-   repo: https://github.com/asottile/blacken-docs\n    rev: 1.20.0\n    hooks:\n    -   id: blacken-docs\n        additional_dependencies: [black==24.8.0]\n        exclude: ^.github/\n-   repo: https://github.com/rstcheck/rstcheck\n    rev: v6.2.5\n    hooks:\n    -   id: rstcheck\n        args: [\n            --report-level=warning,\n        ]\n-   repo: https://github.com/codespell-project/codespell\n    rev: v2.4.2\n    hooks:\n    -   id: codespell\n        files: \\.(py|sh|rst|yml|yaml)$\nci:\n    # Settings for the https://pre-commit.ci/ continuous integration service\n    autofix_prs: true\n    # Default message is more verbose\n    autoupdate_commit_msg: '[pre-commit.ci] autoupdate'\n    # Default is weekly\n    autoupdate_schedule: monthly\n"
  },
  {
    "path": "LICENSE.rst",
    "content": "Copyright 2019, Peter Cock, The James Hutton Institute, UK.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "MANIFEST.in",
    "content": "include README.rst\ninclude LICENSE.rst\ninclude requirements.txt\nrecursive-include tests *.py *.txt *.sh *.toml\n"
  },
  {
    "path": "README.rst",
    "content": "flake8-black\n============\n\n.. image:: https://img.shields.io/pypi/v/flake8-black.svg\n   :alt: Released on the Python Package Index (PyPI)\n   :target: https://pypi.org/project/flake8-black/\n.. image:: https://img.shields.io/conda/vn/conda-forge/flake8-black.svg\n   :alt: Released on Conda\n   :target: https://anaconda.org/conda-forge/flake8-black\n.. image:: https://results.pre-commit.ci/badge/github/peterjc/flake8-black/master.svg\n   :target: https://results.pre-commit.ci/latest/github/peterjc/flake8-black/master\n   :alt: pre-commit.ci status\n.. image:: https://img.shields.io/github/actions/workflow/status/peterjc/flake8-black/test.yml?logo=github-actions\n   :alt: GitHub workflow status\n   :target: https://github.com/peterjc/flake8-black/actions\n.. image:: https://img.shields.io/pypi/dm/flake8-black.svg\n   :alt: PyPI downloads\n   :target: https://pypistats.org/packages/flake8-black\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :alt: Code style: black\n   :target: https://github.com/python/black\n\nIntroduction\n------------\n\nThis is an MIT licensed `flake8 <https://github.com/pycqa/flake8>`_ plugin\nfor validating Python code style with the command line code formatting tool\n`black <https://github.com/python/black>`_. It is available to install from\nthe `Python Package Index (PyPI) <https://pypi.org/project/flake8-black/>`_.\n\nBlack, *\"The Uncompromising Code Formatter\"*, is normally run to edit your\nPython code in place to match their coding style, a strict subset of the\n`PEP 8 style guide <https://www.python.org/dev/peps/pep-0008/>`_.\n\nThe point of this plugin is to be able to run ``black --check ...`` from\nwithin the ``flake8`` plugin ecosystem. You might use this via a ``git``\npre-commit hook, or as part of your continuous integration testing.\n\nIf you are using `pre-commit <https://pre-commit.com/>`_ configure it to call\nblack and/or flake8 directly - you do not need flake8-black at all.\n\nFlake8 Validation codes\n-----------------------\n\nEarly versions of flake8 assumed a single character prefix for the validation\ncodes, which became problematic with collisions in the plugin ecosystem. Since\nv3.0, flake8 has supported longer prefixes, therefore this plugin uses ``BLK``\nas its prefix.\n\n====== =======================================================================\nCode   Description (*and notes*)\n------ -----------------------------------------------------------------------\nBLK100 Black would make changes.\nBLK9## Internal error (*various, listed below*):\nBLK900 Failed to load file: ...\nBLK901 Invalid input.\nBLK997 Invalid TOML file: ...\nBLK998 Could not access flake8 line length setting (*no longer used*).\nBLK999 Unexpected exception.\n====== =======================================================================\n\nNote that if your Python code has a syntax error, ``black --check ...`` would\nreport this as an error. Likewise ``flake8 ...`` will by default report the\nsyntax error, but importantly it does not seem to then call the plugins, so\nyou will *not* get an additional ``BLK`` error.\n\n\nInstallation\n------------\n\nPython 3.9 or later is required, but ``black`` can be used on Python code\nwritten for older versions of Python.\n\nYou can install ``flake8-black`` using ``pip``, which should install ``flake8``\nand ``black`` as well if not already present::\n\n    $ pip install flake8-black\n\nAlternatively, if you are using the Anaconda packaging system, the following\ncommand will install the plugin with its dependencies::\n\n    $ conda install -c conda-forge flake8-black\n\nThe new validator should be automatically included when using ``flake8`` which\nmay now report additional validation codes starting with ``BLK`` (as defined\nabove). For example::\n\n    $ flake8 example.py\n\nYou can request only the ``BLK`` codes be shown using::\n\n    $ flake8 --select BLK example.py\n\nPython package management\n-------------------------\n\nFor large projects especially, you should consider pinning the exact\nversion of black you want to use as their updates do sometimes introduce\nchanges which would show up as new ``BLK100`` violations via flake8.\n\nYou should be able to specify your black version in your conda or pip\nrequirements or environment, or using using pipenv or poetry etc.\n\nConfiguration\n-------------\n\nWe assume you are familiar with `flake8 configuration\n<http://flake8.pycqa.org/en/latest/user/configuration.html>`_ and\n`black configuration\n<https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file>`_.\n\nWe recommend using the following settings in your ``flake8`` configuration,\nfor example in your ``.flake8``, ``setup.cfg``, or ``tox.ini`` file::\n\n    [flake8]\n    # Recommend matching the black line length (default 88),\n    # rather than using the flake8 default of 79:\n    max-line-length = 88\n    extend-ignore =\n        # See https://github.com/PyCQA/pycodestyle/issues/373\n        E203,\n\nNote currently ``pycodestyle`` gives false positives on the spaces ``black``\nuses for slices, which ``flake8`` reports as ``E203: whitespace before ':'``.\nUntil `pyflakes issue 373 <https://github.com/PyCQA/pycodestyle/issues/373>`_\nis fixed, and ``flake8`` is updated, we suggest disabling this style check.\n\nSeparately ``pyproject.toml`` is used for ``black`` configuration - if this\nfile is found, the plugin will look at the following ``black`` settings:\n\n* ``target_version``\n* ``skip_string_normalization``\n* ``line_length``\n\nYou can specify a particular path for the ``pyproject.toml`` file (e.g.\nglobal development settings) using ``--black-config FILENAME`` at the\ncommand line, or using ``black-config = FILENAME`` in your ``flake8``\nconfiguration file.\n\nIgnoring validation codes\n-------------------------\n\nUsing the flake8 no-quality-assurance pragma comment is not recommended (e.g.\nadding ``# noqa: BLK100`` to the first line black would change). Instead use\nthe black pragma comments ``# fmt: off`` at the start, and ``# fmt: on`` at\nthe end, of any region of your code which should not be changed. Or, add\n``# fmt: skip`` to single lines. Or, exclude the entire file by name (see\nbelow).\n\nIgnoring files\n--------------\n\nThe plugin does *NOT* currently consider the ``black`` settings ``include``\nand ``exclude``, so if you have certain Python files which you do not use\nwith ``black`` and have told it to ignore, you will *also* need to tell\n``flake8`` to ignore them (e.g. using ``exclude`` or ``per-file-ignores``).\n\n\nVersion History\n---------------\n\n======= ============ ===========================================================\nVersion Release date Changes\n------- ------------ -----------------------------------------------------------\nv0.4.0  *Pending*    - Now tested on Python 3.9 through 3.13, and black 23.9.1\n                       (as before) and black 25.9.0 (current latest).\n                     - Support the API change in ``decode_bytes`` in black 25.9.0.\n                     - Error ``BLK997`` does not have the bad TOML filename.\nv0.3.7  2025-09-19   - Now tested on Python 3.8 though 3.13.\n                     - Using ``black.Mode`` class name in place of legacy alias\n                       ``black.FileMode`` from beta release era.\n                     - Does not work on black 25.9.0 onwards.\nv0.3.6  2022-12-13   - Use standard library ``tomllib`` on Python 3.11 onwards,\n                       contribution from\n                       `Ganden Schaffner <https://github.com/gschaffner>`_.\nv0.3.5  2022-11-21   - Fix regression clashing with ``flake8-rst-docstrings``.\nv0.3.4  2022-11-17   - Replaces ``setup.py`` with ``pyproject.toml`` for build.\nv0.3.3  2022-05-16   - Cope with line-length as string in pyproject.toml config.\nv0.3.2  2022-02-25   - Use ``tomli`` library to match black, contribution from\n                       `Brian Helba <https://github.com/brianhelba>`_.\n                     - Adopted GitHub Actions to replace TravisCI testing.\n                     - Python 3.7 or later required.\nv0.3.0  2022-02-25   - Requires black v22.1.0 (first non-beta release) or later.\n                     - Support options \"preview\", \"skip-magic-trailing-comma\"\n                       in the black TOML file, contribution from\n                       `Ferdy <https://github.com/ferdynice>`_.\nv0.2.4  2022-01-30   - Support black v22.1.0 which changed a function call,\n                       contribution from\n                       `Raffaele Salmaso <https://github.com/rsalmaso>`_.\nv0.2.3  2021-07-16   - Made ``toml`` dependency explicit in ``setup.py``.\nv0.2.2  2021-07-16   - Declared ``toml`` dependency (for black 21.7b0).\nv0.2.1  2020-07-25   - Detect ``*.pyi`` files via extension.\nv0.2.0  2020-05-20   - Minimum requirement on black 19.3b0 or later is now\n                       implicit. This is a workaround for `pipenv issue 3928\n                       <https://github.com/pypa/pipenv/issues/3928>`_. Upgrade\n                       black if running flake8 gives an error like this:\n                       ``Flake8 failed to load plugin \"BLK\" due to __call__()\n                       got an unexpected keyword argument 'target_versions'.``\nv0.1.2  2020-05-18   - Removed test broken by flake8 v3.8 change to resolve\n                       configuration files relative to current directory.\nv0.1.1  2019-08-26   - Option to use a (global) black configuration file,\n                       contribution from\n                       `Tomasz Grining <https://github.com/098799>`_.\n                     - New ``BLK997`` if can't parse ``pyproject.toml`` file.\n                     - Logs configuration files, use ``-v`` or ``--verbose``.\n                     - Fixed flake8 \"builtins\" parameter warning.\n                     - Now requires black 19.3b0 or later.\nv0.1.0  2019-06-03   - Uses main black settings from ``pyproject.toml``,\n                       contribution from `Alex <https://github.com/ADKosm>`_.\n                     - WARNING: Now ignores flake8 ``max-line-length`` setting.\nv0.0.4  2019-03-15   - Supports black 19.3b0 which changed a function call.\nv0.0.3  2019-02-21   - Bug fix when ``W292 no newline at end of file`` applies,\n                       contribution from\n                       `Sapphire Becker <https://github.com/sapphire-janrain>`_.\nv0.0.2  2019-02-15   - Document syntax error behaviour (no BLK error reported).\nv0.0.1  2019-01-10   - Initial public release.\n                     - Passes flake8 ``max-line-length`` setting to black.\n======= ============ ===========================================================\n\n\nDevelopers\n----------\n\nThis plugin is on GitHub at https://github.com/peterjc/flake8-black\n\nDevelopers may install the plugin from the git repository with optional build\ndependencies::\n\n    $ pip install -e .[develop]\n\nTo make a new release once tested locally and online::\n\n    $ git tag vX.Y.Z\n    $ python -m build\n    $ git push origin master --tags\n    $ twine upload dist/flake8?black-X.Y.Z*\n\nThe PyPI upload should trigger an automated pull request updating the\n`flake8-black conda-forge recipe\n<https://github.com/conda-forge/flake8-black-feedstock/blob/master/recipe/meta.yaml>`_.\n"
  },
  {
    "path": "flake8_black.py",
    "content": "\"\"\"Check Python code passes black style validation via flake8.\n\nThis is a plugin for the tool flake8 tool for checking Python\nsource code using the tool black.\n\"\"\"\n\nimport sys\nfrom os import path\nfrom pathlib import Path\n\nif sys.version_info >= (3, 11):\n    import tomllib\nelse:\n    import tomli as tomllib\n\nimport black\n\nfrom flake8 import utils as stdin_utils\nfrom flake8 import LOG\n\n__version__ = \"0.4.0\"\n\nblack_prefix = \"BLK\"\n\n\ntry:\n    black.decode_bytes(b\"\")\nexcept TypeError:\n    # TypeError: decode_bytes() missing required argument 'mode' (pos 2)\n    decode_bytes_wrapper = black.decode_bytes\nelse:\n    # Probably running older than black 25.9.0\n    def decode_bytes_wrapper(src, mode):\n        \"\"\"Proxy wrapper for backward compatibility.\"\"\"\n        return black.decode_bytes(src)\n\n\ndef find_diff_start(old_src, new_src):\n    \"\"\"Find line number and column number where text first differs.\"\"\"\n    old_lines = old_src.split(\"\\n\")\n    new_lines = new_src.split(\"\\n\")\n\n    for line in range(min(len(old_lines), len(new_lines))):\n        old = old_lines[line]\n        new = new_lines[line]\n        if old == new:\n            continue\n        for col in range(min(len(old), len(new))):\n            if old[col] != new[col]:\n                return line, col\n        # Difference at the end of the line...\n        return line, min(len(old), len(new))\n    # Difference at the end of the file...\n    return min(len(old_lines), len(new_lines)), 0\n\n\nclass BadBlackConfig(ValueError):\n    \"\"\"Bad black TOML configuration file.\"\"\"\n\n    pass\n\n\ndef load_black_mode(toml_filename=None):\n    \"\"\"Load black configuration TOML file (or return defaults) as black.Mode object.\"\"\"\n    if not toml_filename:\n        return black.FileMode(\n            target_versions=set(),\n            line_length=black.DEFAULT_LINE_LENGTH,  # Expect to be 88\n            string_normalization=True,\n            magic_trailing_comma=True,\n            preview=False,\n        )\n\n    LOG.info(\"flake8-black: loading black settings from %s\", toml_filename)\n    try:\n        with toml_filename.open(mode=\"rb\") as toml_file:\n            pyproject_toml = tomllib.load(toml_file)\n    except ValueError:\n        LOG.info(\"flake8-black: invalid TOML file %s\", toml_filename)\n        raise BadBlackConfig(path.relpath(toml_filename))\n    config = pyproject_toml.get(\"tool\", {}).get(\"black\", {})\n    black_config = {k.replace(\"--\", \"\").replace(\"-\", \"_\"): v for k, v in config.items()}\n\n    # Extract the fields we care about,\n    # cast to int explicitly otherwise line length could be a string\n    return black.Mode(\n        target_versions={\n            black.TargetVersion[val.upper()]\n            for val in black_config.get(\"target_version\", [])\n        },\n        line_length=int(black_config.get(\"line_length\", black.DEFAULT_LINE_LENGTH)),\n        string_normalization=not black_config.get(\"skip_string_normalization\", False),\n        magic_trailing_comma=not black_config.get(\"skip_magic_trailing_comma\", False),\n        preview=bool(black_config.get(\"preview\", False)),\n    )\n\n\nblack_config = {None: load_black_mode()}  # None key's value is default config\n\n\nclass BlackStyleChecker:\n    \"\"\"Checker of Python code using black.\"\"\"\n\n    name = \"black\"\n    version = __version__\n    override_config = None\n\n    STDIN_NAMES = {\"stdin\", \"-\", \"(none)\", None}\n\n    def __init__(self, tree, filename=\"(none)\"):\n        \"\"\"Initialise.\"\"\"\n        self.tree = tree\n        self.filename = filename\n\n    @property\n    def _file_mode(self):\n        \"\"\"Return black.FileMode object, using local pyproject.toml as needed.\"\"\"\n        if self.override_config:\n            return self.override_config\n\n        # Unless using override, we look for pyproject.toml\n        project_root = black.find_project_root(\n            (\".\" if self.filename in self.STDIN_NAMES else self.filename,)\n        )\n        if isinstance(project_root, tuple):\n            # black stable 22.1.0 update find_project_root return value\n            # from Path to Tuple[Path, str]\n            project_root = project_root[0]\n        path = project_root / \"pyproject.toml\"\n\n        if path in black_config:\n            # Already loaded\n            LOG.debug(\"flake8-black: %s using pre-loaded %s\", self.filename, path)\n            return black_config[path]\n        elif path.is_file():\n            # Use this pyproject.toml for this python file,\n            # (unless configured with global override config)\n            # This should be thread safe - does not matter even if\n            # two workers load and cache this file at the same time\n            black_config[path] = load_black_mode(path)\n            LOG.debug(\"flake8-black: %s using newly loaded %s\", self.filename, path)\n            return black_config[path]\n        else:\n            # No project specific file, use default\n            LOG.debug(\"flake8-black: %s using defaults\", self.filename)\n            return black_config[None]\n\n    @classmethod\n    def add_options(cls, parser):\n        \"\"\"Add black-config options.\"\"\"\n        parser.add_option(\n            \"--black-config\",\n            metavar=\"TOML_FILENAME\",\n            default=None,\n            action=\"store\",\n            # type=\"string\",  <- breaks using None as a sentinel\n            # normalize_paths=True,  <- broken and breaks None as a sentinel\n            # https://gitlab.com/pycqa/flake8/issues/562\n            # https://gitlab.com/pycqa/flake8/merge_requests/337\n            parse_from_config=True,\n            help=\"Path to black TOML configuration file (overrides the \"\n            \"default 'pyproject.toml' detection; use empty string '' to mean \"\n            \"ignore all 'pyproject.toml' files).\",\n        )\n\n    @classmethod\n    def parse_options(cls, optmanager, options, extra_args):\n        \"\"\"Parse black-config options.\"\"\"\n        # We have one and only one flake8 plugin configuration\n        if options.black_config is None:\n            LOG.info(\"flake8-black: No black configuration set\")\n            cls.override_config = None\n            return\n        elif not options.black_config:\n            LOG.info(\"flake8-black: Explicitly using no black configuration file\")\n            cls.override_config = black_config[None]  # explicitly use defaults\n            return\n\n        # Validate the path setting - handling relative paths ourselves,\n        # see https://gitlab.com/pycqa/flake8/issues/562\n        black_config_path = Path(options.black_config)\n        if options.config:\n            # Assume black config path was via flake8 config file\n            base_path = Path(path.dirname(path.abspath(options.config)))\n            black_config_path = base_path / black_config_path\n        if not black_config_path.is_file():\n            # Want flake8 to abort, see:\n            # https://gitlab.com/pycqa/flake8/issues/559\n            raise ValueError(\n                \"Plugin flake8-black could not find specified black config file: \"\n                \"--black-config %s\" % black_config_path\n            )\n\n        # Now load the TOML file, and the black section within it\n        # This configuration is to override any local pyproject.toml\n        try:\n            cls.override_config = black_config[black_config_path] = load_black_mode(\n                black_config_path\n            )\n        except BadBlackConfig:\n            # Could raise BLK997, but view this as an abort condition\n            raise ValueError(\n                \"Plugin flake8-black could not parse specified black config file: \"\n                \"--black-config %s\" % black_config_path\n            )\n\n    def run(self):\n        \"\"\"Use black to check code style.\"\"\"\n        msg = None\n        line = 0\n        col = 0\n\n        try:\n            if self.filename in self.STDIN_NAMES:\n                self.filename = \"stdin\"\n                raw_source = stdin_utils.stdin_get_value().encode(\"utf-8\")\n            else:\n                with open(self.filename, \"rb\") as buf:\n                    raw_source = buf.read()\n        except Exception as e:\n            raw_source = \"\"\n            msg = \"900 Failed to load file: %s\" % e\n\n        if not raw_source and not msg:\n            # Empty file (good)\n            return\n        elif raw_source:\n            # Call black...\n            try:\n                file_mode = self._file_mode\n                file_mode.is_pyi = self.filename and self.filename.endswith(\".pyi\")\n                source, _, _ = decode_bytes_wrapper(raw_source, file_mode)\n                new_code = black.format_file_contents(\n                    source, mode=file_mode, fast=False\n                )\n            except black.NothingChanged:\n                return\n            except black.InvalidInput:\n                msg = \"901 Invalid input.\"\n            except (BadBlackConfig, tomllib.TOMLDecodeError):\n                # Seems in black 25.9.0 the TOMLDecodeError is triggered while\n                # finding project root, not trivial to get the path\n                msg = \"997 Invalid TOML file\"\n            except Exception as err:\n                msg = \"999 Unexpected exception: %r\" % err\n            else:\n                assert (\n                    new_code != source\n                ), \"Black made changes without raising NothingChanged\"\n                line, col = find_diff_start(source, new_code)\n                line += 1  # Strange as col seems to be zero based?\n                msg = \"100 Black would make changes.\"\n        # If we don't know the line or column numbers, leaving as zero.\n        yield line, col, black_prefix + msg, type(self)\n"
  },
  {
    "path": "pyproject.toml",
    "content": "[build-system]\nrequires = ['pip>=21.3', 'setuptools>=61', 'wheel']\nbuild-backend = 'setuptools.build_meta'\n\n[project]\nname = 'flake8-black'\ndescription = 'flake8 plugin to call black as a code style validator'\nkeywords = ['black', 'formatting', 'style', 'flake8']\nlicense = {text = 'MIT'}\nreadme = 'README.rst'\nauthors = [\n  {name = 'Peter J. A. Cock'}\n]\nmaintainers = [\n  {name = 'Peter J. A. Cock', email = 'p.j.a.cock@googlemail.com'}\n]\nclassifiers = [\n  'Intended Audience :: Developers',\n  'Framework :: Flake8',\n  'License :: OSI Approved :: MIT License',\n  'Operating System :: OS Independent',\n  'Topic :: Software Development :: Libraries :: Python Modules',\n  'Topic :: Software Development :: Quality Assurance',\n  'Programming Language :: Python',\n  'Programming Language :: Python :: 3',\n  'Programming Language :: Python :: 3 :: Only'\n]\nrequires-python = '>=3.9'\ndependencies = [\n  'flake8>=3',\n  'black>=22.1.0',\n  'tomli ; python_version < \"3.11\"',\n]\ndynamic = ['version']\n[project.entry-points]\n'flake8.extension' = {BLK = 'flake8_black:BlackStyleChecker'}\n[project.optional-dependencies]\ndevelop = ['build', 'twine']\n[project.urls]\nHomepage = 'https://github.com/peterjc/flake8-black'\n'Source Code' = 'https://github.com/peterjc/flake8-black/'\n'Bug Tracker' = 'https://github.com/peterjc/flake8-black/issues'\nDocumentation = 'https://github.com/peterjc/flake8-black/blob/master/README.rst'\n\n[tool.setuptools]\npy-modules = ['flake8_black']\nzip-safe = true\n[tool.setuptools.dynamic]\nversion = {attr = 'flake8_black.__version__'}\n"
  },
  {
    "path": "requirements.txt",
    "content": "# This is a plugin for flake8, so we require that.\n# Our prefix is not single letter, so we need v3:\nflake8 >= 3.0.0\n\n# We need black\nblack >= 22.1.0\ntomli ; python_version < \"3.11\"\n"
  },
  {
    "path": "tests/conflicting_configurations/.flake8",
    "content": "[flake8]\n\n# Plugin flake8-black will pass this value to black\nmax-line-length = 120\n\nextend-ignore =\n    # See https://github.com/PyCQA/pycodestyle/issues/373\n    # flake8/pycodechecker give false positives on black code\n    E203,\n"
  },
  {
    "path": "tests/conflicting_configurations/goodbye.py",
    "content": "\"\"\"Print 'Au revoir' to the terminal.\n\nThis is a simple test script.\n\"\"\"\n\nprint(\"Au revoir\")\n"
  },
  {
    "path": "tests/conflicting_configurations/hello.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line\nand a PEP263 encoding line.\n\"\"\"\n\nprint(\"Hello world\")\n"
  },
  {
    "path": "tests/conflicting_configurations/pyproject.toml",
    "content": "[tool.black]\nline-length = 90\n"
  },
  {
    "path": "tests/non_conflicting_configurations/.flake8",
    "content": "[flake8]\n\n# Plugin flake8-black will pass this value to black\nmax-line-length = 120\n\nextend-ignore =\n    # See https://github.com/PyCQA/pycodestyle/issues/373\n    # flake8/pycodechecker give false positives on black code\n    E203,\n"
  },
  {
    "path": "tests/non_conflicting_configurations/hello.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line\nand a PEP263 encoding line.\n\"\"\"\n\nprint(\"Hello world\")\n"
  },
  {
    "path": "tests/non_conflicting_configurations/pyproject.toml",
    "content": "[tool.black]\nline-length = 120\n"
  },
  {
    "path": "tests/run_tests.sh",
    "content": "#!/bin/bash\nset -euo pipefail\nIFS=$'\\n\\t'\n\n# Assumes in the tests/ directory\n\necho \"Checking our configuration option appears in help\"\nflake8 -h 2>&1 | grep \"black-config\"\n\nset +o pipefail\n\necho \"Checking we report an error when can't find specified config file\"\nflake8 --black-config does_not_exist.toml 2>&1 | grep -i \"could not find\"\n\necho \"Checking failure with mal-formed TOML file\"\nflake8 --select BLK test_cases/ --black-config with_bad_toml/pyproject.toml 2>&1 | grep -i \"could not parse\"\n\nset -o pipefail\n\necho \"Checking we report no errors on these test cases\"\n# Must explicitly include *.pyi or flake8 ignores them\nflake8 --select BLK test_cases/*.py*\n# Adding --black-config '' meaning ignore any pyproject.toml should have no effect:\nflake8 --select BLK test_cases/*.py --black-config ''\nflake8 --select BLK --max-line-length 50 test_cases/*.py\nflake8 --select BLK --max-line-length 90 test_cases/*.py\nflake8 --select BLK with_pyproject_toml/*.py\nflake8 --select BLK with_pyproject_toml/*.py --black-config with_pyproject_toml/pyproject.toml\nflake8 --select BLK --max-line-length 88 with_pyproject_toml/\nflake8 --select BLK without_pyproject_toml/*.py --black-config with_pyproject_toml/pyproject.toml\n# Adding --black-config '' should have no effect:\n#flake8 --select BLK --max-line-length 88 with_pyproject_toml/ --black-config ''\nflake8 --select BLK non_conflicting_configurations/*.py\nflake8 --select BLK conflicting_configurations/*.py\n# Here using --black-config '' meaning ignore any (bad) pyproject.toml files:\nflake8 --select BLK with_bad_toml/hello_world.py --black-config ''\n\necho \"Checking we report expected black changes\"\ndiff test_changes/hello_world.txt <(flake8 --select BLK test_changes/hello_world.py)\ndiff test_changes/hello_world_EOF.txt <(flake8 --select BLK test_changes/hello_world_EOF.py)\ndiff test_changes/hello_world_EOF.txt <(flake8 --select BLK test_changes/hello_world_EOF.py --black-config '')\ndiff <(\n  if [ \"${WIN:-1}\" = 0 ]; then\n    sed 's_/_\\\\_2' with_bad_toml/hello_world.txt\n  else\n    cat with_bad_toml/hello_world.txt\n  fi\n) <(flake8 --select BLK with_bad_toml/hello_world.py)\ndiff with_pyproject_toml/ignoring_toml.txt <(flake8 with_pyproject_toml/ --select BLK --black-config '')\n\n# no changes by default,\nflake8 --select BLK test_changes/commas.py tests/black_preview.py\n# will make changes if we ignore the magic trailing comma:\ndiff test_changes/commas.txt <(flake8 --select BLK test_changes/commas.py --black-config with_pyproject_toml/pyproject.toml)\n# will make changes if we enable future functionality preview mode:\ndiff test_changes/black_preview.txt <(flake8 --select BLK test_changes/black_preview.py --black-config with_pyproject_toml/pyproject.toml)\n\necho \"Tests passed.\"\n"
  },
  {
    "path": "tests/test_cases/hello_world.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line\nand a PEP263 encoding line.\n\"\"\"\n\nprint(\"Hello world\")\n"
  },
  {
    "path": "tests/test_cases/mixed_tab_spaces.py",
    "content": "\"\"\"Invalid under Python 3, example with mixed indentation.\"\"\"\n\nif True:\n    print(\"This line was indented with four spaces!\")\n    if True:\n        print(\"This line was indented with eight spaces.\")\n    if True:\n\tprint(\"This line was indented with a tab!\")\n"
  },
  {
    "path": "tests/test_cases/no_closing_bracket.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal (with syntax error).\n\nThis is a simple test script using a hashbang line and a PEP263 encoding line. There is\na deliberate syntax error (missing closing bracket).\n\nBlack will fail to parse this file:\n\n    $ black --check no_closing_bracket.py ; echo \"Return code $?\"\n    error: cannot format no_closing_bracket.py: ('EOF in multi-line statement', (31, 0))\n    All done! ð ð ð\n    1 file would fail to reformat.\n    Return code 123\n\nIt seems in this case the plugin never gets the chance to report:\n\n    $ flake8 --select BLK no_closing_bracket.py ; echo \"Return code $?\"\n    Return code 0\n\nThis doesn't really matter, as it would be redundant with the flake8 syntax errors:\n\n    $ flake8 no_closing_bracket.py ; echo \"Return code $?\"\n    no_closing_bracket.py:30:19: E999 SyntaxError: unexpected EOF while parsing\n    Return code 1\n\n\"\"\"\n\nprint(\"Hello world\"\n"
  },
  {
    "path": "tests/test_cases/stub.pyi",
    "content": "def my_function(): ...\n\nclass Wibble: ...\n"
  },
  {
    "path": "tests/test_changes/black_preview.py",
    "content": "\"\"\"Example showing future black string reformatting.\"\"\"\n\na_very_long_variable = 17.3\nshort_value = 1234567890\n\n\ndef and_a_very_long_function_call():\n    \"\"\"Deep thought.\"\"\"\n    return 42\n\n\nmy_dict = {\n    \"a key in my dict\": a_very_long_variable\n    * and_a_very_long_function_call()\n    / 100000.0,\n    \"another key\": (short_value),\n}\n"
  },
  {
    "path": "tests/test_changes/black_preview.txt",
    "content": "test_changes/black_preview.py:13:25: BLK100 Black would make changes.\n"
  },
  {
    "path": "tests/test_changes/commas.py",
    "content": "\"\"\"Example of black and magic commas.\"\"\"\n\nvegetables = {\n    \"carrot\",\n    \"parsnip\",\n    \"potato\",\n    \"swede\",\n    \"leak\",\n    \"aubergine\",\n    \"tomato\",\n    \"peas\",\n    \"beans\",\n}\n\n# This set would easily fit on one line, but a trailing comma\n# after the final entry tells black (by default) to leave this\n# with one entry per line:\nyucky = {\n    \"aubergine\",\n    \"squid\",\n    \"snails\",\n}\n\nprint(\"I dislike these vegetables: %s.\" % \", \".join(vegetables.intersection(yucky)))\n"
  },
  {
    "path": "tests/test_changes/commas.txt",
    "content": "test_changes/commas.py:18:10: BLK100 Black would make changes.\n"
  },
  {
    "path": "tests/test_changes/hello_world.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line and a PEP263 encoding line.\n\nIn the original format, there excess spaces in the print call, and unwanted\nblank lines - which black will remove.\n\"\"\"\n\n\nprint ( \"Hello world\" )\n\n"
  },
  {
    "path": "tests/test_changes/hello_world.txt",
    "content": "test_changes/hello_world.py:12:6: BLK100 Black would make changes.\n"
  },
  {
    "path": "tests/test_changes/hello_world_EOF.py",
    "content": "\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script which in the formal form has a missing final\nline break - which black will add.\n\nThe point of this is the edit position will be at the very end of the file,\nwhich is a corner case.\n\"\"\"\n\nprint(\"Hello world\")"
  },
  {
    "path": "tests/test_changes/hello_world_EOF.txt",
    "content": "test_changes/hello_world_EOF.py:11:1: BLK100 Black would make changes.\n"
  },
  {
    "path": "tests/with_bad_toml/hello_world.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line\nand a PEP263 encoding line.\n\"\"\"\n\nprint(\"Hello world\")\n"
  },
  {
    "path": "tests/with_bad_toml/hello_world.txt",
    "content": "with_bad_toml/hello_world.py:0:1: BLK997 Invalid TOML file\n"
  },
  {
    "path": "tests/with_bad_toml/pyproject.toml",
    "content": "[tool.black]\nskip-string-normalization = true\n# This line is (a) in the wrong file, and (b) invalid syntax\nblack-config=\n"
  },
  {
    "path": "tests/with_pyproject_toml/ignoring_toml.txt",
    "content": "with_pyproject_toml/ordinary_quotes.py:10:7: BLK100 Black would make changes.\n"
  },
  {
    "path": "tests/with_pyproject_toml/ordinary_quotes.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line\nand a PEP263 encoding line.\nWe use ordinary quotes in this test.\n\"\"\"\n\nprint('Hello world')\n"
  },
  {
    "path": "tests/with_pyproject_toml/pyproject.toml",
    "content": "[tool.black]\n# This is probably better as an integer,\n# but reasonable to cope with it as str:\nline-length = \"88\"\nskip-string-normalization = true\nskip-magic-trailing-comma = true\npreview = true\n"
  },
  {
    "path": "tests/without_pyproject_toml/ordinary_quotes.py",
    "content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Print 'Hello world' to the terminal.\n\nThis is a simple test script using a hashbang line\nand a PEP263 encoding line.\nWe use ordinary quotes in this test.\n\"\"\"\n\nprint('Hello world')\n"
  }
]