Skip to content

Commit

Permalink
Add config support to find_opts
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Jun 26, 2018
1 parent d1f254f commit bdc7f47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 9 additions & 5 deletions invocations/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,28 @@ def blacken(
:param str find_opts:
Extra option string appended to the end of the internal ``find``
command. For example, skip a vendor directory with ``"-and -not -path
./vendor\*"``, add ``-mtime N``, or etc.
./vendor\*"``, add ``-mtime N``, or etc. Honors the
``blacken.find_opts`` config option.
.. versionadded:: 1.2
.. versionchanged:: 1.4
Added the ``find_opts`` argument.
"""
config = c.config.get("blacken", {})
default_folders = ["."]
configured_folders = c.config.get("blacken", {}).get(
"folders", default_folders
)
configured_folders = config.get("folders", default_folders)
folders = folders or configured_folders

default_find_opts = ""
configured_find_opts = config.get("find_opts", default_find_opts)
find_opts = find_opts or configured_find_opts

black_command_line = "black -l {}".format(line_length)
if check:
black_command_line = "{} --check".format(black_command_line)
if diff:
black_command_line = "{} --diff".format(black_command_line)
if find_opts is not None:
if find_opts:
find_opts = " {}".format(find_opts)
else:
find_opts = ""
Expand Down
12 changes: 12 additions & 0 deletions tests/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ def folders_config_loses_to_runtime(self, ctx):
ctx.blacken = dict(folders=["nowhere"])
blacken(ctx, folders=["nowhere"])
assert "nowhere" in ctx.run_command

def find_opts_configurable(self, ctx):
ctx.blacken = dict(find_opts="-and -not -name foo.py")
blacken(ctx)
assert (
"find . -name '*.py' -and -not -name foo.py" in ctx.run_command
)

def find_opts_config_loses_to_runtime(self, ctx):
ctx.blacken = dict(find_opts="-and -not -name foo.py")
blacken(ctx, find_opts="-or -name '*.js'")
assert "find . -name '*.py' -or -name '*.js'" in ctx.run_command

0 comments on commit bdc7f47

Please sign in to comment.