Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add readthedocs config file #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jhlegarreta
Copy link
Contributor

@jhlegarreta jhlegarreta commented Feb 6, 2023

  • ENH: Add readthedocs config file
  • ENH: Add the numpydoc extension to process the docstrings

@github-actions github-actions bot added the type:enhancement New feature or request label Feb 6, 2023
@github-actions github-actions bot added type:enhancement New feature or request and removed type:enhancement New feature or request labels Feb 6, 2023
@jhlegarreta
Copy link
Contributor Author

jhlegarreta commented Feb 6, 2023

Building the documentation is failing since we modernized the package setup using pyproject.toml:
https://readthedocs.org/projects/tractolearn/builds/19396465/

The issue lies in the tomli package not being installed when building the documentation. It is required from:
https://github.com/scil-vital/tractolearn/blob/main/doc/conf.py#L15
so that the package metadata can be parsed:
https://github.com/scil-vital/tractolearn/blob/main/doc/conf.py#L23

Python seems to install it when executing the pyproject.toml, probably through the setuptools_scm requirement.

Now, if one installs tomli manually, and then sphinx-rtd-theme, the process fails because Sphinx seems to be unable to get the version using https://github.com/scil-vital/tractolearn/blob/main/doc/conf.py#L33, and fails with

(...)
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

Manually specifying a version makes the documentation build process partially succeed (the process exists successfully, but no content is added to the TOC/the index.html page only contains the welcome heading from index.rst; but that may be a separate issue).

There may be 2 solutions to the version issue (removing from importlib.metadata import version from https://github.com/scil-vital/tractolearn/blob/main/doc/conf.py#L16 in either case):

  • Use from setuptools_scm import get_version and then _version = get_version(), assuming setuptools_scm is installed, and then assuming tractolearn gets installed by Sphinx prior to generating the documentation.
  • Use
import tractolearn
_version = tractolearn.__version__

which also assumes that tractolearn gets installed.

In either case, it looks like in order to build the doc, we need to add to pyproject.toml a section with the documentation dependencies:

doc = [
 "sphinx",
 "sphinx-rtd-theme",
 "tomli",
]

and then add to conf.py:

python:
  install:
    - method: pip
      path: .
      extra_requirements:
        - doc

following https://docs.readthedocs.io/en/stable/config-file/v2.html#packages.

Add `readthedocs` config file.

Specifically:
- Set the Python version to 3.8, as the default version `readthedocs` is
curreently using is 3.7, whose EOL is only 4 months away.
- List the dependencies to be able to build the documentation in the
`pyproject.toml` file.
- Read the package version in the documentation configuration `conf.py`
file using `pkg_resources`.
Add the `numpydoc` extension to process the docstrings, which are
written according to the `Numpy` convention.
@github-actions github-actions bot added type:documentation Improvements or additions to documentation type:enhancement New feature or request and removed type:enhancement New feature or request labels Feb 7, 2023
@jhlegarreta
Copy link
Contributor Author

I found a way to get the version string. The documentation's first steps now work locally:

python -m sphinx -T -E -b html -d _build/doctrees -D language=en . ../_readthedocs/html

I did not go further/did not complete all steps that the successful readthedocs builds do. There are some warnings about the contents of index.rst. They require further investigation/probably it is best to address them separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:documentation Improvements or additions to documentation type:enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant