Skip to content

Commit 927ee26

Browse files
authored
Release 1.4.0 (#2986)
1 parent 5cce501 commit 927ee26

File tree

4 files changed

+213
-1
lines changed

4 files changed

+213
-1
lines changed

.markdownlintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// Code block style
1717
"MD046": { "style": "fenced" },
1818

19+
// Multiple headings with the same title
20+
"MD024": { "siblings_only": true },
21+
1922
// Allow inline HTML
2023
"MD033": false
2124
}

docs/about/release-notes.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,214 @@ The current and past members of the MkDocs team.
2727
* [@oprypin](https://github.com/oprypin/)
2828
* [@ultrabug](https://github.com/ultrabug/)
2929

30+
## Version 1.4.0 (2022-09-27)
31+
32+
### Feature upgrades
33+
34+
#### Hooks (#2978)
35+
36+
The new `hooks:` config allows you to add plugin-like event handlers from local Python files, without needing to set up and install an actual plugin.
37+
38+
See [**documentation**](../user-guide/configuration.md#hooks).
39+
40+
#### `edit_uri` flexibility (#2927)
41+
42+
There is a new `edit_uri_template:` config.
43+
It works like `edit_uri` but more generally covers ways to construct an edit URL.
44+
See [**documentation**](../user-guide/configuration.md#edit_uri_template).
45+
46+
Additionally, the `edit_uri` functionality will now fully work even if `repo_url` is omitted (#2928)
47+
48+
### Upgrades for plugin developers
49+
50+
NOTE: This release has big changes to the implementation of plugins and their configs. But, the intention is to have zero breaking changes in all reasonably common use cases. Or at the very least if a code fix is required, there should always be a way to stay compatible with older MkDocs versions. Please report if this release breaks something.
51+
52+
#### Customize event order for plugin event handlers (#2973)
53+
54+
Plugins can now choose to set a priority value for their event handlers. This can override the old behavior where for each event type, the handlers are called in the order that their plugins appear in the [`plugins` config](../user-guide/configuration.md#plugins).
55+
56+
If this is set, events with higher priority are called first. Events without a chosen priority get a default of 0. Events that have the same priority are ordered as they appear in the config.
57+
58+
See [**documentation**](../dev-guide/plugins.md#event-priorities).
59+
60+
#### New events that persist across builds in `mkdocs serve` (#2972)
61+
62+
The new events are `on_startup` and `on_shutdown`. They run at the very beginning and very end of an `mkdocs` invocation.
63+
`on_startup` also receives information on how `mkdocs` was invoked (e.g. `serve` `--dirtyreload`).
64+
65+
See [**documentation**](../dev-guide/plugins.md#events).
66+
67+
#### Replace `File.src_path` to not deal with backslashes (#2930)
68+
69+
The property `src_path` uses backslashes on Windows, which doesn't make sense as it's a virtual path.
70+
To not make a breaking change, there's no change to how *this* property is used, but now you should:
71+
72+
* Use **`File.src_uri`** instead of `File.src_path`
73+
* and **`File.dest_uri`** instead of `File.dest_path`.
74+
75+
These consistently use forward slashes, and are now the definitive source that MkDocs itself uses.
76+
77+
See [source code](https://github.com/mkdocs/mkdocs/blob/1.4.0/mkdocs/structure/files.py#L151).
78+
79+
As a related tip: you should also stop using `os.path.*` or `pathlib.Path()` to deal with these paths, and instead use `posixpath.*` or `pathlib.PurePosixPath()`
80+
81+
#### MkDocs is type-annotated, ready for use with [mypy](https://mypy.readthedocs.io/) (#2941, #2970)
82+
83+
##### Type annotations for event handler methods (#2931)
84+
85+
MkDocs' plugin event methods now have type annotations. You might have been adding annotations to events already, but now they will be validated to match the original.
86+
87+
See [source code](https://github.com/mkdocs/mkdocs/blob/1.4.0/mkdocs/plugins.py#L165) and [documentation](../dev-guide/plugins.md#events).
88+
89+
One big update is that now you should annotate method parameters more specifically as `config: defaults.MkDocsConfig` instead of `config: base.Config`. This not only makes it clear that it is the [main config of MkDocs itself](https://github.com/mkdocs/mkdocs/blob/1.4.0/mkdocs/config/defaults.py), but also provides type-safe access through attributes of the object (see next section).
90+
91+
See [source code](https://github.com/mkdocs/mkdocs/blob/1.4.0/mkdocs/config/defaults.py) and [documentation](../dev-guide/plugins.md#on_event_name).
92+
93+
#### Rework ConfigOption schemas as class-based (#2962)
94+
95+
When developing a plugin, the settings that it accepts used to be specified in the `config_scheme` variable on the plugin class.
96+
This approach is now soft-deprecated, and instead you should specify the config in a sub-class of `base.Config`.
97+
98+
Old example:
99+
100+
```python
101+
from mkdocs import plugins
102+
from mkdocs.config import base, config_options
103+
104+
class MyPlugin(plugins.BasePlugin):
105+
config_scheme = (
106+
('foo', config_options.Type(int)),
107+
('bar', config_options.Type(str, default='')),
108+
)
109+
110+
def on_page_markdown(self, markdown: str, *, config: base.Config, **kwargs):
111+
if self.config['foo'] < 5:
112+
if config['site_url'].startswith('http:'):
113+
return markdown + self.config['baz']
114+
```
115+
116+
This code snippet actually has many mistakes but it will pass all type checks and silently run and even succeed in some cases.
117+
118+
So, on to the new equivalent example, changed to new-style schema and attribute-based access:
119+
(Complaints from "mypy" added inline)
120+
121+
```python
122+
from mkdocs import plugins
123+
from mkdocs.config import base, config_options as c
124+
125+
class MyPluginConfig(base.Config):
126+
foo = c.Optional(c.Type(int))
127+
bar = c.Type(str, default='')
128+
129+
class MyPlugin(plugins.BasePlugin[MyPluginConfig]):
130+
def on_page_markdown(self, markdown: str, *, config: base.MkDocsConfig, **kwargs):
131+
if self.config.foo < 5: # Error, `foo` might be `None`, need to check first.
132+
if config.site_url.startswith('http:'): # Error, MkDocs' `site_url` also might be `None`.
133+
return markdown + self.config.baz # Error, no such attribute `baz`!
134+
```
135+
136+
This lets you notice the errors from a static type checker before running the code and fix them as such:
137+
138+
```python
139+
class MyPlugin(plugins.BasePlugin[MyPluginConfig]):
140+
def on_page_markdown(self, markdown: str, *, config: base.MkDocsConfig, **kwargs):
141+
if self.config.foo is not None and self.config.foo < 5: # OK, `int < int` is valid.
142+
if (config.site_url or '').startswith('http:'): # OK, `str.startswith(str)` is valid.
143+
return markdown + self.config.bar # OK, `str + str` is valid.
144+
```
145+
146+
See [**documentation**](../dev-guide/plugins.md#config_scheme).
147+
148+
Also notice that we had to explicitly mark the config attribute `foo` as `Optional`.
149+
The new-style config has all attributes marked as required by default, and specifying `required=False` or `required=True` is not allowed!
150+
151+
##### New: `config_options.Optional` (#2962)
152+
153+
Wrapping something into `Optional` is conceptually similar to "I want the default to be `None`" -- and you *have* to express it like that, because writing `default=None` doesn't actually work.
154+
155+
Breaking change: the method `BaseConfigOption.is_required()` was removed. Use `.required` instead. (#2938)
156+
And even the `required` property should be mostly unused now.
157+
For class-based configs, there's a new definition for whether an option is "required":
158+
159+
* It has no default, and
160+
* It is not wrapped into `config_options.Optional`.
161+
162+
##### New: `config_options.ListOfItems` (#2938)
163+
164+
Defines a list of items that each must adhere to the same constraint. Kind of like a validated `Type(list)`
165+
166+
Examples how to express a list of integers (with `from mkdocs.config import config_options as c`):
167+
168+
Description | Code entry
169+
----------- | ----------
170+
Required to specify | `foo = c.ListOfItems(c.Type(int))`
171+
Optional, default is [] | `foo = c.ListOfItems(c.Type(int), default=[])`
172+
Optional, default is None | `foo = c.Optional(c.ListOfItems(c.Type(int)))`
173+
174+
See more [examples in **documentation**](../dev-guide/plugins.md#examples-of-config-definitions).
175+
176+
##### Updated: `config_options.SubConfig` (#2807)
177+
178+
`SubConfig` used to silently ignore all validation of its config options. Now you should pass `validate=True` to it or just use new class-based configs where this became the default.
179+
180+
So, it can be used to validate a nested sub-dict with all keys pre-defined and value types strictly validated.
181+
182+
See [examples in **documentation**](../dev-guide/plugins.md#examples-of-config-definitions).
183+
184+
#### Other changes to config options
185+
186+
`URL`'s default is now `None` instead of `''`. This can still be checked for truthiness in the same way - `if config.some_url:` (#2962)
187+
188+
`FilesystemObject` is no longer abstract and can be used directly, standing for "file or directory" with optional existence checking (#2938)
189+
190+
Bug fixes:
191+
192+
* Fix `SubConfig`, `ConfigItems`, `MarkdownExtensions` to not leak values across different instances (#2916, #2290)
193+
* `SubConfig` raises the correct kind of validation error without a stack trace (#2938)
194+
* Fix dot-separated redirect in `config_options.Deprecated(moved_to)` (#2963)
195+
196+
Tweaked logic for handling `ConfigOption.default` (#2938)
197+
198+
Deprecated config option classes: `ConfigItems` (#2983), `OptionallyRequired` (#2962), `RepoURL` (#2927)
199+
200+
### Theme updates
201+
202+
* Styles of admonitions in "MkDocs" theme (#2981):
203+
* Update colors to increase contrast
204+
* Apply admonition styles also to `<details>` tag, to support Markdown extensions that provide it ([pymdownx.details](https://facelessuser.github.io/pymdown-extensions/extensions/details/), [callouts](https://oprypin.github.io/markdown-callouts/#collapsible-blocks))
205+
206+
* Built-in themes now also support these languages:
207+
* Russian (#2976)
208+
* Turkish (Turkey) (#2946)
209+
* Ukrainian (#2980)
210+
211+
### Future compatibility
212+
213+
* `extra_css:` and `extra_javascript:` warn if a backslash `\` is passed to them. (#2930, #2984)
214+
215+
* Show `DeprecationWarning`s as INFO messages. (#2907)
216+
217+
If any plugin or extension that you use relies on deprecated functionality of other libraries, it is at risk of breaking in the near future. Plugin developers should address these in a timely manner.
218+
219+
* Avoid a dependency on `importlib_metadata` starting from Python 3.10 (#2959)
220+
221+
* Drop support for Python 3.6 (#2948)
222+
223+
#### Incompatible changes to public APIs
224+
225+
* `mkdocs.utils`:
226+
* `create_media_urls` and `normalize_url` warn if a backslash `\` is passed to them. (#2930)
227+
* `is_markdown_file` stops accepting case-insensitive variants such as `.MD`, which is how MkDocs build was already operating. (#2912)
228+
* Hard-deprecated: `modified_time`, `reduce_list`, `get_html_path`, `get_url_path`, `is_html_file`, `is_template_file`. (#2912)
229+
230+
### Miscellaneous
231+
232+
* If a plugin adds paths to `watch` in `LiveReloadServer`, it can now `unwatch` them. (#2777)
233+
234+
* Bugfix (regression in 1.2): Support listening on an IPv6 address in `mkdocs serve`. (#2951)
235+
236+
Other small improvements; see [commit log](https://github.com/mkdocs/mkdocs/compare/1.3.1...1.4.0).
237+
30238
## Version 1.3.1 (2022-07-19)
31239

32240
* Pin Python-Markdown version to &lt;3.4, thus excluding its latest release that breaks too many external extensions (#2893)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ markdown_extensions:
3333
permalink:
3434
- attr_list
3535
- def_list
36+
- tables
3637
- pymdownx.highlight:
3738
use_pygments: false
3839
- pymdownx.snippets

mkdocs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
# For acceptable version formats, see https://www.python.org/dev/peps/pep-0440/
5-
__version__ = '1.3.1'
5+
__version__ = '1.4.0'

0 commit comments

Comments
 (0)