Skip to content

Commit 113979c

Browse files
committed
refactor: Move extension entrypoint from ext.py to __init__.py
Then it can be consistency with other sphinxnotes projects.
1 parent 8f80425 commit 113979c

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
# add these directories to sys.path here. If the directory is relative to the
153153
# documentation root, use os.path.abspath to make it absolute, like shown here.
154154
sys.path.insert(0, os.path.abspath('../src/sphinxnotes'))
155-
extensions.append('snippet.ext')
155+
extensions.append('snippet')
156156

157157
# DOG FOOD CONFIGURATION START
158158

src/sphinxnotes/snippet/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
sphinxnotes.snippet
3+
~~~~~~~~~~~~~~~~~~~
4+
5+
Sphinx extension entrypoint.
6+
7+
:copyright: Copyright 2024 Shengyu Zhang
8+
:license: BSD, see LICENSE for details.
9+
"""
10+
11+
12+
def setup(app):
13+
# **WARNING**: We don't import these packages globally, because the current
14+
# package (sphinxnotes.snippet) is always resloved when importing
15+
# sphinxnotes.snippet.*. If we import packages here, eventually we will
16+
# load a lot of packages from the Sphinx. It will seriously **SLOW DOWN**
17+
# the startup time of our CLI tool (sphinxnotes.snippet.cli).
18+
#
19+
# .. seealso:: https://github.com/sphinx-notes/snippet/pull/31
20+
from .ext import (
21+
SnippetBuilder,
22+
on_config_inited,
23+
on_env_get_outdated,
24+
on_doctree_resolved,
25+
on_builder_finished,
26+
)
27+
28+
app.add_builder(SnippetBuilder)
29+
30+
app.add_config_value('snippet_config', {}, '')
31+
app.add_config_value('snippet_patterns', {'*': ['.*']}, '')
32+
33+
app.connect('config-inited', on_config_inited)
34+
app.connect('env-get-outdated', on_env_get_outdated)
35+
app.connect('doctree-resolved', on_doctree_resolved)
36+
app.connect('build-finished', on_builder_finished)

src/sphinxnotes/snippet/ext.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
sphinxnotes.ext.snippet
2+
sphinxnotes.snippet.ext
33
~~~~~~~~~~~~~~~~~~~~~~~
44
5-
Sphinx extension for sphinxnotes.snippet.
5+
Sphinx extension implementation, but the entrypoint is located at __init__.py.
66
7-
:copyright: Copyright 2021 Shengyu Zhang
7+
:copyright: Copyright 2024 Shengyu Zhang
88
:license: BSD, see LICENSE for details.
99
"""
1010

@@ -206,15 +206,3 @@ def _format_modified_time(timestamp: float) -> str:
206206
"""Return an RFC 3339 formatted string representing the given timestamp."""
207207
seconds, fraction = divmod(timestamp, 1)
208208
return time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(seconds)) + f'.{fraction:.3f}'
209-
210-
211-
def setup(app: Sphinx):
212-
app.add_builder(SnippetBuilder)
213-
214-
app.add_config_value('snippet_config', {}, '')
215-
app.add_config_value('snippet_patterns', {'*': ['.*']}, '')
216-
217-
app.connect('config-inited', on_config_inited)
218-
app.connect('env-get-outdated', on_env_get_outdated)
219-
app.connect('doctree-resolved', on_doctree_resolved)
220-
app.connect('build-finished', on_builder_finished)

0 commit comments

Comments
 (0)