mkdocs-include-markdown-plugin 7.1.1__tar.gz → 7.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/PKG-INFO +21 -3
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/README.md +20 -2
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/pyproject.toml +1 -1
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/cache.py +33 -15
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/config.py +1 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/plugin.py +6 -9
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/process.py +3 -6
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/.gitignore +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/LICENSE +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/__init__.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/directive.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/event.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/files_watcher.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/logger.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.1 → mkdocs_include_markdown_plugin-7.1.2}/src/mkdocs_include_markdown_plugin/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: mkdocs-include-markdown-plugin
|
|
3
|
-
Version: 7.1.
|
|
3
|
+
Version: 7.1.2
|
|
4
4
|
Summary: Mkdocs Markdown includer plugin.
|
|
5
5
|
Project-URL: Source, https://github.com/mondeja/mkdocs-include-markdown-plugin
|
|
6
6
|
Project-URL: Documentation, https://github.com/mondeja/mkdocs-include-markdown-plugin#documentation
|
|
@@ -135,8 +135,9 @@ plugins:
|
|
|
135
135
|
cache: 600
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
In order to use this feature, the dependency [platformdirs] must be installed
|
|
139
|
-
|
|
138
|
+
In order to use this feature, the dependency [platformdirs] must be installed
|
|
139
|
+
or the setting [`cache_dir`](#cache_dir) must be defined. You can include
|
|
140
|
+
[platformdirs] in the installation of the plugin adding the `cache` extra:
|
|
140
141
|
|
|
141
142
|
```txt
|
|
142
143
|
# requirements.txt
|
|
@@ -145,6 +146,23 @@ mkdocs-include-markdown-plugin[cache]
|
|
|
145
146
|
|
|
146
147
|
<!-- mdpo-disable-next-line -->
|
|
147
148
|
|
|
149
|
+
#### `cache_dir`
|
|
150
|
+
|
|
151
|
+
Directory where cached HTTP requests will be stored. If set, [platformdirs] is not
|
|
152
|
+
needed to be installed to use [`cache`](#cache).
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
plugins:
|
|
156
|
+
- include-markdown:
|
|
157
|
+
cache: 600
|
|
158
|
+
cache_dir: ./mkdocs-include-markdown-cache
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
A _.gitignore_ file will be added to the cache directory if not exists to avoid
|
|
162
|
+
committing the cache files.
|
|
163
|
+
|
|
164
|
+
<!-- mdpo-disable-next-line -->
|
|
165
|
+
|
|
148
166
|
#### `directives`
|
|
149
167
|
|
|
150
168
|
Customize the names of the directives.
|
|
@@ -101,8 +101,9 @@ plugins:
|
|
|
101
101
|
cache: 600
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
In order to use this feature, the dependency [platformdirs] must be installed
|
|
105
|
-
|
|
104
|
+
In order to use this feature, the dependency [platformdirs] must be installed
|
|
105
|
+
or the setting [`cache_dir`](#cache_dir) must be defined. You can include
|
|
106
|
+
[platformdirs] in the installation of the plugin adding the `cache` extra:
|
|
106
107
|
|
|
107
108
|
```txt
|
|
108
109
|
# requirements.txt
|
|
@@ -111,6 +112,23 @@ mkdocs-include-markdown-plugin[cache]
|
|
|
111
112
|
|
|
112
113
|
<!-- mdpo-disable-next-line -->
|
|
113
114
|
|
|
115
|
+
#### `cache_dir`
|
|
116
|
+
|
|
117
|
+
Directory where cached HTTP requests will be stored. If set, [platformdirs] is not
|
|
118
|
+
needed to be installed to use [`cache`](#cache).
|
|
119
|
+
|
|
120
|
+
```yaml
|
|
121
|
+
plugins:
|
|
122
|
+
- include-markdown:
|
|
123
|
+
cache: 600
|
|
124
|
+
cache_dir: ./mkdocs-include-markdown-cache
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A _.gitignore_ file will be added to the cache directory if not exists to avoid
|
|
128
|
+
committing the cache files.
|
|
129
|
+
|
|
130
|
+
<!-- mdpo-disable-next-line -->
|
|
131
|
+
|
|
114
132
|
#### `directives`
|
|
115
133
|
|
|
116
134
|
Customize the names of the directives.
|
|
@@ -9,9 +9,6 @@ import time
|
|
|
9
9
|
from importlib.util import find_spec
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
CACHE_AVAILABLE = find_spec('platformdirs') is not None
|
|
13
|
-
|
|
14
|
-
|
|
15
12
|
class Cache:
|
|
16
13
|
"""Cache for arbitrary content, one file per entry."""
|
|
17
14
|
|
|
@@ -64,31 +61,52 @@ class Cache:
|
|
|
64
61
|
def clean(self) -> None:
|
|
65
62
|
"""Clean expired entries from the cache."""
|
|
66
63
|
for fname in os.listdir(self.cache_dir):
|
|
64
|
+
if fname == '.gitignore':
|
|
65
|
+
continue
|
|
67
66
|
fpath = os.path.join(self.cache_dir, fname)
|
|
68
67
|
creation_time = self.get_creation_time_from_fpath(fpath)
|
|
69
68
|
if time.time() > creation_time + self.expiration_seconds:
|
|
70
69
|
os.remove(fpath)
|
|
71
70
|
|
|
72
71
|
|
|
73
|
-
def get_cache_directory() -> str | None:
|
|
74
|
-
"""Get
|
|
75
|
-
if
|
|
72
|
+
def get_cache_directory(cache_dir: str) -> str | None:
|
|
73
|
+
"""Get cache directory."""
|
|
74
|
+
if cache_dir:
|
|
75
|
+
return cache_dir
|
|
76
|
+
|
|
77
|
+
if not is_platformdirs_installed():
|
|
76
78
|
return None
|
|
77
79
|
|
|
78
80
|
try:
|
|
79
81
|
from platformdirs import user_data_dir
|
|
80
82
|
except ImportError:
|
|
81
83
|
return None
|
|
84
|
+
else:
|
|
85
|
+
return user_data_dir('mkdocs-include-markdown-plugin')
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def initialize_cache(expiration_seconds: int, cache_dir: str) -> Cache | None:
|
|
89
|
+
"""Initialize a cache instance."""
|
|
90
|
+
cache_directory = get_cache_directory(cache_dir)
|
|
91
|
+
|
|
92
|
+
if cache_directory is None:
|
|
93
|
+
return None
|
|
82
94
|
|
|
83
|
-
|
|
84
|
-
os.makedirs(cache_dir, exist_ok=True)
|
|
95
|
+
os.makedirs(cache_directory, exist_ok=True)
|
|
85
96
|
|
|
86
|
-
|
|
97
|
+
# Add a `.gitignore` file to prevent the cache directory from being
|
|
98
|
+
# included in the repository. This is needed because the cache directory
|
|
99
|
+
# can be configured as a relative path with `cache_dir` setting.
|
|
100
|
+
gitignore = os.path.join(cache_directory, '.gitignore')
|
|
101
|
+
if not os.path.exists(gitignore):
|
|
102
|
+
with open(gitignore, 'wb') as f:
|
|
103
|
+
f.write(b'*\n')
|
|
87
104
|
|
|
105
|
+
cache = Cache(cache_directory, expiration_seconds)
|
|
106
|
+
cache.clean()
|
|
107
|
+
return cache
|
|
88
108
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
cache_dir, expiration_seconds,
|
|
94
|
-
)
|
|
109
|
+
|
|
110
|
+
def is_platformdirs_installed() -> bool:
|
|
111
|
+
"""Check if `platformdirs` package is installed without importing it."""
|
|
112
|
+
return find_spec('platformdirs') is not None
|
|
@@ -24,6 +24,7 @@ class PluginConfig(Config): # noqa: D101
|
|
|
24
24
|
end = Optional(MkType(str))
|
|
25
25
|
exclude = ListOfItems(MkType(str), default=[])
|
|
26
26
|
cache = MkType(int, default=0)
|
|
27
|
+
cache_dir = MkType(str, default='')
|
|
27
28
|
recursive = MkType(bool, default=True)
|
|
28
29
|
directives = MkType(
|
|
29
30
|
dict,
|
|
@@ -31,22 +31,19 @@ class IncludeMarkdownPlugin(BasePlugin[PluginConfig]):
|
|
|
31
31
|
|
|
32
32
|
def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
|
|
33
33
|
if self.config.cache > 0:
|
|
34
|
-
cache = initialize_cache(self.config.cache)
|
|
34
|
+
cache = initialize_cache(self.config.cache, self.config.cache_dir)
|
|
35
35
|
if cache is None:
|
|
36
36
|
raise PluginError(
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
' mkdocs-include-markdown-plugin
|
|
40
|
-
' extra to install
|
|
37
|
+
'Either `cache_dir` global setting must be configured or'
|
|
38
|
+
' `platformdirs` package is required to use the'
|
|
39
|
+
' `cache` option. Install mkdocs-include-markdown-plugin'
|
|
40
|
+
" with the 'cache' extra to install `platformdirs`.",
|
|
41
41
|
)
|
|
42
|
-
cache.clean()
|
|
43
42
|
self._cache = cache
|
|
44
43
|
|
|
45
44
|
if '__default' not in self.config.directives: # pragma: no cover
|
|
46
45
|
for directive in self.config.directives:
|
|
47
|
-
if directive not in
|
|
48
|
-
'include', 'include-markdown',
|
|
49
|
-
}:
|
|
46
|
+
if directive not in ('include', 'include-markdown'):
|
|
50
47
|
raise PluginError(
|
|
51
48
|
f"Invalid directive name '{directive}' at 'directives'"
|
|
52
49
|
' global setting. Valid values are "include" and'
|
|
@@ -244,12 +244,9 @@ def rewrite_relative_urls(
|
|
|
244
244
|
``source_path`` will still work when inserted into a file at
|
|
245
245
|
``destination_path``.
|
|
246
246
|
"""
|
|
247
|
-
|
|
248
|
-
from urllib.parse import urlparse, urlunparse
|
|
249
|
-
|
|
250
|
-
if is_relative_path(url):
|
|
251
|
-
return url
|
|
247
|
+
from urllib.parse import urlparse, urlunparse
|
|
252
248
|
|
|
249
|
+
def rewrite_url(url: str) -> str:
|
|
253
250
|
scheme, netloc, path, params, query, fragment = urlparse(url)
|
|
254
251
|
|
|
255
252
|
# absolute or mail
|
|
@@ -425,7 +422,7 @@ def increase_headings_offset(markdown: str, offset: int = 0) -> str:
|
|
|
425
422
|
|
|
426
423
|
def rstrip_trailing_newlines(content: str) -> str:
|
|
427
424
|
"""Removes trailing newlines from a string."""
|
|
428
|
-
while content.endswith('\n'
|
|
425
|
+
while content.endswith(('\n', '\r')):
|
|
429
426
|
content = content.rstrip('\r\n')
|
|
430
427
|
return content
|
|
431
428
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|