Skip to content

Commit 108a867

Browse files
committed
Changed how cache is cleared as previous approach didn't cache anything.
1 parent 3ef6171 commit 108a867

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

seed_intersphinx_mapping/__main__.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
#
3+
# __main__.py
4+
"""
5+
CLI entry point for seed_intersphinx_mapping.
6+
"""
7+
#
8+
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
9+
#
10+
# Permission is hereby granted, free of charge, to any person obtaining a copy
11+
# of this software and associated documentation files (the "Software"), to deal
12+
# in the Software without restriction, including without limitation the rights
13+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
# copies of the Software, and to permit persons to whom the Software is
15+
# furnished to do so, subject to the following conditions:
16+
#
17+
# The above copyright notice and this permission notice shall be included in all
18+
# copies or substantial portions of the Software.
19+
#
20+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
26+
# OR OTHER DEALINGS IN THE SOFTWARE.
27+
#
28+
29+
__all__ = ["clear_cache"]
30+
31+
# stdlib
32+
import sys
33+
34+
# this package
35+
from seed_intersphinx_mapping import cache, get_sphinx_doc_url
36+
37+
38+
def clear_cache():
39+
"""
40+
Clear any cached URLs.
41+
"""
42+
43+
if cache.clear(get_sphinx_doc_url):
44+
print("Cache cleared successfully.")
45+
return 0
46+
else:
47+
return 1
48+
49+
50+
if __name__ == "__main__":
51+
sys.exit(clear_cache())

seed_intersphinx_mapping/core.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ def get_sphinx_doc_url(pypi_name: str) -> str:
7171
Not all projects include this URl in their distributions and therefore it may not be possible to determine it from PyPI.
7272
7373
Responses are cached to prevent overloading the PyPI server.
74-
If using the Sphinx extension the cache is cleared whenever a document is rebuilt.
75-
It can also be cleared manually as follows:
74+
The cache can be cleared as follows:
7675
77-
.. code-block:: python
76+
.. prompt:: bash
7877
79-
>>> from seed_intersphinx_mapping import cache, get_sphinx_doc_url
80-
>>> cache.clear(get_sphinx_doc_url)
81-
True
78+
python3 -m seed_intersphinx_mapping
79+
80+
.. TODO:: automatic cache clearing
8281
8382
:param pypi_name: The name of the project on PyPI
8483

seed_intersphinx_mapping/extension.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ def sphinx_seed_intersphinx_mapping(app: Sphinx, config: Config) -> None:
6969
# input(">")
7070

7171

72-
def sphinx_purge_cache(app: Sphinx, env: BuildEnvironment, docname):
73-
"""
74-
Clear any cached URLs.
75-
76-
:param app: The sphinx application.
77-
:param env: The sphinx build environment.
78-
"""
79-
80-
cache.clear(get_sphinx_doc_url)
81-
82-
8372
def setup(app: Sphinx) -> Dict[str, Any]:
8473
"""
8574
Setup Sphinx Extension.
@@ -100,9 +89,6 @@ def setup(app: Sphinx) -> Dict[str, Any]:
10089

10190
app.connect("config-inited", sphinx_seed_intersphinx_mapping, priority=850)
10291

103-
# Clear Cache
104-
app.connect("env-purge-doc", sphinx_purge_cache)
105-
10692
return {
10793
"version": __version__,
10894
"parallel_read_safe": True,

0 commit comments

Comments
 (0)