Skip to content

Commit

Permalink
docs: misc sphinx docs tidy-ups (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisimcevoy authored Jun 6, 2024
1 parent cbb04af commit ce56212
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ docs.sphinx.html:
# /docs/source for each public module in the pyoda_time package
# recursively. Those files will contain directives (e.g. :automodule:)
# which can later be handled by the autodoc extension.
# The default behaviour for sphinx-apidoc directs autodoc to include
# :members:, :undoc-members: and :show-inheritance:.
# We don't want inheritance to be shown, hence we explicitly set
# the SPHINX_APIDOC_OPTIONS environment variable as per the docs.
# https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html#envvar-SPHINX_APIDOC_OPTIONS
SPHINX_APIDOC_OPTIONS=members,undoc-members poetry run sphinx-apidoc -fe -d 1 -o docs/source pyoda_time pyoda_time/version.py
poetry run sphinx-apidoc -o docs/source pyoda_time

@echo "Building html docs with sphinx-autodoc"
# Uses the sphinx Makefile in /docs to build the documentation.
# The autodoc extension is enabled in /docs/conf.py.
# That extensions interprets the directives in the files which were
# generated by sphinx-apidoc in the previous command, allowing
# us to turn that into html documentation.
poetry run make -C docs html
poetry run make -C docs SPHINXOPTS=-W html
23 changes: 18 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_default_options
autodoc_class_signature = "separated"
autodoc_default_options = {
"show-inheritance": True,
"special-members": ",".join(
[
"__add__",
Expand Down Expand Up @@ -130,17 +131,29 @@ def process_metaclass_properties(
]

# Add the property docstring, formatted as reStructuredText field lists.
for line in property_docstring.splitlines():
for paragraph in property_docstring.split("\n\n"):
# Sphinx is really finicky about whitespace, so we
# need to take control of that here.
line = line.strip()
paragraph = paragraph.strip()

if line.startswith(":"):
if paragraph.startswith(":"):
# It's a field list, so we make sure it's properly indented.
doc_lines.append(f" {line}")
current_field = ""
for line in paragraph.splitlines():
line = line.strip()
if line.startswith(":"):
if current_field:
doc_lines.append(f" {current_field.strip()}")
current_field = line
else:
current_field += " " + line
doc_lines.append(f" {current_field.strip()}")

else:
# It's a regular line of the docstring, so we add it as is.
doc_lines.append(f" {line}")
paragraph = " ".join(line.strip() for line in paragraph.splitlines())
doc_lines.append(f" {paragraph}")

doc_lines.append("")

lines.extend(doc_lines)
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Welcome to Pyoda Time's documentation!
======================================

.. toctree::
:maxdepth: 2
:maxdepth: 4
:caption: Contents:

API Reference <pyoda_time>
modules



Expand Down
2 changes: 1 addition & 1 deletion docs/source/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pyoda_time
==========

.. toctree::
:maxdepth: 1
:maxdepth: 4

pyoda_time
2 changes: 1 addition & 1 deletion docs/source/pyoda_time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subpackages
-----------

.. toctree::
:maxdepth: 1
:maxdepth: 4

pyoda_time.calendars
pyoda_time.fields
Expand Down
2 changes: 1 addition & 1 deletion docs/source/pyoda_time.testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subpackages
-----------

.. toctree::
:maxdepth: 1
:maxdepth: 4

pyoda_time.testing.time_zones

Expand Down
2 changes: 1 addition & 1 deletion docs/source/pyoda_time.text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subpackages
-----------

.. toctree::
:maxdepth: 1
:maxdepth: 4

pyoda_time.text.patterns

Expand Down
2 changes: 1 addition & 1 deletion docs/source/pyoda_time.time_zones.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subpackages
-----------

.. toctree::
:maxdepth: 1
:maxdepth: 4

pyoda_time.time_zones.cldr
pyoda_time.time_zones.io
Expand Down
2 changes: 1 addition & 1 deletion pyoda_time/_calendar_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _get_year_month_day_calendar_from_days_since_epoch(self, days_since_epoch: i

# region object overrides

def __str__(self) -> str:
def __repr__(self) -> str:
"""Converts this calendar system to text by simply returning its unique ID."""
return self.id

Expand Down
2 changes: 0 additions & 2 deletions pyoda_time/_system_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class SystemClock(IClock, metaclass=__SystemClockMeta):
your application, which should only depend on the interface.
"""

instance: SystemClock

def get_current_instant(self) -> Instant:
"""Gets the current time as an ``Instant``.
Expand Down

0 comments on commit ce56212

Please sign in to comment.