Merge pull request #24 from matthiask/mk/exclude

Fixed #22: Added configuration options to define excluded paths
This commit is contained in:
sur.la.route 2021-09-21 13:09:27 +02:00 committed by GitHub
commit 229c9c7317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 15 deletions

View file

@ -1,6 +1,9 @@
Changelog
=========
- Added support for overriding or extending the list of excluded paths in
``pyproject.toml``
0.3.9
-----
- Updated attribute handling

View file

@ -25,3 +25,5 @@ Configuration options can also be added to your projects `pyproject.toml` file.
extension = "html.dj"
custom_blocks = "toc,example" # custom code blocks {% toc %}...{% endtoc %}
indent = " " # change indentation level
exclude = ".venv,venv,.tox,.eggs,..." # override the default set of excluded paths
extend_exclude = ".custom" # add paths to exclude

View file

@ -45,7 +45,7 @@ def get_src(src: Path, config: Config) -> List[Path]:
paths = list(
filter(
lambda x: not re.search(config.ignored_paths, str(x), re.VERBOSE),
lambda x: not re.search(config.exclude, str(x), re.VERBOSE),
list(src.glob(f"**/*.{extension}")),
)
)

View file

@ -4,6 +4,7 @@
import logging
import re
## get pyproject.toml settings
from pathlib import Path
@ -61,7 +62,20 @@ class Config:
quiet: Optional[bool] = False,
):
self.ignored_paths: str = r"""
djlint_settings = load_pyproject_settings(Path(src))
# custom configuration options
self.extension: str = str(extension or djlint_settings.get("extension", "html"))
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
self.quiet: str = str(quiet or djlint_settings.get("quiet", ""))
self.custom_blocks: str = str(
build_custom_blocks(djlint_settings.get("custom_blocks")) or ""
)
# base options
self.indent: str = djlint_settings.get("indent", " ")
default_exclude: str = r"""
\.venv
| venv
| \.tox
@ -81,19 +95,12 @@ class Config:
| node_modules
| __pypackages__
"""
djlint_settings = load_pyproject_settings(Path(src))
# custom configuration options
self.extension: str = str(extension or djlint_settings.get("extension", "html"))
self.ignore: str = str(ignore or djlint_settings.get("ignore", ""))
self.quiet: str = str(quiet or djlint_settings.get("quiet", ""))
self.custom_blocks: str = str(
build_custom_blocks(djlint_settings.get("custom_blocks")) or ""
)
# base options
self.indent: str = djlint_settings.get("indent", " ")
self.exclude: str = djlint_settings.get("exclude", default_exclude)
extend_exclude: str = djlint_settings.get("extend_exclude", "")
if extend_exclude:
self.exclude += r" | " + r" | ".join(
re.escape(x.strip()) for x in extend_exclude.split(",")
)
# contents of tags will not be formatted, but tags will be formatted
self.ignored_block_opening: str = r"""

View file

@ -0,0 +1 @@
{{missing_space}}

View file

@ -0,0 +1 @@
{{missing_space}}

View file

@ -0,0 +1,2 @@
[tool.djlint]
extend_exclude = "excluded.html"

View file

@ -63,3 +63,10 @@ def test_indent(runner: CliRunner) -> None:
in result.output
)
assert result.exit_code == 1
def test_exclude(runner: CliRunner) -> None:
result = runner.invoke(djlint, ["tests/config_excludes"])
assert """html.html""" in result.output
assert """excluded.html""" not in result.output
assert result.exit_code == 1