Debian Codegraph @

docs/contributing.rst

raw
1 ************
2 Contributing
3 ************
4
5 This project follows the Read the Docs :doc:`code of conduct
6 <rtd-dev:code-of-conduct>`. If you are not familiar with our code of conduct policy,
7 take a minute to read the policy before starting with your first contribution.
8
9 .. tip::
10 There is a new dockerized build environment, see :ref:`dockerized-build`.
11
12 Modifying the theme
13 ===================
14
15 The styles for this theme use SASS_ and a custom CSS framework called Wyrm_. We
16 use Webpack_ and node-sass_ to build the CSS. Webpack_ is used to watch for
17 changes, rebuild the static assets, and rebuild the Sphinx demo documentation.
18
19 .. note::
20 The installation of Node is outside the scope of this documentation. You
21 will need Node version 10+ in order to make changes to this theme.
22
23 Set up your environment
24 -----------------------
25
26 #. Install Sphinx_ and documentation build dependencies.
27
28 .. code:: console
29
30 $ pip install -e '.[dev]'
31
32 #. Install Webpack_, node-sass_, and theme dependencies locally.
33
34 .. code:: console
35
36 $ npm install
37
38 Making changes
39 --------------
40
41 Changes to the theme can be compiled and tested with Webpack_:
42
43 .. code:: console
44
45 $ npm run dev
46
47 This script will do the following:
48
49 #. Install and update any dependencies.
50 #. Build the static CSS from SASS source files.
51 #. Build the demo documentation.
52 #. Watch for changes to the SASS files and documentation and rebuild everything
53 on any detected changes.
54
55 Alternatively, if you don't need to watch the files, the release build script
56 can be used to test built assets:
57
58 .. code:: console
59
60 $ npm run build
61
62 .. _Webpack: https://webpack.js.org/
63 .. _node-sass: https://github.com/sass/node-sass
64 .. _SASS: http://www.sass-lang.com
65 .. _Wyrm: http://www.github.com/snide/wyrm/
66 .. _Sphinx: http://www.sphinx-doc.org/en/stable/
67
68
69 .. _dockerized-build:
70
71 Dockerized development
72 ======================
73
74 If you have Docker available on your platform, you can get started building CSS and JS artifacts a bit faster and won't have to worry about any of the setup spilling over into your general environment.
75
76 When building with Docker, we create an image containing the build dependencies. Some of these are quite outdated and therefore ideal to isolate a container. The image is tagged as ``sphinx_rtd_theme:latest``.
77
78 Inside the running docker image, we mount the working copy of the repository, build the artifacts and finally observe that the artifacts have been built and left in your current git checkout.
79
80 Use the following steps:
81
82 .. code-block:: console
83
84 # Builds an updated version of the docker image
85 $ docker-compose build
86
87 # Runs the development webserver
88 $ docker-compose run sphinx_rtd_theme dev
89
90 # If you want to copy stuff out of the Docker environment, run this make
91 # target or read the actual Makefile to see what is going on.
92 # We suggest running this command every time that you want to quickly build
93 # new CSS/JS assets
94 $ make docker-build-all
95
96 Every time you change the Node or Python requirements, you will need to rebuild images with ``docker-compose run sphinx_rtd_theme build``. If you change SASS or JS, you will need to rebuild assets.
97
98 Testing
99 =======
100
101 QA testing theme changes and pull requests is complex, due to backwards
102 compatibility.
103
104 The following cases need to be tested with changes to CSS or JavaScript:
105
106 * Multiple, modern browsers should be tested.
107 * Multiple viewport sizes should be tested for changes.
108 We support large, tablet, and mobile viewport sizes
109 * We currently support only HTML5 writer.
110 * Multiple major versions of Sphinx should be tested.
111 We currently support Sphinx ``>=6.0``
112
113 It's easiest to test combinations of dependency versions using ``tox``:
114
115 .. code:: console
116
117 % tox -e py312-sphinx74
118
119 If the tests and build are successful, you can view the built documentation at
120 the directory noted by Sphinx:
121
122 .. code:: console
123
124 build succeeded, 10 warnings.
125
126 The HTML pages are in .tox/py312-sphinx74/tmp/html.
127 ___________________________ summary ___________________________
128 py312-sphinx74: commands succeeded
129 congratulations :)
130
131 You can then open up this path with a series of browsers to test.
132
133 The best way to spot UI issues is to compare two or more builds. You can build
134 multiple ``tox`` environments, and open both up for comparison:
135
136 .. code:: console
137
138 % tox -e py312-sphinx62
139 ...
140 % tox -e py312-sphinx74
141 ...
142 % firefox .tox/py312-sphinx62/tmp/html/index.html
143 % firefox .tox/py312-sphinx74/tmp/html/index.html
144
145 You can also use a separate ``tox`` environment for building output to compare
146 against. All of the ``tox`` environments have an additional postfix, ``-qa``, to
147 allow building the same environment twice, without overwriting any files. In
148 this test scenario, you would build from a branch or tag before building the
149 same ``tox`` environment for the pull request branch you are testing.
150
151 For example, to test against the tag ``0.5.2``:
152
153 .. code:: console
154
155 % git checkout 0.5.2
156 % tox -e py310-sphinx53-qa
157 ...
158 % git checkout feature/example-pull-request
159 % tox -e py310-sphinx53
160 ...
161 % firefox .tox/py310-sphinx53-qa/tmp/html/index.html
162 % firefox .tox/py310-sphinx53/tmp/html/index.html
163
164 Currently, the most important environments to QA are:
165
166 .. This list is purposely shorter than what we describe above. If we test all of
167 the cases above, we'll be here all day. Python 3, and latest
168 minor of each major Sphinx release should give us enough work.
169
170 * ``py312-sphinx62``
171 * ``py312-sphinx74``
172 * ``py312-sphinx80``
173 * ``py312-sphinxlatest``
174 * ``py312-sphinxdev``
175
176 Translations
177 ============
178
179 Translations are managed using `Transifex`_. You can join any of the existing
180 language teams or request a new language is added to the project. For more
181 information on our translation standards, see our docs on
182 :doc:`rtd-dev:i18n`
183
184 Periodically, core team should update the translation files outside our normal
185 releases. Someone from the core team, with write access to Transifex, should run
186 the following:
187
188 .. code:: console
189
190 $ python setup.py update_translations
191
192 This will extract new messages, upload the messages to Transifex, and will
193 update our local translation files. Changes can be checked in to a branch and
194 put up for review.
195
196 .. _Transifex: https://www.transifex.com/readthedocs/sphinx-rtd-theme
197
198 Versioning
199 ==========
200
201 ..
202 TODO make these instructions organization wide. We've talked about
203 standardizing packaging version and tooling here (bumpver instead of
204 bump2version).
205
206 In between releases, the package version specified will always be a alpha
207 release, matching ``1.1.1alpha1``.
208
209 As pull requests are merged and the release impact changes, this version will
210 incremented ahead of release. For example, if we merge a new feature pull
211 request, we'd run ``bump2version minor`` to increment ``1.1.1alpha1`` to
212 ``1.2.0alpha1``.
213
214 To put out a release for testing, we will upload a release candidate. We would
215 run ``bump2version release`` to increment ``1.2.0alpha1`` to ``1.2.0rc1``.
216
217 After a testing period, the release candidate can become a full release. We
218 would run ``bump2version release`` again to increment ``1.2.0rc1`` to ``1.2.0``.
219
220 After the release process below, we increment the version again, so that the
221 development version -- the version found in the repository -- is always greater
222 than the most recent release. We follow up with another pull request by running
223 ``bump2version patch``, which increments ``1.2.0`` to ``1.2.1alpha1``.
224
225 Releasing the theme
226 ===================
227
228 To release a new version of the theme, core team will take the following steps:
229
230 #. Install the required depedencies with ``pip install '.[dev]'``.
231 #. Bump the version by running ``bump2version [major|minor|patch|dev]``.
232 This will automatically increase the correct part(s) of the version number,
233 you do not need to specify the exact version number.
234 We follow `semantic versioning`_ and `PEP440`_
235 (with regards to alpha release and development versions). The version
236 increment should reflect these releases and any potentially breaking changes.
237 #. New versions are by default ``alpha`` releases. If this is a release candidate,
238 run ``bump2version --allow-dirty release`` to update the release to an ``rc``
239 release. If this is a final release, run the command again.
240 #. Update the changelog (``docs/changelog.rst``) with the version information.
241 #. Run ``python setup.py update_translations`` to compile new translation files
242 and update Transifex.
243 #. Run ``npm install && npm run build`` to rebuild all the theme assets,
244 notice that ``package-lock.json`` will be updated with a new package
245 version. But take care that it isn't also bumping versions of dependencies
246 in ways that are risky to the release. *If* ``package-lock.json`` changes, you
247 need to commit it to git and tag it together with your release.
248 #. Commit these changes to a pull request.
249 #. Merge the pull request after review.
250 #. Check out ``master`` branch locally for tagging. **Remember to pull from remote**.
251 #. Tag the release in git: ``git tag $NEW_VERSION``.
252 #. Push the tag to GitHub: ``git push --tags origin``.
253 #. Upload the package to PyPI:
254
255 .. code:: console
256
257 $ rm -rf dist/
258 $ python setup.py sdist bdist_wheel
259 $ twine upload --sign --identity [email protected] dist/*
260
261 #. Finally, open a new pull request updating the development release version to
262 the next patch by running ``bump2version patch``. Open a pull request with
263 this change. See `Versioning`_ above for more details.
264
265 .. _PEP440: https://www.python.org/dev/peps/pep-0440/
266 .. _semantic versioning: http://semver.org/