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

Update docs #2373

Merged
merged 38 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0c13026
Update environment.yml and setup.cfg to latest version of sphinx
aknierim Jul 4, 2023
501f2a9
Moved docs/_static/theme_overrides.css to docs/_static/ctapipe.css
aknierim Jul 4, 2023
135df80
Added logos dark/light
aknierim Jul 4, 2023
11275ed
Updated docs, added version switcher
aknierim Jul 4, 2023
c1eef15
Update setup.cfg pydata dependency
aknierim Jul 4, 2023
a76a43d
Added sphinx-design
aknierim Jul 4, 2023
c60a81e
Update environment.yml and setup.cfg to latest version of sphinx
aknierim Jul 4, 2023
658fb6a
Moved docs/_static/theme_overrides.css to docs/_static/ctapipe.css
aknierim Jul 4, 2023
d2a6d54
Added logos dark/light
aknierim Jul 4, 2023
b97b531
Updated docs, added version switcher
aknierim Jul 4, 2023
40aab03
Update setup.cfg pydata dependency
aknierim Jul 4, 2023
bc9d6d7
Added sphinx-design
aknierim Jul 4, 2023
1050126
Merge branch 'update-docs' of github.com:aknierim/ctapipe into update…
aknierim Jul 4, 2023
07ce4ba
Fixed sphinx warning for ctapipe.compat.StrEnum
aknierim Jul 4, 2023
c025fe3
Fixed sphinx warnings for `ctapipe.instrument`
aknierim Jul 5, 2023
2aed4de
Attempt at a temporary workaround
aknierim Jul 5, 2023
8b60b9a
Added ``:noindex:`` option to certain rst files
aknierim Jul 5, 2023
f3f6d00
Workarounds for duplicate reference warnings
aknierim Jul 7, 2023
958e5d9
Fix heading issue
aknierim Jul 7, 2023
1618eb1
Not adding to __all__ fixes automodapi warnings
aknierim Jul 9, 2023
a99555b
Change back to automodapi, rework docs front page
aknierim Jul 9, 2023
246639f
Ignore unused import warnings
aknierim Jul 10, 2023
3c0223b
Fix isort failing in ctapipe/instrument/camera/__init__.py
aknierim Jul 10, 2023
099f601
Remove html_sidebars option from conf.py
aknierim Jul 10, 2023
57d348f
Fix duplicated reference warning for muon components
maxnoe Jul 17, 2023
c0dc668
Fix broken html syntax in Component.__repr_html__
maxnoe Jul 17, 2023
2f16d23
Clear notebook outputs
maxnoe Jul 17, 2023
4f5f051
Fix add_css_file call in docs/conf.py
maxnoe Jul 17, 2023
63b9e63
Fix Tool repr_html and add html escaping
maxnoe Jul 17, 2023
beb5fad
Simplify __init__.py
maxnoe Jul 17, 2023
02798cb
Remove version switcher from navbar
aknierim Jul 17, 2023
a089c49
Add sidebar to all pages
aknierim Jul 17, 2023
61547d2
Fix for failed CI/lint
aknierim Jul 17, 2023
22d2062
Move content of caution admonition to announcement banner
aknierim Jul 18, 2023
2a6b6ed
Add sphinx conf path to .readthedocs.yml
aknierim Jul 18, 2023
854a84e
Add sidebars again
aknierim Jul 18, 2023
c782ba0
Add navbar version switcher
aknierim Jul 19, 2023
05cc382
Fix versions in switcher.json
aknierim Jul 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions ctapipe/calib/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Camera calibration module.
"""

from .calibrator import CameraCalibrator
from .gainselection import GainSelector
from .calibrator import CameraCalibrator # noqa: F401
from .gainselection import GainSelector # noqa: F401

__all__ = [
"CameraCalibrator",
"GainSelector",
# "CameraCalibrator",
# "GainSelector",
]
17 changes: 10 additions & 7 deletions ctapipe/core/component.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Class to handle configuration for algorithms """
import html
import warnings
import weakref
from abc import ABCMeta
Expand Down Expand Up @@ -233,9 +234,9 @@ def _repr_html_(self):
or "Undocumented"
)
lines = [
"<div style='border:1px solid black; max-width: 700px; padding:2em'; word-wrap:break-word;>",
'<div style="border:1px solid black; max-width: 700px; padding:2em; word-wrap:break-word;">',
f"<b>{name}</b>",
f"<p> {docstring} </p>",
docstring,
"<table>",
" <colgroup>",
" <col span='1' style=' '>",
Expand All @@ -246,21 +247,23 @@ def _repr_html_(self):
]
for key, val in self.get_current_config()[name].items():
htmlval = (
str(val).replace("/", "/<wbr>").replace("_", "_<wbr>")
html.escape(str(val)).replace("/", "/<wbr>").replace("_", "_<wbr>")
) # allow breaking at boundary

