Skip to content

Commit 05f54c0

Browse files
Concurrent (#11)
1 parent 3f3deb9 commit 05f54c0

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

mkdocs_file_filter_plugin/judger.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,38 @@ def evaluate(self, file: MkDocsFile):
2828
)
2929
for glob in self.plugin_config.include_glob:
3030
if fnmatch.fnmatchcase(file.src_path, glob):
31-
return True, str(f"glob: {glob}")
31+
return file, True, str(f"glob: {glob}")
3232
for regex in self.plugin_config.include_regex:
3333
if re.match(regex, file.src_path):
34-
return True, str(f"regex: {regex}")
34+
return file, True, str(f"regex: {regex}")
3535
if file.is_documentation_page() and self.plugin_config.include_tag is not []:
3636
tags = self.__get_metadata(file)
3737
for tag in self.plugin_config.include_tag:
3838
if tag in tags:
39-
return True, str(f"{self.plugin_config.metadata_property}: {tag}")
39+
return (
40+
file,
41+
True,
42+
str(f"{self.plugin_config.metadata_property}: {tag}"),
43+
)
4044
for glob in self.plugin_config.exclude_glob:
4145
if fnmatch.fnmatchcase(file.src_path, glob):
42-
return False, str(f"glob: {glob}")
46+
return file, False, str(f"glob: {glob}")
4347
for regex in self.plugin_config.exclude_regex:
4448
if re.match(regex, file.src_path):
45-
return False, str(f"regex: {regex}")
49+
return file, False, str(f"regex: {regex}")
4650
if file.is_documentation_page() and self.plugin_config.exclude_tag is not []:
4751
tags = self.__get_metadata(file)
4852
for tag in self.plugin_config.exclude_tag:
4953
if tag in tags:
50-
return False, str(f"{self.plugin_config.metadata_property}: {tag}")
54+
return (
55+
file,
56+
False,
57+
str(f"{self.plugin_config.metadata_property}: {tag}"),
58+
)
5159
if self.plugin_config.mkdocsignore is True:
5260
if self.mkdocsignore_parser.match(pathlib.Path(file.abs_src_path)):
53-
return False, "mkdocsignore"
54-
return True, "no rule"
61+
return file, False, "mkdocsignore"
62+
return file, True, "no rule"
5563

5664
def __path_fix(self, src_path, abs_src_path):
5765
if os.sep != "/":

mkdocs_file_filter_plugin/plugin.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import concurrent.futures
12
import pathlib
23

34
from mkdocs.config.defaults import MkDocsConfig
@@ -55,11 +56,18 @@ def on_files(self, files: MkDocsFiles, config: MkDocsConfig):
5556
return
5657

5758
judger = Judger(self.config, config)
58-
for file in files:
59-
result, reason = judger.evaluate(file)
60-
if result:
59+
60+
with concurrent.futures.ThreadPoolExecutor() as executor:
61+
results = [executor.submit(judger.evaluate, file) for file in files]
62+
concurrent.futures.wait(results)
63+
64+
for result in results:
65+
file, included, reason = result.result()
66+
if included:
6167
LOG.debug("include file: %s (because %s)" % (file.src_path, reason))
68+
continue
6269
else:
6370
LOG.debug("exclude file: %s (because %s)" % (file.src_path, reason))
6471
files.remove(file)
65-
return MkDocsFiles(files)
72+
73+
return files

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = 'A MkDocs plugin that lets you exclude/include docs files using gl
55
authors = ["Dariusz Porowski"]
66
homepage = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin"
77
repository = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin"
8-
documentation = "https://dariusz.porowski.dev/mkdocs-file-filter-plugin"
8+
documentation = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin/blob/main/README.md"
99
readme = "README.md"
1010
license = "MIT"
1111
keywords = ["mkdocs", "plugin", "exclude", "include", "glob", "regex", "gitignore", "markdown", "frontmatter", "metadata", "tags"]
@@ -16,6 +16,7 @@ classifiers = [
1616
"Programming Language :: Python :: 3.8",
1717
"Programming Language :: Python :: 3.9",
1818
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
1920
"Programming Language :: Python :: 3 :: Only",
2021
"Operating System :: OS Independent",
2122
"License :: OSI Approved :: MIT License",
@@ -33,7 +34,7 @@ History = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin/releases
3334
file-filter = "mkdocs_file_filter_plugin.plugin:FileFilter"
3435

3536
[tool.poetry.dependencies]
36-
python = ">=3.8.1,<3.11"
37+
python = ">=3.8.1,<4.0"
3738
mkdocs = "^1.4.0"
3839
igittigitt = "^2.1.2"
3940
pyyaml = "^6.0"

0 commit comments

Comments
 (0)