Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-blue for openSUSE:Factory checked in at 2021-03-17 20:16:31 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-blue (Old) and /work/SRC/openSUSE:Factory/.python-blue.new.2401 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-blue" Wed Mar 17 20:16:31 2021 rev:2 rq:879548 version:0.6.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-blue/python-blue.changes 2021-01-18 11:34:48.885113196 +0100 +++ /work/SRC/openSUSE:Factory/.python-blue.new.2401/python-blue.changes 2021-03-17 20:20:00.255321565 +0100 @@ -1,0 +2,20 @@ +Wed Mar 17 04:05:48 UTC 2021 - Steve Kowalik <steven.kowa...@suse.com> + +- Update to 0.6.0: + * Add bullet about default line length of 79 characters + * Run blue over docs/ directory + * Fix formatting in docs/conf.py + * Preserve whitespace before hash mark on hanging comments (#31) + * Use flake8 to parse project and user configs for blue + * Patch the config param's callback + * Fixes for static analysis + * Format keys for Click's default_map + * Add pytest for testing + * Format tests/test_blue.py in blue and bluecheck commands + * Add tests for config parsing + * Update docs requirements to match setup.py + * Add note to README and changelog. + * Fix --version option handling and add test cases + * Move coverage switches on pytest to separate sections + +------------------------------------------------------------------- Old: ---- blue-0.5.2.tar.gz New: ---- blue-0.6.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-blue.spec ++++++ --- /var/tmp/diff_new_pack.ew8xhT/_old 2021-03-17 20:20:00.759322254 +0100 +++ /var/tmp/diff_new_pack.ew8xhT/_new 2021-03-17 20:20:00.763322260 +0100 @@ -20,7 +20,7 @@ %define skip_python2 1 %define modname blue Name: python-blue -Version: 0.5.2 +Version: 0.6.0 Release: 0 Summary: A code formatter written in, and written for Python License: MIT @@ -31,6 +31,7 @@ BuildRequires: %{python_module black} # BuildRequires: %%{python_module doc8} BuildRequires: %{python_module flake8} +BuildRequires: %{python_module pytest-cov} BuildRequires: %{python_module pytest} BuildRequires: %{python_module rstcheck} BuildRequires: %{python_module setuptools} @@ -44,7 +45,9 @@ Requires: python-aiohttp_cors Requires: python-appdirs Requires: python-attrs >= 18.1.0 +Requires: python-black Requires: python-click >= 7.1.2 +Requires: python-flake8 Requires: python-mypy_extensions >= 0.4.3 Requires: python-pathspec >= 0.6 Requires: python-regex >= 2020.1.8 @@ -55,7 +58,7 @@ Requires: python-dataclasses %endif Requires(post): update-alternatives -Requires(postun): update-alternatives +Requires(postun):update-alternatives BuildArch: noarch %python_subpackages ++++++ blue-0.5.2.tar.gz -> blue-0.6.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/.github/workflows/integration.yml new/blue-0.6.0/.github/workflows/integration.yml --- old/blue-0.5.2/.github/workflows/integration.yml 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/.github/workflows/integration.yml 2021-02-12 06:25:05.000000000 +0100 @@ -7,9 +7,9 @@ checks: runs-on: ubuntu-latest strategy: - max-parallel: 4 + max-parallel: 5 matrix: - check: [doc8, docs, flake8, rstcheck] + check: [bluecheck, doc8, flake8, rstcheck, docs] steps: - uses: actions/checkout@v2 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/README.rst new/blue-0.6.0/README.rst --- old/blue-0.5.2/README.rst 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/README.rst 2021-02-12 06:25:05.000000000 +0100 @@ -51,6 +51,16 @@ quoted strings for docstrings; it just looks better to us! For all other strings, ``blue`` defaults to single quoted strings. +* ``blue`` defaults to line lengths of 79 characters. Nearly every project + creates a pyproject.toml just to change this one setting so making it + consistent with PEP 8 seems relatively harmless. + +* ``blue`` preserves the whitespace before the hash mark for right hanging + comments. + +* ``blue`` supports multiple config files: ``pyproject.toml``, ``setup.cfg``, + ``tox.ini``, and ``.blue``. + We are `accumulating <https://github.com/grantjenks/blue/issues/2>`_ a list of other deviations we are considering. As we decide to implement any particular suggestion, we'll turn those into individual issues and tackle them @@ -83,6 +93,8 @@ ``black`` project. * Grant Jenks * Barry Warsaw +* Corey from FutureSpaceDesigns for the unofficial logo and `blue project + merchandise <https://www.teepublic.com/t-shirt/6556561-tobias-blue>`_. ``blue`` is licensed under the terms of the Apache License Version 2.0. ``black`` is `licensed <https://github.com/psf/black#license>`_ under the @@ -92,9 +104,15 @@ Project details =============== +.. image:: https://img.shields.io/badge/code%20style-blue-blue.svg + :target: https://blue.readthedocs.io/ + .. image:: https://github.com/grantjenks/blue/workflows/integration/badge.svg :target: https://github.com/grantjenks/blue/actions?query=workflow%3Aintegration +.. image:: https://github.com/grantjenks/blue/workflows/release/badge.svg + :target: https://github.com/grantjenks/blue/actions?query=workflow%3Arelease + * Project home: https://github.com/grantjenks/blue * Report bugs and suggestions at: https://github.com/grantjenks/blue/issues * Code hosting: https://github.com/grantjenks/blue.git diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/blue/__init__.py new/blue-0.6.0/blue/__init__.py --- old/blue-0.5.2/blue/__init__.py 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/blue/__init__.py 2021-02-12 06:25:05.000000000 +0100 @@ -4,14 +4,20 @@ """ +import logging import re +import sys import black from black import ( Leaf, Path, + ProtoComment, + STANDALONE_COMMENT, STRING_PREFIX_CHARS, + click, + make_comment, prev_siblings_are, sub_twice, syms, @@ -19,10 +25,19 @@ toml, user_cache_dir, ) +from flake8.options import config as flake8_config +from flake8.options import manager as flake8_manager -from typing import Dict, Any +from enum import Enum +from functools import lru_cache +from typing import Any, Dict, List, Optional -__version__ = '0.5.2' +from click.decorators import version_option + + +__version__ = '0.6.0' + +LOG = logging.getLogger(__name__) black_normalize_string_quotes = black.normalize_string_quotes black_format_file_in_place = black.format_file_in_place @@ -31,6 +46,50 @@ black.CACHE_DIR = Path(user_cache_dir('blue', version=__version__)) +# Blue works by monkey patching black, so we don't have to duplicate +# everything, and we can take advantage of black's excellent implementation. +# We still have to monkey patch more than we want so eventually, these ought +# to be implemented by hooks in black that we can set. Until then, there are +# essentially two modes of black operation we have to deal with. +# +# When black is formatting a single file, it's easy to monkey patch at an entry +# point for blue. But when formatting multiple files, black uses some clever +# asynchronous parallelization which prevents us from monkey patching a few +# things in the blue entry point. By way of code inspection and +# experimentation, we've found a convenient place to monkey patch a few things +# after the subprocesses have been spawned. Define your monkey patch points +# here. + + +class Mode(Enum): + asynchronous = 1 + synchronous = 2 + + +BLUE_MONKEYPATCHES = [ + # Synchronous Monkees. + ('format_file_in_place', Mode.synchronous), + ('normalize_string_quotes', Mode.synchronous), + ('parse_pyproject_toml', Mode.synchronous), + # Asynchronous Monkees. + ('normalize_string_quotes', Mode.asynchronous), + ('list_comments', Mode.asynchronous), +] + + +def monkey_patch_black(mode: Mode) -> None: + blue = sys.modules['blue'] + for function_name, monkey_mode in BLUE_MONKEYPATCHES: + if monkey_mode is mode: + setattr(black, function_name, getattr(blue, function_name)) + + +# Because blue makes different choices than black, and all of this code is +# essentially ripped off from black, applying blue to it will change the +# formatting. That will make diff'ing with black more difficult, so just turn +# off formatting for anything that comes from black. + +# fmt: off def is_docstring(leaf: Leaf) -> bool: # Most of this function was copied from Black! @@ -142,35 +201,119 @@ def format_file_in_place(*args, **kws): - # Black does some clever aync/parallelization so apply monkey patches here - # too. - black.normalize_string_quotes = normalize_string_quotes + # This is a convenient place to monkey patch any function that must be + # done after black's asynchronous invocation. + monkey_patch_black(Mode.asynchronous) return black_format_file_in_place(*args, **kws) +# Like black's list_comments() but preserves whitespace leading up to the hash +# mark. Because what we really need to do is restore the whitespace after the +# line.lstrip() statement, there really is no good way to more narrowly +# monkeypatch. This would be a good hook to install. See +# https://github.com/grantjenks/blue/issues/14 +@lru_cache(maxsize=4096) +def list_comments(prefix: str, *, is_endmarker: bool) -> List[ProtoComment]: + result: List[ProtoComment] = [] + if not prefix or "#" not in prefix: + return result + + consumed = 0 + nlines = 0 + ignored_lines = 0 + for index, orig_line in enumerate(prefix.split("\n")): + consumed += len(orig_line) + 1 # adding the length of the split '\n' + line = orig_line.lstrip() + if not line: + nlines += 1 + if not line.startswith("#"): + # Escaped newlines outside of a comment are not really newlines at + # all. We treat a single-line comment following an escaped newline + # as a simple trailing comment. + if line.endswith("\\"): + ignored_lines += 1 + continue + + if index == ignored_lines and not is_endmarker: + comment_type = token.COMMENT # simple trailing comment + else: + comment_type = STANDALONE_COMMENT + # Restore the original whitespace, but only for hanging comments. We + # use a heuristic to figure out hanging comments since that information + # isn't explicitly passed in here (no, `is_endmarker` doesn't tell us, + # apparently). Hanging comments seem to not have a newline in prefix. + # + # Note however that the whitespace() function in black will add back + # two leading spaces (see DOUBLESPACE). Rather than monkey patch the + # entire function, let's just remove up to two spaces before the hash + # character. + if '\n' not in prefix: + whitespace = orig_line[:-len(line)] + if len(whitespace) >= 2: + whitespace = whitespace[2:] + comment = whitespace + make_comment(line) + else: + comment = make_comment(line) + result.append( + ProtoComment( + type=comment_type, value=comment, newlines=nlines, + consumed=consumed + ) + ) + nlines = 0 + return result + + def parse_pyproject_toml(path_config: str) -> Dict[str, Any]: - """Parse a pyproject toml file, pulling out relevant parts for Blue + """Parse a pyproject toml file, pulling out relevant parts for Black If parsing fails, will raise a toml.TomlDecodeError - """ - # Most of this function was copied from Black! pyproject_toml = toml.load(path_config) - config = pyproject_toml.get('tool', {}).get('blue', {}) - return { - k.replace('--', '').replace('-', '_'): v for k, v in config.items() - } - + # Read the "blue" section of pyproject.toml for configs. + config = pyproject_toml.get("tool", {}).get("blue", {}) + return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()} # noqa: E501 +# fmt: on + + +class MergedConfigParser(flake8_config.MergedConfigParser): + def _parse_config(self, config_parser, parent=None): + """Skip option parsing in flake8's config parsing.""" + config_dict = {} + for option_name in config_parser.options(self.program_name): + value = config_parser.get(self.program_name, option_name) + LOG.debug('Option "%s" has value: %r', option_name, value) + config_dict[option_name] = value + return config_dict + + +def read_configs( + ctx: click.Context, param: click.Parameter, value: Optional[str] +) -> Optional[str]: + """Read configs through the config param's callback hook.""" + # Use black's `read_pyproject_toml` for the default + result = black.read_pyproject_toml(ctx, param, value) + # Use flake8's config file parsing to load setup.cfg, tox.ini, and .blue + # The parsing looks both in the project and user directories. + finder = flake8_config.ConfigFileFinder('blue') + manager = flake8_manager.OptionManager('blue', '0') + parser = MergedConfigParser(manager, finder) + config = parser.parse() + # Merge the configs into Click's `default_map`. + default_map: Dict[str, Any] = {} + default_map.update(ctx.default_map or {}) + for key, value in config.items(): + key = key.replace('--', '').replace('-', '_') + default_map[key] = value + ctx.default_map = default_map + return result -def monkey_patch_black(): - """Monkey patch black. - Python, I love you. - - """ - black.format_file_in_place = format_file_in_place - black.normalize_string_quotes = normalize_string_quotes - black.parse_pyproject_toml = parse_pyproject_toml +def main(): + monkey_patch_black(Mode.synchronous) + # Reach in and monkey patch the Click options. This is tricky based on the + # way Click works! This is highly fragile because the index into the Click + # parameters is dependent on the decorator order for Black's main(). # Change the default line length to 79 characters. line_length_param = black.main.params[1] assert line_length_param.name == 'line_length' @@ -181,8 +324,13 @@ target_version_param.help = target_version_param.help.replace( 'Black', 'Blue' ) - - -def main(): - monkey_patch_black() + # Change the config param callback to support setup.cfg, tox.ini, etc. + config_param = black.main.params[17] + assert config_param.name == 'config' + config_param.callback = read_configs + # Change the version string by adding a redundant Click `version_option` + # decorator on `black.main`. Fortunately the added `version_option` takes + # precedence over the existing one. + version_string = f'{__version__}, based on black {black.__version__}' + version_option(version_string)(black.main) black.main() Binary files old/blue-0.5.2/docs/_static/logo.png and new/blue-0.6.0/docs/_static/logo.png differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/docs/conf.py new/blue-0.6.0/docs/conf.py --- old/blue-0.5.2/docs/conf.py 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/docs/conf.py 2021-02-12 06:25:05.000000000 +0100 @@ -12,6 +12,7 @@ import os import sys + sys.path.insert(0, os.path.abspath('..')) import blue @@ -32,8 +33,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [ -] +extensions = [] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -48,7 +48,6 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -# html_theme = 'alabaster' # Add any paths that contain custom static files (such as style sheets) here, @@ -56,6 +55,25 @@ # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] +html_theme_options = { + 'logo': 'logo.png', + 'logo_name': True, + 'logo_text_align': 'center', + 'show_powered_by': False, + 'show_related': True, + 'github_user': 'grantjenks', + 'github_repo': 'blue', + 'github_type': 'star', +} + +html_sidebars = { + '**': [ + 'about.html', + 'localtoc.html', + 'searchbox.html', + ] +} + # -- Read the Docs ----------------------------------------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/docs/index.rst new/blue-0.6.0/docs/index.rst --- old/blue-0.5.2/docs/index.rst 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/docs/index.rst 2021-02-12 06:25:05.000000000 +0100 @@ -5,6 +5,17 @@ ======= +2021-02-11 (0.6.0) +------------------ + +- Preserve the whitespace before the hash mark for right hanging comments. + (GH#20) +- Support multiple config files: pyproject.toml, setup.cfg, tox.ini, and .blue + (GH#30) +- Fixed ``blue --version`` (GH#32) +- Added tests! + + 2021-01-17 (0.5.2) ------------------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/docs/requirements.txt new/blue-0.6.0/docs/requirements.txt --- old/blue-0.5.2/docs/requirements.txt 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/docs/requirements.txt 2021-02-12 06:25:05.000000000 +0100 @@ -1 +1,2 @@ -black +black==20.8b1 +flake8==3.8.4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/requirements.txt new/blue-0.6.0/requirements.txt --- old/blue-0.5.2/requirements.txt 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/requirements.txt 2021-02-12 06:25:05.000000000 +0100 @@ -1,6 +1,8 @@ -e . doc8 flake8 +pytest +pytest-cov rstcheck sphinx tox diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/setup.py new/blue-0.6.0/setup.py --- old/blue-0.5.2/setup.py 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/setup.py 2021-02-12 06:25:05.000000000 +0100 @@ -13,6 +13,7 @@ def run_tests(self): import tox + errno = tox.cmdline(self.test_args) exit(errno) @@ -36,7 +37,7 @@ packages=['blue'], tests_require=['tox'], cmdclass={'test': Tox}, - install_requires=['black==20.8b1'], + install_requires=['black==20.8b1', 'flake8==3.8.4'], project_urls={ 'Documentation': 'https://blue.readthedocs.io/en/latest', 'Source': 'https://github.com/grantjenks/blue.git', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/bad_cases/demo.py new/blue-0.6.0/tests/bad_cases/demo.py --- old/blue-0.5.2/tests/bad_cases/demo.py 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/bad_cases/demo.py 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,64 @@ +# Copied from the Black Playground at https://black.now.sh/ (MIT LICENSE) +# And reformated with Blue :) + +from seven_dwwarfs import Grumpy, Happy, Sleepy, Bashful, Sneezy, Dopey, Doc + +x = {"a": 37, "b": 42, "c": 927} + +x = 123456789.123456789e123456789 + +if ( + very_long_variable_name is not None + and very_long_variable_name.field > 0 + or very_long_variable_name.is_debug +): + z = "hello " + "world" +else: + world = "world" + a = "hello {}".format(world) + f = rf"hello {world}" +if this and that: + y = "hello " "world" # Hanging comment + + +class Foo(object): + def f(self): + return 37 * -2 + + def g(self, x, y=42): + return y + + +def f(a: List[int]): + return 37 - a[42 - u : y ** 3] + + +def very_important_function( + template: str, + *variables, + file: os.PathLike, + debug: bool = False, +): + """Applies `variables` to the `template` and writes to `file`.""" + with open(file, "w") as f: + ... + + +# fmt: off +custom_formatting = [ + 0, 1, 2, + 3, 4, 5, + 6, 7, 8, +] +# fmt: on +regular_formatting = [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, +] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_blue/.blue new/blue-0.6.0/tests/config_blue/.blue --- old/blue-0.5.2/tests/config_blue/.blue 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_blue/.blue 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,2 @@ +[blue] +line-length = 25 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_blue/example.py new/blue-0.6.0/tests/config_blue/example.py --- old/blue-0.5.2/tests/config_blue/example.py 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_blue/example.py 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,4 @@ +def example(): + return ( + x1 + x2 + x3 + x4 + ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_pyproject/example.py new/blue-0.6.0/tests/config_pyproject/example.py --- old/blue-0.5.2/tests/config_pyproject/example.py 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_pyproject/example.py 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,4 @@ +def example(): + return ( + x1 + x2 + x3 + x4 + ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_pyproject/pyproject.toml new/blue-0.6.0/tests/config_pyproject/pyproject.toml --- old/blue-0.5.2/tests/config_pyproject/pyproject.toml 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_pyproject/pyproject.toml 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,2 @@ +[tool.blue] +line-length = 25 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_setup/example.py new/blue-0.6.0/tests/config_setup/example.py --- old/blue-0.5.2/tests/config_setup/example.py 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_setup/example.py 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,4 @@ +def example(): + return ( + x1 + x2 + x3 + x4 + ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_setup/setup.cfg new/blue-0.6.0/tests/config_setup/setup.cfg --- old/blue-0.5.2/tests/config_setup/setup.cfg 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_setup/setup.cfg 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,2 @@ +[blue] +line-length = 25 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_tox/example.py new/blue-0.6.0/tests/config_tox/example.py --- old/blue-0.5.2/tests/config_tox/example.py 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_tox/example.py 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,4 @@ +def example(): + return ( + x1 + x2 + x3 + x4 + ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/config_tox/tox.ini new/blue-0.6.0/tests/config_tox/tox.ini --- old/blue-0.5.2/tests/config_tox/tox.ini 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/config_tox/tox.ini 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,2 @@ +[blue] +line-length = 25 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/good_cases/demo.py new/blue-0.6.0/tests/good_cases/demo.py --- old/blue-0.5.2/tests/good_cases/demo.py 1970-01-01 01:00:00.000000000 +0100 +++ new/blue-0.6.0/tests/good_cases/demo.py 2021-02-12 06:25:05.000000000 +0100 @@ -0,0 +1,64 @@ +# Copied from the Black Playground at https://black.now.sh/ (MIT LICENSE) +# And reformated with Blue :) + +from seven_dwwarfs import Grumpy, Happy, Sleepy, Bashful, Sneezy, Dopey, Doc + +x = {'a': 37, 'b': 42, 'c': 927} + +x = 123456789.123456789e123456789 + +if ( + very_long_variable_name is not None + and very_long_variable_name.field > 0 + or very_long_variable_name.is_debug +): + z = 'hello ' + 'world' +else: + world = 'world' + a = 'hello {}'.format(world) + f = rf'hello {world}' +if this and that: + y = 'hello ' 'world' # Hanging comment + + +class Foo(object): + def f(self): + return 37 * -2 + + def g(self, x, y=42): + return y + + +def f(a: List[int]): + return 37 - a[42 - u : y ** 3] + + +def very_important_function( + template: str, + *variables, + file: os.PathLike, + debug: bool = False, +): + """Applies `variables` to the `template` and writes to `file`.""" + with open(file, 'w') as f: + ... + + +# fmt: off +custom_formatting = [ + 0, 1, 2, + 3, 4, 5, + 6, 7, 8, +] +# fmt: on +regular_formatting = [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, +] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tests/test_blue.py new/blue-0.6.0/tests/test_blue.py --- old/blue-0.5.2/tests/test_blue.py 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/tests/test_blue.py 2021-02-12 06:25:05.000000000 +0100 @@ -1,5 +1,60 @@ +import pathlib +import subprocess + +import black import blue +import pytest + +tests_dir = pathlib.Path(__file__).parent.absolute() + + +@pytest.mark.parametrize( + 'test_dir', + [ + 'config_setup', + 'config_tox', + 'config_blue', + 'config_pyproject', + 'good_cases', + ], +) +def test_good_dirs(monkeypatch, test_dir): + test_dir = tests_dir / test_dir + monkeypatch.chdir(test_dir) + monkeypatch.setattr('sys.argv', ['blue', '--check', '.']) + black.find_project_root.cache_clear() + with pytest.raises(SystemExit) as exc_info: + blue.main() + assert exc_info.value.code == 0 + + +@pytest.mark.parametrize( + 'test_dir', + ['bad_cases'], +) +def test_bad_dirs(monkeypatch, test_dir): + test_dir = tests_dir / test_dir + monkeypatch.chdir(test_dir) + monkeypatch.setattr('sys.argv', ['blue', '--check', '.']) + black.find_project_root.cache_clear() + with pytest.raises(SystemExit) as exc_info: + blue.main() + assert exc_info.value.code == 1 + + +def test_main(capsys, monkeypatch): + monkeypatch.setattr('sys.argv', ['blue', '--version']) + with pytest.raises(SystemExit) as exc_info: + import blue.__main__ + assert exc_info.value.code == 0 -def test_version(): - assert blue.__version__ +def test_version(capsys, monkeypatch): + monkeypatch.setattr('sys.argv', ['blue', '--version']) + with pytest.raises(SystemExit) as exc_info: + blue.main() + assert exc_info.value.code == 0 + out, err = capsys.readouterr() + version = f'blue, version {blue.__version__}, based on black {black.__version__}\n' + assert out == version + assert err == '' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/blue-0.5.2/tox.ini new/blue-0.6.0/tox.ini --- old/blue-0.5.2/tox.ini 2021-01-18 06:52:53.000000000 +0100 +++ new/blue-0.6.0/tox.ini 2021-02-12 06:25:05.000000000 +0100 @@ -1,14 +1,24 @@ [tox] -envlist=py36,py37,py38,py39,doc8,docs,flake8,rstcheck +envlist=bluecheck,doc8,flake8,rstcheck,docs,py36,py37,py38,py39 skip_missing_interpreters=True [testenv] -deps=pytest commands=pytest +deps= + pytest + pytest-cov [pytest] +addopts= + --cov blue testpaths=blue docs tests +[testenv:blue] +commands=blue blue docs setup.py tests/test_blue.py + +[testenv:bluecheck] +commands=blue --check blue docs setup.py tests/test_blue.py + [testenv:docs] allowlist_externals=make changedir=docs @@ -27,6 +37,19 @@ deps=rstcheck commands=rstcheck --report warning README.rst +[coverage:report] +fail_under=87 +show_missing=true + +[coverage:run] +branch=true +parallel=true +omit= + +[coverage:paths] +source= + blue + [flake8] ignore= E124