# traits of the current component
if key in traits:
thehelp = f"{traits[key].help} (default: {traits[key].default_value})"
thehelp = html.escape(
f"{traits[key].help} (default: {traits[key].default_value})"
)
lines.append(f"<tr><th>{key}</th>")
if val != traits[key].default_value:
lines.append(
f"<td style='text-align: left;'><span style='color:blue; max-width:30em;'>{htmlval}</span></td>"
f'<td style="text-align: left;"><span style="color:blue; max-width:30em;">{htmlval}</span></td>'
)
else:
lines.append(f"<td style='text-align: left;'>{htmlval}</td>")
lines.append(f'<td style="text-align: left;">{htmlval}</td>')
lines.append(
f"<td style='text-align: left;'><i>{thehelp}</i></td></tr>"
f'<td style="text-align: left;"><i>{thehelp}</i></td></tr>'
)
lines.append(" </tbody>")
lines.append("</table>")
Expand Down
10 changes: 7 additions & 3 deletions ctapipe/core/tool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Classes to handle configurable command-line user interfaces."""
import html
import logging
import logging.config
import os
Expand Down Expand Up @@ -495,8 +496,9 @@ def _repr_html_(self):
or "Undocumented"
)
lines = [
'<div style="border:1px solid black; max-width: 700px; padding:2em; word-wrap:break-word;">',
f"<b>{name}</b>",
f"<p> {docstring} </p>",
docstring,
"<table>",
" <colgroup>",
" <col span='1' style=' '>",
Expand All @@ -507,12 +509,14 @@ def _repr_html_(self):
]
for key, val in self.get_current_config()[name].items():
htmlval = (
str(val).replace("/", "/<wbr>").replace("_", "_<wbr>")
html.escape(str(val)).replace("/", "/<wbr>").replace("_", "_<wbr>")
) # allow breaking at boundary

# traits of the current component
if key in traits:
thehelp = f"{traits[key].help} (default: {traits[key].default_value})"
thehelp = html.escape(
f"{traits[key].help} (default: {traits[key].default_value})"
)
lines.append(f"<tr><th>{key}</th>")
if val != traits[key].default_value:
lines.append(
Expand Down
2 changes: 2 additions & 0 deletions ctapipe/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)
from .muon import (
MuonIntensityFitter,
MuonProcessor,
MuonRingFitter,
intensity_ratio_inside_ring,
kundu_chaudhuri_circle_fit,
Expand Down Expand Up @@ -93,6 +94,7 @@
"chi_squared",
"MuonIntensityFitter",
"MuonRingFitter",
"MuonProcessor",
"kundu_chaudhuri_circle_fit",
"mean_squared_error",
"intensity_ratio_inside_ring",
Expand Down
9 changes: 3 additions & 6 deletions ctapipe/image/muon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
ring_containment,
)
from .fitting import kundu_chaudhuri_circle_fit
from .intensity_fitter import MuonIntensityFitter
from .processor import MuonProcessor
from .ring_fitter import MuonRingFitter
from .intensity_fitter import MuonIntensityFitter # noqa: F401
from .processor import MuonProcessor # noqa: F401
from .ring_fitter import MuonRingFitter # noqa: F401

__all__ = [
"MuonIntensityFitter",
"MuonRingFitter",
"kundu_chaudhuri_circle_fit",
"mean_squared_error",
"intensity_ratio_inside_ring",
"ring_completeness",
"ring_containment",
"MuonProcessor",
]
17 changes: 9 additions & 8 deletions ctapipe/instrument/camera/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from .description import CameraDescription
from .geometry import CameraGeometry, UnknownPixelShapeWarning, PixelShape
from .readout import CameraReadout
from .description import CameraDescription # noqa: F401
from .geometry import CameraGeometry, PixelShape, UnknownPixelShapeWarning # noqa: F401
from .readout import CameraReadout # noqa: F401

# commented out due to sphinx issue with classes being defined in 3 places
__all__ = [
"CameraDescription",
"CameraGeometry",
"PixelShape",
"UnknownPixelShapeWarning",
"CameraReadout",
# "CameraDescription",
# "CameraGeometry",
# "PixelShape",
# "UnknownPixelShapeWarning",
# "CameraReadout",
]
47 changes: 47 additions & 0 deletions docs/_static/ctapipe.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* override table width restrictions */
@media screen and (min-width: 767px) {

.wy-table-responsive table td {
/* !important prevents the common CSS stylesheets from overriding
this as on RTD they are loaded after this stylesheet */
white-space: normal !important;
}

.wy-table-responsive {
overflow: visible !important;
}
}

/* sphinx-design */
.sd-card {
border-radius: 5px;
padding: 30px 10px 20px 10px;
margin: 10px 0px;
}

.sd-card .sd-card-header .sd-card-text {
margin: 0px;
}

.sd-card .sd-card-header {
border: none;
text-align: center;
font-size: var(--pst-font-size-h4);
font-weight: bold;
padding: 0.5rem 0rem 0.5rem 0rem;
}

.sd-card .sd-card-footer {
border: none;
}

.sd-card .sd-card-footer .sd-card-text {
max-width: 220px;
margin-left: auto;
margin-right: auto;
}

html[data-theme="dark"] .sd-shadow-sm {
--sd-color-shadow: #6e6e6e;
}

13 changes: 0 additions & 13 deletions docs/_static/theme_overrides.css

This file was deleted.

3 changes: 3 additions & 0 deletions docs/changes/2373.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Switched to ``PyData`` theme for docs
* Updated ``Sphinx`` to version 6.2.1
* Updated front page of docs
71 changes: 42 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
setup_metadata = dict(setup_cfg.items("metadata"))
setup_options = dict(setup_cfg.items("options"))


# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Expand All @@ -52,10 +53,13 @@
"nbsphinx",
"matplotlib.sphinxext.plot_directive",
"numpydoc",
"sphinx_design",
"IPython.sphinxext.ipython_console_highlighting",
]


numpydoc_show_class_members = False
numpydoc_class_members_toctree = False
nbsphinx_timeout = 200 # allow max 2 minutes to build each notebook


Expand All @@ -64,6 +68,8 @@


def setup(app):
app.add_css_file("ctapipe.css")

# fix trait aliases generating doc warnings
from ctapipe.core import traits

Expand Down Expand Up @@ -122,6 +128,7 @@ def setup(app):
("py:class", "ctapipe.compat.StrEnum"),
]


# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
Expand Down Expand Up @@ -182,32 +189,53 @@ def setup(app):
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "default"
html_theme = "pydata_sphinx_theme"


html_favicon = "_static/favicon.ico"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
html_theme_options = {
"logo": {
"image_light": "ctapipe_logo.webp",
"image_dark": "ctapipe_logo_dark.webp",
"alt_text": "ctapipe",
},
"github_url": "https://github.com/cta-observatory/ctapipe",
"header_links_before_dropdown": 6,
"navbar_start": ["navbar-logo"],
"use_edit_page_button": True,
"icon_links": [
{
"name": "CTA Observatory",
"url": "https://www.cta-observatory.org/",
"type": "url",
"icon": "https://www.cta-observatory.org/wp-content/themes/ctao/favicon.ico",
},
],
}

html_sidebars = {"**": ["sidebar-nav-bs.html", "sidebar-ethical-ads.html"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a waste of space: there is no content in the sidebar for most of the pages

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version switcher is there. We had an alternative version, but that would require manually curating a json file of versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right, but this is currently the only way to get the version switcher from RTD. The way I see it, we currently have three options:

  1. We go back and reimplement the dropdown menu I previously added. This however would mean that we have to add any new version to a JSON file by hand.

  2. We use the flyout menu from RTD, thus making it necessary to have the sidebar on all pages.

  3. We use the flyout menu only on specific pages like the front page and for example the API docs.

I'm not sure which option is the best as I guess all of them have their drawbacks...

Copy link
Contributor

@kosack kosack Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this works fine in the vodf pages I created.. Not sure how I configured it, but there the switcher is floating on the lower-right corner: https://vodf.readthedocs.io/en/latest/ (and also in the top-bar)
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course the ethical ads don't appear though

Copy link
Contributor Author

@aknierim aknierim Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to figure out why the behaviour is so different from your vodf pages today but couldn't find anything. My only guess would be different behaviour when using Sphinx 4.5 and PyData 0.10 for the vodf pages versus the ctapipe docs with Sphinx 6.2.1 and PyData 0.13.3...

Copy link
Contributor Author

@aknierim aknierim Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version switcher in the navbar on the vodf pages is of course the same one that uses the manually curated json file. But the version switcher from RTD is what boggles my mind.

At least from what I gathered from the PyData theme dev docs and an open issue, they are currently working on a way to make the RTD version switcher more customizable, or at least movable from the sidebar. But for the time being it should actually only appear in the primary sidebar (if not hidden) on the left.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who knows? I can try updating the VODF docs and see if it disappears... You're right that it's not quite the same version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we can deal with that in a later PR, for now it's fine.



# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
html_static_path = ["_static"]

html_context = {
"css_files": ["_static/theme_overrides.css"] # override wide tables in RTD theme
"default_mode": "light",
"github_user": "cta-observatory",
"github_repo": "ctapipe",
"github_version": "main",
"doc_path": "docs",
}

html_favicon = "_static/favicon.ico"
# -- Options for HTMLHelp output ------------------------------------------

html_css_files = ["ctapipe.css"]
html_file_suffix = ".html"

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
Expand All @@ -216,6 +244,7 @@ def setup(app):
# Output file base name for HTML help builder.
htmlhelp_basename = project + "doc"


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
Expand Down Expand Up @@ -277,19 +306,3 @@ def setup(app):
"iminuit": ("https://iminuit.readthedocs.io/en/latest/", None),
"traitlets": ("https://traitlets.readthedocs.io/en/stable/", None),
}

# on_rtd is whether we are on readthedocs.org
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

if not on_rtd: # only import and set the theme if we're building docs locally
try:
import sphinx_rtd_theme
except ImportError:
raise ImportError(
"It looks like you don't have the sphinx_rtd_theme "
"package installed. This documentation "
"uses the Read The Docs theme, so you must install this "
"first. For example, pip install sphinx_rtd_theme"
)
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
7 changes: 4 additions & 3 deletions docs/ctapipe_api/calib/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.. _calib:

===============================
Calibration (`~ctapipe.calib`)
===============================

==============================
Calibration (`~ctapipe.calib`)
==============================

.. currentmodule:: ctapipe.calib

Expand Down
2 changes: 1 addition & 1 deletion docs/ctapipe_api/calib/index_camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CTA Cameras (MC, prototypes and final camera calibration algorithms).
CameraCalibrator
****************

The primary class in this module is the `CameraCalibrator`. This class handles
The primary class in this module is the `~ctapipe.calib.camera.calibrator.CameraCalibrator`. This class handles
two data level transition stages for the event:

* R1 -> DL0 (:ref:`image_reducers`)
Expand Down
8 changes: 4 additions & 4 deletions docs/ctapipe_api/instrument/camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Camera Description
==================

The `CameraDescription` contains classes holding information about the
Cherenkov camera, namely the `CameraGeometry` and `CameraReadout` classes.
The `~camera.description.CameraDescription` contains classes holding information about the
Cherenkov camera, namely the `~camera.geometry.CameraGeometry` and `~camera.readout.CameraReadout` classes.


.. toctree::
Expand All @@ -17,10 +17,10 @@ Cherenkov camera, namely the `CameraGeometry` and `CameraReadout` classes.


Reference/API
-------------

=============

.. automodapi:: ctapipe.instrument.camera
:no-inheritance-diagram:

.. automodapi:: ctapipe.instrument.camera.description
:no-inheritance-diagram: