Skip to content

Commit 9c2330e

Browse files
PipKatakaszynski
andauthored
Add error message guidelines and how to build a PDF locally (#45)
* Add link to Microsoft Error Messages guidelines and incorporate information on building a PDF of the documentation locally on Windows * Incorporate Pythonic message sources and edit logging content * Incorporate review comments * Apply suggestions from code review Add Linux PDF build link Co-authored-by: Alex Kaszynski <[email protected]> * Incorporate review comments * Update doc/source/guidelines/doc_practices.rst * Fix missing end-string Co-authored-by: Alex Kaszynski <[email protected]>
1 parent 270ceff commit 9c2330e

File tree

3 files changed

+342
-282
lines changed

3 files changed

+342
-282
lines changed

doc/source/guidelines/dev_practices.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ any new issues from your changes.
106106
107107
pytest -v --cov _unittest
108108
109+
Error Messages
110+
~~~~~~~~~~~~~~
111+
For general information on writting good error messages, see Microsoft's
112+
`Error Message Guidelines <https://docs.microsoft.com/en-us/windows/win32/debug/error-message-guidelines>`_.
113+
114+
For information specific to writing Pythonic error messages, see:
115+
116+
- `Python Exception Handling <https://www.codementor.io/@sheena/python-exception-handling-ogr0a41t7>`_
117+
- `7 Tips to Improve Your Error Handling in Python <https://pybit.es/articles/pythonic-exceptions/>`_
118+
119+
Additionally, ensure that you have reviewed this guide's :ref:`logging` topic.
120+
109121
Spelling and Code Style
110122
~~~~~~~~~~~~~~~~~~~~~~~
111123
If you are using Linux or Mac OS, run spelling and coding style checks:

doc/source/guidelines/doc_practices.rst

Lines changed: 160 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ key. To keep documentation up to date with rapdily evolving code:
1616
- Support contributions from both inside and outside of the development team
1717
- Perform periodic reviews
1818

19+
Understanding Documentation Sources
20+
------------------------------------
1921
The generation of PyAnsys documentation uses `Sphinx <https://www.sphinx-doc.org/en/master/>`__
2022
and an Ansys-branded theme (`pyansys-sphinx-theme <https://github.com/pyansys/pyansys-sphinx-theme>`_)
21-
to assemble content that comes from docstrings, reStructuredText (RST) files, and Python (PY)
22-
example files.
23+
to assemble content in:
24+
25+
- Docstrings
26+
- reStructuredText (RST) files
27+
- Python (PY) example files
2328

2429
Docstrings
25-
----------
30+
~~~~~~~~~~
2631
Docstrings must be formatted so that Sphinx can parse them. You can use either of these
2732
Sphinx extensions:
2833

@@ -46,9 +51,9 @@ recommend the use of numpy-style docstrings so that there is consistency
4651
across PyAnsys libraries. For more information, see :ref:`api_documentation`.
4752

4853
RST Files
49-
---------
54+
~~~~~~~~~
5055
To provide general usage information in your documentation, use your favorite editor to
51-
create RST files that you then place in the repository's ``doc/`` directory. The ``index.rst``
56+
create RST files that you then place in the repository's ``doc`` directory. The ``index.rst``
5257
file in the ``doc\source`` directory defines the first level of your documentation hierarchy.
5358
The ``toctree`` directive indicates the maximum number of heading levels that the documentation
5459
is to display. Below this directive are the directory names for your documentation sections.
@@ -80,7 +85,7 @@ guide.
8085

8186
Within RST files, heading titles are followed by a line having a string of characters that is
8287
the same length as the heading title. If the length of the characters
83-
under the heading title do not match the length of the heading title, Sphinx will generate a warning.
88+
under the heading title do not match the length of the heading title, Sphinx generates a warning.
8489

8590
For consistency within PyAnsys libraries, the use of these special characters is recommended for
8691
headings but are not enforced:
@@ -97,7 +102,7 @@ its HTML pages and then explore the RST files in its repository. This will help
97102
the syntax and see how RST files have been nested to create this guide.
98103

99104
Examples
100-
--------
105+
~~~~~~~~
101106
Examples come in two formats:
102107

103108
- Basic code snippets demonstrating some functionality
@@ -109,11 +114,9 @@ repository. All of these examples, which should be PEP 8-compliant, are compiled
109114
during the build process. Always ensure that your examples run properly locally because
110115
they will be verified through the CI performed via GitHub Actions.
111116

112-
Adding a New Example
113-
~~~~~~~~~~~~~~~~~~~~
114-
Adding a standalone example consists of placing it in an applicable subfolder in the ``examples``
117+
Adding a new standalone example consists of placing it in an applicable subdirectory in the ``examples``
115118
directory. If none of the existing directories match the category of your example, create
116-
a new subfolder with a ``README.txt`` file describing the new category. Because these examples
119+
a new subdirectory with a ``README.txt`` file describing the new category. Because these examples
117120
are built using the `Sphinx-Gallery <https://sphinx-gallery.github.io/stable/index.html>`_
118121
extension, you must follow its `coding guidelines <https://sphinx-gallery.github.io/stable/index.html>`_.
119122

@@ -124,100 +127,37 @@ Accessing a Library's Documentation
124127
Documentation for the latest stable release of a PyAnsys library is accessible
125128
from its repository. You can generally access the latest development version of the
126129
documentation tracking the ``main`` branch by adding the prefix ``dev.`` to
127-
the URL for the latest stable release. For example, consider PyAEDT documentation.
130+
the URL for the latest stable release.
131+
132+
For example, consider PyAEDT documentation:
128133

129134
- The URL for documentation of the latest stable release is `<https://aedtdocs.pyansys.com/>`_.
130135
- The URL for documentation of the lastest development version is `<https://dev.aedtdocs.pyansys.com/>`_.
131136

132137
The latest development versions of both the library and its documentation are automatically kept
133138
up-to-date via GitHub actions.
134139

135-
.. _doc_building:
136-
137-
Building Documentation Locally
138-
------------------------------
139-
You can build and verify the HTML documentation for a PyAnsys library locally
140-
by installing Sphinx and other documentation build dependencies.
141-
142-
Setting Up Your Machine
143-
~~~~~~~~~~~~~~~~~~~~~~~
144-
Anaconda provides Python and tools, such as a Python IDE (Interactive Development Environment),
145-
a Python command line editor, and Sphinx dependencies. This gives you what you need to get up
146-
and running.
147-
148-
#. Install the `Anaconda individual edition <https://www.anaconda.com/products/individual>`_.
149-
150-
#. If a PyAnsys library already exists, create a directory in which to place a clone of its GitHub repository.
151-
152-
#. Clone the PyAnsys library's GitHub repository. For more information, see :ref:`cloning`.
153-
154-
#. If you have not yet cloned the ``pyansys-sphinx-theme`` repository, clone it.
155-
156-
Installing Build Requirements
157-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158-
You can build documentation for the ``dev_guide`` and ``pyansys-sphinx-theme`` repositories without
159-
installing a PyAnsys library in development mode. However, when you push changes that you have made
160-
in a local branch to the GitHub repository for other PyAnsys libraries, CI checks typically require
161-
that the full library is installed.
162-
163-
#. In Anaconda Powershell, navigate to the base directory in the library's cloned repository.
164-
165-
#. If your library must be installed in development mode, enter:
166-
167-
.. code::
168-
169-
pip install -e .
170-
171-
#. To install the build requirements for generating documentation, enter:
172-
173-
.. code::
174-
175-
pip install -r requirements_docs.txt
176-
177-
#. If you are running on a Linux/Mac OS, to build the documentation, enter:
178-
179-
.. code::
140+
To make documentation changes, you create a branch with a name that begins with a prefix of
141+
``doc/`` that is then followed by a short description of what you are changing. For more
142+
information, see :ref:`branch_naming`.
180143

181-
make -C doc html
182-
183-
#. If you are running on Windows, to build the documentation, enter two
184-
commands:
185-
186-
.. code::
187-
188-
cd doc
189-
make.bat html
190-
191-
192-
As Sphinx is generating HTML output in the library's ``doc\_build\html`` folder,
193-
Anaconda Powershell displays any errors and warnings for unexpected indentations,
194-
bad target locations for links, missing files, and extra files included in the
195-
repository but not referenced by any ``index.rst`` file.
196-
197-
#. Resolve all indicated issues before submitting a pull request (PR) to push
198-
your changes to the library's GitHub repository.
199-
200-
#. After local documentation builds successfully, navigate to ``doc/_build/html/``
201-
and use your browser to open the ``index.html`` file to review the documentation,
202-
repeating the local build process until there are no errors or obvious issues.
203-
204-
.. note::
205-
You can use ``make.bat`` to build more than HTML output. To view a summary of
206-
all target options, enter ``make.bat``.
207-
208-
Your next step is to push your changes to the library's GitHub repository
209-
by creating a PR. For more information, see :ref:`create_pr`.
144+
As you are making changes in this branch, you want to periodically generate the documentation
145+
locally so that you can test your changes before you create a GitHub pull request. For more
146+
information, see :ref:`doc_building`. It is also possible for you to build a PDF
147+
of your documentation locally on Windows as described in :ref:`pdf_building`.
210148

211149
.. _cloning:
212150

213151
Cloning a GitHub Repository
214152
---------------------------
215-
While developers likely know how to clone a GitHub repository, technical documentation
216-
specialists may not know how to do this. You can easily use either Windows PowerShell
217-
or GitBash.
153+
Contributing to a GitHub repository requires that you first clone the repository. While developers
154+
likely know many ways to do this, technical documentation specialists may need to review the
155+
following instructions for using either Windows PowerShell or GitBash to clone a GitHub repository.
218156

219157
Using Windows PowerShell to Clone a GitHub Repository
220158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159+
To use Windows PowerShell to clone a GitHub repository:
160+
221161
#. In Windows PowerShell, navigate to the directory on your machine where you want
222162
to clone GitHub repositories.
223163

@@ -239,21 +179,22 @@ Using Windows PowerShell to Clone a GitHub Repository
239179

240180
#. Press ``Enter`` to copy the files in the repository to your local directory.
241181

242-
#. Type ``ls`` to see a list of the files now in the folder for this repository
243-
in your local directory.
182+
#. Type ``ls`` to see a list of the files now in your local directory.
244183

245184
.. note::
246185
In Anaconda Powershell, typing ``dir`` is the equivalent to typing ``ls``.
247186

248187
Using GitBash to Clone a GitHub Repository
249188
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189+
To use GitBash to clone a GitHub repository:
190+
250191
#. In the directory where you want to clone PyAnsys repositories, right-click and
251192
select ``GitBash Here``.
252193

253194
#. Type ``git clone`` followed by the address of the repo to clone.
254195

255-
For example, to clone the ``pyansys-sphinx-theme`` repository, you would
256-
type and enter:
196+
197+
For example, you clone the ``pyansys-sphinx-theme`` repository with:
257198

258199
.. code::
259200
@@ -263,13 +204,11 @@ type and enter:
263204

264205
Pushing Changes to the GitHub Repository
265206
----------------------------------------
266-
Once you have tested your changes in local documentation builds and are
267-
satisifed with them, you can push them to the library's GitHub repository.
268-
You can use Git commands or Git Extension to accomplish this.
269-
270-
For documentation changes, the branch name should always have a prefix of ``doc/``
271-
followed by a short description of what you've changed. For more information, see
272-
:ref:`branch_naming`.
207+
As you make changes in your ``doc/`` branch, you want to periodically test then in
208+
local documentation builds as described in :ref:`doc_building`. After you resolve
209+
any issues and are satisfied with what apears in a local build, you are ready
210+
to push your changes to the library's GitHub repository. To accomplish this,
211+
you can use either Git commands or Git Extensions.
273212

274213
Using Git Commands to Push Changes
275214
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -317,8 +256,7 @@ To use Git commands to push your changes to the GitHub repository:
317256
followed by the branch name.
318257

319258
For the given example, you would enter:
320-
321-
259+
322260
.. code::
323261
324262
git push --set-upstream origin doc/edit_contributing
@@ -356,6 +294,7 @@ To use Git Extensions to push your changes to the GitHub repository:
356294

357295
#. Create the PR as described in :ref:`create_pr`.
358296

297+
359298
.. _create_pr:
360299

361300
Creating the GitHub PR
@@ -378,3 +317,122 @@ the GitHub PR:
378317

379318
If you need to change a PR title, to its right, click the ``Edit`` button,
380319
which becomes a ``Save`` button while you are in editing mode.
320+
321+
.. _doc_building:
322+
323+
Building Documentation Locally
324+
------------------------------
325+
You can build and verify the HTML documentation for a PyAnsys library locally
326+
by installing Sphinx and other documentation build dependencies.
327+
328+
Setting Up Your Machine
329+
~~~~~~~~~~~~~~~~~~~~~~~
330+
Anaconda provides Python and tools, such as a Python IDE (Interactive Development Environment),
331+
a Python command line editor, and Sphinx dependencies. This gives you what you need to get up
332+
and running.
333+
334+
#. Install the `Anaconda individual edition <https://www.anaconda.com/products/individual>`_.
335+
336+
#. If a PyAnsys library already exists, create a directory in which to place a clone of its GitHub repository.
337+
338+
#. Clone the PyAnsys library's GitHub repository. For more information, see :ref:`cloning`.
339+
340+
#. If you have not yet cloned the `pyansys-sphinx-theme <https://github.com/pyansys/pyansys-sphinx-theme>`_
341+
repository, clone it.
342+
343+
Installing Build Requirements
344+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345+
You can build documentation for the `dev_guide <https://github.com/pyansys/dev-guide>`_
346+
and `pyansys-sphinx-theme <https://github.com/pyansys/pyansys-sphinx-theme>`_ repositories without
347+
installing a PyAnsys library in development mode. However, when you push changes that you have made
348+
in a local branch to the GitHub repository for other PyAnsys libraries, CI checks typically require
349+
that the full library is installed.
350+
351+
#. In Anaconda Powershell, navigate to the base directory in the library's cloned repository.
352+
353+
#. If your library must be installed in development mode, enter:
354+
355+
.. code::
356+
357+
pip install -e .
358+
359+
#. To install the build requirements for generating documentation, enter:
360+
361+
.. code::
362+
363+
pip install -r requirements_docs.txt
364+
365+
#. If you are running on a Linux/Mac OS, to build the documentation, enter:
366+
367+
.. code::
368+
369+
make -C doc html
370+
371+
#. If you are running on Windows, to build the documentation, enter two
372+
commands:
373+
374+
.. code::
375+
376+
cd doc
377+
.\make.bat html
378+
379+
380+
As Sphinx is generating HTML output in the library's ``../doc/_build/html`` directory,
381+
Anaconda Powershell displays any errors and warnings for unexpected indentations,
382+
bad target locations for links, missing files, and extra files included in the
383+
repository but not referenced by any ``index.rst`` file.
384+
385+
#. Resolve all indicated issues before submitting a pull request (PR) to push
386+
your changes to the library's GitHub repository.
387+
388+
#. After local documentation builds successfully, navigate to ``doc/_build/html/``
389+
and use your browser to open the ``index.html`` file to review the documentation,
390+
repeating the local build process until there are no errors or obvious issues.
391+
392+
.. note::
393+
You can use ``make.bat`` to build more than HTML output. To view a summary of
394+
all target options, enter ``make.bat``.
395+
396+
Your next step is to push your changes to the library's GitHub repository
397+
by creating a PR. For more information, see :ref:`create_pr`.
398+
399+
.. _pdf_building:
400+
401+
Building a PDF of Your Documentation Locally
402+
--------------------------------------------
403+
Some libraries supply a link to a PDF of the documentation under 'Assets' in the
404+
release notes for a version. On Linux, building this PDF can be done by following
405+
`these directions <https://sudonull.com/post/70830-How-to-make-LaTeX-and-PDF-generation-in-Sphinx>`_.
406+
On Windows, building a PDF is a manual process that you run locally:
407+
408+
#. Install `MiKTeX <https://miktex.org/download>`_ for Windows, selecting the
409+
recommended option for installing it for only your own use.
410+
#. From the Windows Start menu, start the MiKTeX Console.
411+
#. On the Welcome page, click ``Check for updates`` and install any available
412+
updates.
413+
#. Install the latest version of Strawbery Perl, which enables you to build
414+
LaTeX files, accepting the default installation location (``C:\Strawberry\``).
415+
#. In the Command Prompt window, type ``perl-v`` to test that your installation is
416+
successful.
417+
#. Ensure that these Perl directory locations have been added to your ``Path``
418+
system environment variable:
419+
420+
- C:/Strawberry/c/bin
421+
- C:/Strawberry/perl/site/bin
422+
- C:/Strawberry/perl/bin
423+
424+
425+
#. In Anaconda PowerShell, navigate to the ``doc`` directory with:
426+
427+
.. code::
428+
429+
cd C:\AnsysDev\GitRepos\PyAnsys\dev-guide\doc
430+
431+
432+
#. Generate LaTeX files and a PDF from these files in ``..\doc\build\latex``
433+
with:
434+
435+
.. code::
436+
437+
.\make latexpdf
438+

0 commit comments

Comments
 (0)