Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contributing to MkDocs
2
3 An introduction to contributing to the MkDocs project.
4
5 The MkDocs project welcomes contributions from developers and
6 users in the open source community. Contributions can be made in a number of
7 ways, a few examples are:
8
9 - Code patches via pull requests
10 - Documentation improvements
11 - Bug reports and patch reviews
12
13 For information about available communication channels please refer to the
14 [README](https://github.com/mkdocs/mkdocs#readme) file in our
15 GitHub repository.
16
17 ## Reporting an Issue
18
19 Please include as much detail as you can. Let us know your platform and MkDocs
20 version. If the problem is visual (for example a theme or design issue), please
21 add a screenshot. If you get an error, please include the full error message and
22 traceback.
23
24 It is particularly helpful if an issue report touches on all of these aspects:
25
26 1. What are you trying to achieve?
27
28 2. What is your `mkdocs.yml` configuration (+ other relevant files)? Preferably reduced to the minimal reproducible example.
29
30 3. What did you expect to happen when applying this setup?
31
32 4. What happened instead and how didn't it match your expectation?
33
34 ## Trying out the Development Version
35
36 If you want to just install and try out the latest development version of
37 MkDocs (in case it already contains a fix for your issue),
38 you can do so with the following command. This can be useful if you
39 want to provide feedback for a new feature or want to confirm if a bug you
40 have encountered is fixed in the git master. It is **strongly** recommended
41 that you do this within a [virtualenv].
42
43 ```bash
44 pip install git+https://github.com/mkdocs/mkdocs.git
45 ```
46
47 ## Installing for Development
48
49 Note that for development you can just use [Hatch] directly as described below. If you wish to install a local clone of MkDocs anyway, you can run `pip install --editable .`. It is **strongly** recommended that you do this within a [virtualenv].
50
51 ## Installing Hatch
52
53 The main tool that is used for development is [Hatch]. It manages dependencies (in a virtualenv that is created on the fly) and is also the command runner.
54
55 So first, [install it][install Hatch]. Ideally in an isolated way with **`pipx install hatch`** (after [installing `pipx`]), or just `pip install hatch` as a more well-known way.
56
57 ## Running all checks
58
59 To run **all** checks that are required for MkDocs, just run the following command in the cloned MkDocs repository:
60
61 ```bash
62 hatch run all
63 ```
64
65 **This will encompass all of the checks mentioned below.**
66
67 All checks need to pass.
68
69 ### Running tests
70
71 To run the test suite for MkDocs, run the following commands:
72
73 ```bash
74 hatch run test:test
75 hatch run integration:test
76 ```
77
78 It will attempt to run the tests against all of the Python versions we
79 support. So don't be concerned if you are missing some. The rest
80 will be verified by [GitHub Actions] when you submit a pull request.
81
82 ### Python code style
83
84 Python code within MkDocs' code base is formatted using [Black] and [Isort] and lint-checked using [Ruff], all of which are configured in `pyproject.toml`.
85
86 You can automatically check and format the code according to these tools with the following command:
87
88 ```bash
89 hatch run style:fix
90 ```
91
92 The code is also type-checked using [mypy] - also configured in `pyproject.toml`, it can be run like this:
93
94 ```bash
95 hatch run types:check
96 ```
97
98 ### Other style checks
99
100 There are several other checks, such as spelling and JS style. To run all of them, use this command:
101
102 ```bash
103 hatch run lint:check
104 ```
105
106 ### Documentation of MkDocs itself
107
108 After making edits to files under the `docs/` dir, you can preview the site locally using the following command:
109
110 ```bash
111 hatch run docs:serve
112 ```
113
114 Note that any 'WARNING' should be resolved before submitting a contribution.
115
116 Documentation files are also checked by markdownlint, so you should run this as well:
117
118 ```bash
119 hatch run lint:check
120 ```
121
122 If you add a new plugin to mkdocs.yml, you don't need to add it to any "requirements" file, because that is managed automatically.
123
124 > INFO: If you don't want to use Hatch, for documentation you can install requirements into a virtualenv, in one of these ways (with `.venv` being the virtualenv directory):
125 >
126 > ```bash
127 > .venv/bin/pip install -r requirements/requirements-docs.txt # Exact versions of dependencies.
128 > .venv/bin/pip install -r $(mkdocs get-deps) # Latest versions of all dependencies.
129 > ```
130
131 ## Translating themes
132
133 To localize a theme to your favorite language, follow the guide on [Translating Themes]. We welcome translation pull requests!
134
135 ## Submitting Pull Requests
136
137 If you're considering a large code contribution to MkDocs, please prefer to
138 open an issue first to get early feedback on the idea.
139
140 Once you think the code is ready to be reviewed, push
141 it to your fork and send a pull request. For a change to be accepted it will
142 most likely need to have tests and documentation if it is a new feature.
143
144 When working with a pull request branch:
145 Unless otherwise agreed, prefer `commit` over `amend`, and `merge` over `rebase`. Avoid force-pushes, otherwise review history is much harder to navigate. For the end result, the "unclean" history is fine because most pull requests are squash-merged on GitHub.
146
147 Do *not* add to *release-notes.md*, this will be written later.
148
149 ### Submitting changes to the builtin themes
150
151 When installed with `i18n` support (`pip install 'mkdocs[i18n]'`), MkDocs allows
152 themes to support being translated into various languages (referred to as
153 locales) if they respect [Jinja's i18n extension] by wrapping text placeholders
154 with `{% trans %}` and `{% endtrans %}` tags.
155
156 Each time a translatable text placeholder is added, removed or changed in a
157 theme template, the theme's Portable Object Template (`pot`) file needs to be
158 updated by running the `extract_messages` command. To update the
159 `pot` file for both built-in themes, run these commands:
160
161 ```bash
162 pybabel extract --project=MkDocs --copyright-holder=MkDocs --msgid-bugs-address='https://github.com/mkdocs/mkdocs/issues' --no-wrap --version="$(hatch version)" --mapping-file mkdocs/themes/babel.cfg --output-file mkdocs/themes/mkdocs/messages.pot mkdocs/themes/mkdocs
163 pybabel extract --project=MkDocs --copyright-holder=MkDocs --msgid-bugs-address='https://github.com/mkdocs/mkdocs/issues' --no-wrap --version="$(hatch version)" --mapping-file mkdocs/themes/babel.cfg --output-file mkdocs/themes/readthedocs/messages.pot mkdocs/themes/readthedocs
164 ```
165
166 The updated `pot` file should be included in a PR with the updated template.
167 The updated `pot` file will allow translation contributors to propose the
168 translations needed for their preferred language. See the guide on [Translating
169 Themes] for details.
170
171 NOTE:
172 Contributors are not expected to provide translations with their changes to
173 a theme's templates. However, they are expected to include an updated `pot`
174 file so that everything is ready for translators to do their job.
175
176 ## Code of Conduct
177
178 Everyone interacting in the MkDocs project's codebases, issue trackers, chat
179 rooms, and mailing lists is expected to follow the [PyPA Code of Conduct].
180
181 [virtualenv]: https://virtualenv.pypa.io/en/latest/user_guide.html
182 [Hatch]: https://hatch.pypa.io/
183 [install Hatch]: https://hatch.pypa.io/latest/install/#pip
184 [installing `pipx`]: https://pypa.github.io/pipx/installation/
185 [GitHub Actions]: https://docs.github.com/actions
186 [PyPA Code of Conduct]: https://www.pypa.io/en/latest/code-of-conduct/
187 [Translating Themes]: https://www.mkdocs.org/dev-guide/translations/
188 [Jinja's i18n extension]: https://jinja.palletsprojects.com/en/latest/extensions/#i18n-extension
189 [Ruff]: https://docs.astral.sh/ruff/
190 [Black]: https://black.readthedocs.io/
191 [Isort]: https://pycqa.github.io/isort/
192 [mypy]: https://mypy-lang.org/