Skip to content

Commit b8bd433

Browse files
Merge pull request #63 from openforcefield/move_faq
Move FAQ from Toolkit
2 parents 96aed61 + 4daf451 commit b8bd433

File tree

6 files changed

+436
-23
lines changed

6 files changed

+436
-23
lines changed

devtools/conda-envs/rtd_env.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
name: openff-toolkit-docs
22
channels:
3-
- conda-forge
3+
- conda-forge
44
dependencies:
5-
- pip
6-
# readthedocs dependencies
7-
- sphinx>=5,<7
8-
- myst-parser>=1,<2
9-
# - myst-nb
10-
- sphinx-notfound-page
11-
- ipython >=8.8
12-
- sphinx-design
13-
# Examples
14-
- gitpython
15-
- nbconvert
16-
- nbformat
17-
# Theme
18-
- pip:
19-
# Theme
20-
- git+https://github.com/openforcefield/openff-sphinx-theme.git@main
21-
# Lints
22-
- sphinxawesome-codelinter
23-
# Sphinx
24-
- git+https://github.com/Yoshanuikabundi/MyST-NB.git@upgrade-to-1
5+
- pip
6+
# readthedocs dependencies
7+
- sphinx>=5,<7
8+
- myst-parser>=1,<2
9+
# - myst-nb
10+
- sphinx-notfound-page
11+
- ipython >=8.8
12+
- sphinx-design>=0.6.0
13+
# Examples
14+
- gitpython
15+
- nbconvert
16+
- nbformat
17+
# Theme
18+
- pip:
19+
# Theme
20+
- git+https://github.com/openforcefield/openff-sphinx-theme.git@main
21+
# Lints
22+
- sphinxawesome-codelinter
23+
# Sphinx
24+
- git+https://github.com/Yoshanuikabundi/MyST-NB.git@upgrade-to-1
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Conditionally provide some variables to a wrapped script.
4+
5+
The purpose of this script is to provide the ability to quickly write short
6+
snippets in the OpenFF documentation that do not require initialization of
7+
common Toolkit objects while not inhibiting the quality of error messages from
8+
more complete code examples.
9+
10+
Code examples are used throughout the docs and testing that they do not raise
11+
errors has caught many documentation errors already. The `codelinter` Sphinx
12+
extension runs this script on all code blocks in this documentation project.
13+
The script sets up some commonly used variables and imports so that short
14+
snippets don't have to initialize them, and then sets up an import hook that
15+
deletes the added names if `openff.toolkit` is imported in the code block. This
16+
means that short snippets can assume some common variables are in scope, but
17+
long code blocks intended to be self-sufficient can opt out of this name
18+
pollution by importing the toolkit.
19+
"""
20+
21+
# Define the default namespace
22+
import openff.toolkit
23+
from openff.toolkit import ForceField, Molecule, Topology
24+
25+
molecule = Molecule.from_smiles("C123C(C1)(C2)C3")
26+
topology = Topology.from_molecules([molecule])
27+
force_field = ForceField("openff_unconstrained-2.2.0.offxml")
28+
ff_unconstrained = force_field
29+
ff_constrained = ForceField("openff-2.2.0.offxml")
30+
31+
# Set the import hook
32+
import builtins
33+
import sys
34+
35+
_old_import = __import__
36+
_already_deleted = False
37+
38+
39+
def __import__(name, *args, **kwargs):
40+
"""
41+
Clear above variables on any new import of the toolkit
42+
"""
43+
global _already_deleted
44+
if name.startswith("openff.toolkit") and not _already_deleted:
45+
global \
46+
molecule, \
47+
topology, \
48+
force_field, \
49+
ForceField, \
50+
Molecule, \
51+
Topology, \
52+
ff_constrained, \
53+
ff_unconstrained
54+
del (
55+
molecule,
56+
topology,
57+
force_field,
58+
ForceField,
59+
Molecule,
60+
Topology,
61+
ff_constrained,
62+
ff_unconstrained,
63+
)
64+
_already_deleted = True
65+
66+
return _old_import(name, *args, **kwargs)
67+
68+
69+
builtins.__import__ = __import__
70+
71+
# Execute the code block
72+
exec(sys.stdin.read())

source/_static/css/faq.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
details.faq.sd-dropdown,
2+
details.faq.sd-dropdown summary,
3+
details.faq.sd-dropdown:not([open]) > .sd-card-header {
4+
border: None;
5+
}
6+
7+
details.faq.sd-dropdown summary.sd-summary-title .sd-summary-state-marker {
8+
min-width: 3em;
9+
transform-origin: 25% 50%;
10+
}

source/conf.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@
7979
"openff.recharge": ("https://docs.openforcefield.org/recharge/en/stable", None),
8080
"openff.nagl": ("https://docs.openforcefield.org/nagl/en/stable", None),
8181
}
82+
intersphinx_disabled_reftypes = ["*"]
83+
myst_heading_anchors = 2
84+
85+
sd_custom_directives = {
86+
"faq-entry": {
87+
"inherit": "dropdown",
88+
"options": {
89+
"animate": "fade-in-slide-down",
90+
"class-container": "faq",
91+
},
92+
}
93+
}
8294

8395
# sphinx-notfound-page
8496
# https://github.com/readthedocs/sphinx-notfound-page
@@ -104,7 +116,7 @@
104116
extensions.append("sphinxawesome.codelinter")
105117
codelinter_languages = {
106118
# Language: command to pass codeblock as stdin
107-
"python": "python",
119+
"python": "python source/_ext/check_python_codeblocks.py",
108120
}
109121
# Tell MyST-NB about codelinter builder
110122
nb_mime_priority_overrides = [
@@ -113,6 +125,9 @@
113125

114126
# Configure the linkcheck builder
115127
linkcheck_anchors = False # This generates lots of false positives
128+
linkcheck_ignore = [
129+
r'https://pubs.acs.org/doi/' # ACS 403s the link checker. Thanks ACS.
130+
]
116131

117132
# Cookbook stuff
118133
import sys
@@ -132,6 +147,7 @@
132147
html_css_files = [
133148
"css/deflist-flowchart.css",
134149
"css/cookbook.css",
150+
"css/faq.css",
135151
]
136152

137153
# List of patterns, relative to source directory, that match files and

0 commit comments

Comments
 (0)