adds a fix and test for #101

This commit is contained in:
Christopher Pickering 2021-10-28 14:39:38 +03:00
parent 85ed2a89b4
commit 77db0be1c2
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
4 changed files with 11 additions and 6 deletions

View file

@ -4,7 +4,6 @@
import logging
import re
## get pyproject.toml settings
from pathlib import Path
@ -218,7 +217,7 @@ class Config:
if extend_exclude:
self.exclude += r" | " + r" | ".join(
re.escape(x.strip()) for x in extend_exclude.split(",")
x.strip() for x in extend_exclude.split(",")
)
# add blank line after load tags

View file

@ -13,8 +13,12 @@ def get_src(src: List[Path], config: Config) -> List[Path]:
"""Get source files."""
paths = []
for item in src:
if Path.is_file(item) and no_pragma(config, item):
paths.append(item)
# normalize path
normalized_item = Path(item).resolve()
if Path.is_file(normalized_item) and no_pragma(config, normalized_item):
paths.append(normalized_item)
continue
# remove leading . from extension
@ -23,9 +27,9 @@ def get_src(src: List[Path], config: Config) -> List[Path]:
paths.extend(
filter(
lambda x: not re.search(config.exclude, str(x), re.VERBOSE)
lambda x: not re.search(config.exclude, x.as_posix(), re.VERBOSE)
and no_pragma(config, x),
list(item.glob(f"**/*.{extension}")),
list(normalized_item.glob(f"**/*.{extension}")),
)
)

View file

@ -0,0 +1 @@
<h1>bad</h2>

View file

@ -84,6 +84,7 @@ 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 """foo/excluded.html""" not in result.output
assert result.exit_code == 1