Skip to content

Commit f3d1fcd

Browse files
Merge pull request #65 from nexB/add-docs-contrib
Add documentation contribute page
2 parents 2841270 + 5556e71 commit f3d1fcd

File tree

4 files changed

+319
-17
lines changed

4 files changed

+319
-17
lines changed
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
.. _contrib_doc_dev:
2+
3+
Contributing to the Documentation
4+
=================================
5+
6+
.. _contrib_doc_setup_local:
7+
8+
Setup Local Build
9+
-----------------
10+
11+
To get started, create or identify a working directory on your local machine.
12+
13+
Open that directory and execute the following command in a terminal session::
14+
15+
git clone https://github.com/nexB/skeleton.git
16+
17+
That will create an ``/skeleton`` directory in your working directory.
18+
Now you can install the dependencies in a virtualenv::
19+
20+
cd skeleton
21+
./configure --docs
22+
23+
.. note::
24+
25+
In case of windows, run ``configure --docs`` instead of this.
26+
27+
Now, this will install the following prerequisites:
28+
29+
- Sphinx
30+
- sphinx_rtd_theme (the format theme used by ReadTheDocs)
31+
- docs8 (style linter)
32+
33+
These requirements are already present in setup.cfg and `./configure --docs` installs them.
34+
35+
Now you can build the HTML documents locally::
36+
37+
source venv/bin/activate
38+
cd docs
39+
make html
40+
41+
Assuming that your Sphinx installation was successful, Sphinx should build a local instance of the
42+
documentation .html files::
43+
44+
open build/html/index.html
45+
46+
.. note::
47+
48+
In case this command did not work, for example on Ubuntu 18.04 you may get a message like “Couldn’t
49+
get a file descriptor referring to the console”, try:
50+
51+
::
52+
53+
see build/html/index.html
54+
55+
You now have a local build of the AboutCode documents.
56+
57+
.. _contrib_doc_share_improvements:
58+
59+
Share Document Improvements
60+
---------------------------
61+
62+
Ensure that you have the latest files::
63+
64+
git pull
65+
git status
66+
67+
Before commiting changes run Continious Integration Scripts locally to run tests. Refer
68+
:ref:`doc_ci` for instructions on the same.
69+
70+
Follow standard git procedures to upload your new and modified files. The following commands are
71+
examples::
72+
73+
git status
74+
git add source/index.rst
75+
git add source/how-to-scan.rst
76+
git status
77+
git commit -m "New how-to document that explains how to scan"
78+
git status
79+
git push
80+
git status
81+
82+
The Scancode-Toolkit webhook with ReadTheDocs should rebuild the documentation after your
83+
Pull Request is Merged.
84+
85+
Refer the `Pro Git Book <https://git-scm.com/book/en/v2/>`_ available online for Git tutorials
86+
covering more complex topics on Branching, Merging, Rebasing etc.
87+
88+
.. _doc_ci:
89+
90+
Continuous Integration
91+
----------------------
92+
93+
The documentations are checked on every new commit through Travis-CI, so that common errors are
94+
avoided and documentation standards are enforced. Travis-CI presently checks for these 3 aspects
95+
of the documentation :
96+
97+
1. Successful Builds (By using ``sphinx-build``)
98+
2. No Broken Links (By Using ``link-check``)
99+
3. Linting Errors (By Using ``Doc8``)
100+
101+
So run these scripts at your local system before creating a Pull Request::
102+
103+
cd docs
104+
./scripts/sphinx_build_link_check.sh
105+
./scripts/doc8_style_check.sh
106+
107+
If you don't have permission to run the scripts, run::
108+
109+
chmod u+x ./scripts/doc8_style_check.sh
110+
111+
.. _doc_style_docs8:
112+
113+
Style Checks Using ``Doc8``
114+
---------------------------
115+
116+
How To Run Style Tests
117+
^^^^^^^^^^^^^^^^^^^^^^
118+
119+
In the project root, run the following commands::
120+
121+
$ cd docs
122+
$ ./scripts/doc8_style_check.sh
123+
124+
A sample output is::
125+
126+
Scanning...
127+
Validating...
128+
docs/source/misc/licence_policy_plugin.rst:37: D002 Trailing whitespace
129+
docs/source/misc/faq.rst:45: D003 Tabulation used for indentation
130+
docs/source/misc/faq.rst:9: D001 Line too long
131+
docs/source/misc/support.rst:6: D005 No newline at end of file
132+
========
133+
Total files scanned = 34
134+
Total files ignored = 0
135+
Total accumulated errors = 326
136+
Detailed error counts:
137+
- CheckCarriageReturn = 0
138+
- CheckIndentationNoTab = 75
139+
- CheckMaxLineLength = 190
140+
- CheckNewlineEndOfFile = 13
141+
- CheckTrailingWhitespace = 47
142+
- CheckValidity = 1
143+
144+
Now fix the errors and run again till there isn't any style error in the documentation.
145+
146+
What is Checked?
147+
^^^^^^^^^^^^^^^^
148+
149+
PyCQA is an Organization for code quality tools (and plugins) for the Python programming language.
150+
Doc8 is a sub-project of the same Organization. Refer this `README <https://github.com/PyCQA/doc8/blob/master/README.rst>`_ for more details.
151+
152+
What is checked:
153+
154+
- invalid rst format - D000
155+
- lines should not be longer than 100 characters - D001
156+
157+
- RST exception: line with no whitespace except in the beginning
158+
- RST exception: lines with http or https URLs
159+
- RST exception: literal blocks
160+
- RST exception: rst target directives
161+
162+
- no trailing whitespace - D002
163+
- no tabulation for indentation - D003
164+
- no carriage returns (use UNIX newlines) - D004
165+
- no newline at end of file - D005
166+
167+
.. _doc_interspinx:
168+
169+
Interspinx
170+
----------
171+
172+
ScanCode toolkit documentation uses `Intersphinx <http://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html>`_
173+
to link to other Sphinx Documentations, to maintain links to other Aboutcode Projects.
174+
175+
To link sections in the same documentation, standart reST labels are used. Refer
176+
`Cross-Referencing <http://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#ref-role>`_ for more information.
177+
178+
For example::
179+
180+
.. _my-reference-label:
181+
182+
Section to cross-reference
183+
--------------------------
184+
185+
This is the text of the section.
186+
187+
It refers to the section itself, see :ref:`my-reference-label`.
188+
189+
Now, using Intersphinx, you can create these labels in one Sphinx Documentation and then referance
190+
these labels from another Sphinx Documentation, hosted in different locations.
191+
192+
You just have to add the following in the ``conf.py`` file for your Sphinx Documentation, where you
193+
want to add the links::
194+
195+
extensions = [
196+
'sphinx.ext.intersphinx'
197+
]
198+
199+
intersphinx_mapping = {'aboutcode': ('https://aboutcode.readthedocs.io/en/latest/', None)}
200+
201+
To show all Intersphinx links and their targets of an Intersphinx mapping file, run::
202+
203+
python -msphinx.ext.intersphinx https://aboutcode.readthedocs.io/en/latest/objects.inv
204+
205+
.. WARNING::
206+
207+
``python -msphinx.ext.intersphinx https://aboutcode.readthedocs.io/objects.inv`` will give
208+
error.
209+
210+
This enables you to create links to the ``aboutcode`` Documentation in your own Documentation,
211+
where you modified the configuration file. Links can be added like this::
212+
213+
For more details refer :ref:`aboutcode:doc_style_guide`.
214+
215+
You can also not use the ``aboutcode`` label assigned to all links from aboutcode.readthedocs.io,
216+
if you don't have a label having the same name in your Sphinx Documentation. Example::
217+
218+
For more details refer :ref:`doc_style_guide`.
219+
220+
If you have a label in your documentation which is also present in the documentation linked by
221+
Intersphinx, and you link to that label, it will create a link to the local label.
222+
223+
For more information, refer this tutorial named
224+
`Using Intersphinx <https://my-favorite-documentation-test.readthedocs.io/en/latest/using_intersphinx.html>`_.
225+
226+
.. _doc_style_conv:
227+
228+
Style Conventions for the Documentaion
229+
--------------------------------------
230+
231+
1. Headings
232+
233+
(`Refer <http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#sections>`_)
234+
Normally, there are no heading levels assigned to certain characters as the structure is
235+
determined from the succession of headings. However, this convention is used in Python’s Style
236+
Guide for documenting which you may follow:
237+
238+
# with overline, for parts
239+
240+
* with overline, for chapters
241+
242+
=, for sections
243+
244+
-, for subsections
245+
246+
^, for sub-subsections
247+
248+
", for paragraphs
249+
250+
2. Heading Underlines
251+
252+
Do not use underlines that are longer/shorter than the title headline itself. As in:
253+
254+
::
255+
256+
Correct :
257+
258+
Extra Style Checks
259+
------------------
260+
261+
Incorrect :
262+
263+
Extra Style Checks
264+
------------------------
265+
266+
.. note::
267+
268+
Underlines shorter than the Title text generates Errors on sphinx-build.
269+
270+
271+
3. Internal Links
272+
273+
Using ``:ref:`` is advised over standard reStructuredText links to sections (like
274+
```Section title`_``) because it works across files, when section headings are changed, will
275+
raise warnings if incorrect, and works for all builders that support cross-references.
276+
However, external links are created by using the standard ```Section title`_`` method.
277+
278+
4. Eliminate Redundancy
279+
280+
If a section/file has to be repeated somewhere else, do not write the exact same section/file
281+
twice. Use ``.. include: ../README.rst`` instead. Here, ``../`` refers to the documentation
282+
root, so file location can be used accordingly. This enables us to link documents from other
283+
upstream folders.
284+
285+
5. Using ``:ref:`` only when necessary
286+
287+
Use ``:ref:`` to create internal links only when needed, i.e. it is referenced somewhere.
288+
Do not create references for all the sections and then only reference some of them, because
289+
this created unnecessary references. This also generates ERROR in ``restructuredtext-lint``.
290+
291+
6. Spelling
292+
293+
You should check for spelling errors before you push changes. `Aspell <http://aspell.net/>`_
294+
is a GNU project Command Line tool you can use for this purpose. Download and install Aspell,
295+
then execute ``aspell check <file-name>`` for all the files changed. Be careful about not
296+
changing commands or other stuff as Aspell gives prompts for a lot of them. Also delete the
297+
temporary ``.bak`` files generated. Refer the `manual <http://aspell.net/man-html/>`_ for more
298+
information on how to use.
299+
300+
7. Notes and Warning Snippets
301+
302+
Every ``Note`` and ``Warning`` sections are to be kept in ``rst_snippets/note_snippets/`` and
303+
``rst_snippets/warning_snippets/`` and then included to eliminate redundancy, as these are
304+
frequently used in multiple files.
305+
306+
Converting from Markdown
307+
------------------------
308+
309+
If you want to convert a ``.md`` file to a ``.rst`` file, this `tool <https://github.com/chrissimpkins/md2rst>`_
310+
does it pretty well. You'd still have to clean up and check for errors as this contains a lot of
311+
bugs. But this is definitely better than converting everything by yourself.
312+
313+
This will be helpful in converting GitHub wiki's (Markdown Files) to reStructuredtext files for
314+
Sphinx/ReadTheDocs hosting.

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Welcome to nexb-skeleton's documentation!
55
:maxdepth: 2
66
:caption: Contents:
77

8-
skeleton/index
8+
skeleton-usage
9+
contribute/contrib_doc
910

1011
Indices and tables
1112
==================

docs/skeleton-usage.rst renamed to docs/source/skeleton-usage.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ To generate requirements.txt:
7373
7474
python etc/scripts/gen_requirements.py -s venv/lib/python<version>/site-packages/
7575
76-
Replace \<version\> with the version number of the Python being used, for example: ``venv/lib/python3.6/site-packages/``
76+
Replace \<version\> with the version number of the Python being used, for example:
77+
``venv/lib/python3.6/site-packages/``
7778

7879
To generate requirements-dev.txt after requirements.txt has been generated:
7980

8081
.. code-block:: bash
82+
8183
./configure --dev
8284
python etc/scripts/gen_requirements_dev.py -s venv/lib/python<version>/site-packages/
8385

docs/source/skeleton/index.rst

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)