From 98080d8de66d84b422b86a16f39bc8540d79edd6 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Tue, 8 Jan 2019 09:40:54 +0100
Subject: [PATCH] [scripts] Add script to dump sphinx catalogs

---
 bob/devtools/scripts/dumpsphinx.py | 46 ++++++++++++++++++++++++++++++
 conda/meta.yaml                    |  3 +-
 setup.py                           |  2 ++
 3 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 bob/devtools/scripts/dumpsphinx.py

diff --git a/bob/devtools/scripts/dumpsphinx.py b/bob/devtools/scripts/dumpsphinx.py
new file mode 100644
index 00000000..61caece0
--- /dev/null
+++ b/bob/devtools/scripts/dumpsphinx.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+import logging
+logger = logging.getLogger(__name__)
+
+from sphinx.ext import intersphinx
+
+import click
+
+from . import bdt
+from ..log import verbosity_option
+
+
+@click.command(context_settings=dict(
+    ignore_unknown_options=True,
+    allow_extra_args=True,
+    ),
+    epilog='''
+Examples:
+
+  1. Dumps objects documented in python 3.x:
+
+     $ bdt dumpsphinx https://docs.python.org/3/objects.inv
+
+
+  2. Dumps objects documented in numpy:
+
+     $ bdt dumpsphinx https://docs.scipy.org/doc/numpy/objects.inv
+
+
+  3. Dumps objects documented in matplotlib:
+
+     $ bdt dumpsphinx http://matplotlib.org/objects.inv
+''')
+@click.argument('url')
+@verbosity_option()
+@bdt.raise_on_error
+def dumpsphinx(url):
+  """Dumps all the objects given an sphinx catalog/inventory URL
+
+  This command is useful when you are struggling to do proper links from your
+  documentation.
+  """
+  intersphinx.inspect_main([url])
diff --git a/conda/meta.yaml b/conda/meta.yaml
index d8d3bab9..21ddbc11 100644
--- a/conda/meta.yaml
+++ b/conda/meta.yaml
@@ -39,10 +39,10 @@ requirements:
     - gitpython
     - python-gitlab
     - requests
+    - sphinx
 
 test:
   requires:
-    - sphinx
     - sphinx_rtd_theme
   imports:
     - {{ name }}
@@ -54,6 +54,7 @@ test:
     - bdt changelog --help
     - bdt release --help
     - bdt visibility --help
+    - bdt dumpsphinx --help
     - sphinx-build -aEW ${PREFIX}/share/doc/{{ name }}/doc {{ project_dir }}/sphinx
 
 about:
diff --git a/setup.py b/setup.py
index 86d4b7a8..103b99b7 100644
--- a/setup.py
+++ b/setup.py
@@ -13,6 +13,7 @@ requires = [
     'requests',
     'gitpython',
     'python-gitlab',
+    'sphinx',
     ]
 
 setup(
@@ -42,6 +43,7 @@ setup(
             'changelog = bob.devtools.scripts.changelog:changelog',
             'lasttag = bob.devtools.scripts.lasttag:lasttag',
             'visibility = bob.devtools.scripts.visibility:visibility',
+            'dumpsphinx = bob.devtools.scripts.dumpsphinx:dumpsphinx',
         ],
     },
     classifiers=[
-- 
GitLab