Gabriel Somlo 9521270
From 41978a7af0f4807c4dfa8d3dc794ac671540bf6e Mon Sep 17 00:00:00 2001
Gabriel Somlo 9521270
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
Gabriel Somlo 9521270
Date: Tue, 1 Oct 2019 15:23:50 -0400
Gabriel Somlo 9521270
Subject: [PATCH] Revert "Change theme to Sphinx Material Design"
Gabriel Somlo 9521270
Gabriel Somlo 9521270
This reverts commit de5eec38c4333eac947579d4c6b5695b3edb2499.
Gabriel Somlo 9521270
Gabriel Somlo 9521270
Reverting this change should allow building the PDF manual as
Gabriel Somlo 9521270
part of a Fedora RPM package.
Gabriel Somlo 9521270
Gabriel Somlo 9521270
Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
Gabriel Somlo 9521270
---
Gabriel Somlo 9521270
 docs/.gitignore                |   1 -
Gabriel Somlo 9521270
 docs/Makefile                  |  30 ++----
Gabriel Somlo 9521270
 docs/_static/.keepme           |   0
Gabriel Somlo 9521270
 docs/conf.py                   | 116 ++++-----------------
Gabriel Somlo 9521270
 docs/markdown_code_symlinks.py | 179 +++++++++++++++++++++++++++++++++
Gabriel Somlo 9521270
 docs/requirements.txt          |   7 +-
Gabriel Somlo 9521270
 6 files changed, 209 insertions(+), 124 deletions(-)
Gabriel Somlo 9521270
 delete mode 100644 docs/_static/.keepme
Gabriel Somlo 9521270
 create mode 100644 docs/markdown_code_symlinks.py
Gabriel Somlo 9521270
Gabriel Somlo 9521270
diff --git a/docs/.gitignore b/docs/.gitignore
Gabriel Somlo 9521270
index 13856a1..e35d885 100644
Gabriel Somlo 9521270
--- a/docs/.gitignore
Gabriel Somlo 9521270
+++ b/docs/.gitignore
Gabriel Somlo 9521270
@@ -1,2 +1 @@
Gabriel Somlo 9521270
-venv
Gabriel Somlo 9521270
 _build
Gabriel Somlo 9521270
diff --git a/docs/Makefile b/docs/Makefile
Gabriel Somlo 9521270
index cb6f107..b52c668 100644
Gabriel Somlo 9521270
--- a/docs/Makefile
Gabriel Somlo 9521270
+++ b/docs/Makefile
Gabriel Somlo 9521270
@@ -1,15 +1,13 @@
Gabriel Somlo 9521270
 # Minimal makefile for Sphinx documentation
Gabriel Somlo 9521270
 #
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
-MAKEDIR := $(dir $(lastword $(MAKEFILE_LIST)))
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
 # You can set these variables from the command line.
Gabriel Somlo 9521270
-SPHINXOPTS      =
Gabriel Somlo 9521270
-SPHINXBUILD     = [ -e venv/bin/activate ] && source venv/bin/activate; sphinx-build
Gabriel Somlo 9521270
-SPHINXAUTOBUILD = [ -e venv/bin/activate ] && source venv/bin/activate; sphinx-autobuild
Gabriel Somlo 9521270
-SPHINXPROJ      = ProjectTrellis
Gabriel Somlo 9521270
-SOURCEDIR       = .
Gabriel Somlo 9521270
-BUILDDIR        = _build
Gabriel Somlo 9521270
+SPHINXOPTS    =
Gabriel Somlo 9521270
+SPHINXBUILD   = sphinx-build
Gabriel Somlo 9521270
+SPHINXAUTOBUILD   = sphinx-autobuild
Gabriel Somlo 9521270
+SPHINXPROJ    = ProjectX-Ray
Gabriel Somlo 9521270
+SOURCEDIR     = .
Gabriel Somlo 9521270
+BUILDDIR      = _build
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # Put it first so that "make" without argument is like "make help".
Gabriel Somlo 9521270
 help:
Gabriel Somlo 9521270
@@ -18,21 +16,9 @@ help:
Gabriel Somlo 9521270
 livehtml:
Gabriel Somlo 9521270
 	@$(SPHINXAUTOBUILD) -b html --ignore \*.swp --ignore \*~ $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
-.PHONY: help livehtml Makefile
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-venv:
Gabriel Somlo 9521270
-	rm -rf venv
Gabriel Somlo 9521270
-	virtualenv --python=python3 venv
Gabriel Somlo 9521270
-	source venv/bin/activate; pip install -r requirements.txt
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-.PHONY: venv
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-links:
Gabriel Somlo 9521270
-	@true
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-.PHONY: links
Gabriel Somlo 9521270
+.PHONY: help livereload Makefile
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # Catch-all target: route all unknown targets to Sphinx using the new
Gabriel Somlo 9521270
 # "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
Gabriel Somlo 9521270
-%: Makefile links
Gabriel Somlo 9521270
+%: Makefile
Gabriel Somlo 9521270
 	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Gabriel Somlo 9521270
diff --git a/docs/_static/.keepme b/docs/_static/.keepme
Gabriel Somlo 9521270
deleted file mode 100644
Gabriel Somlo 9521270
index e69de29..0000000
Gabriel Somlo 9521270
diff --git a/docs/conf.py b/docs/conf.py
Gabriel Somlo 9521270
index e847b58..8989469 100644
Gabriel Somlo 9521270
--- a/docs/conf.py
Gabriel Somlo 9521270
+++ b/docs/conf.py
Gabriel Somlo 9521270
@@ -24,7 +24,7 @@ import recommonmark
Gabriel Somlo 9521270
 import os
Gabriel Somlo 9521270
 import sys
Gabriel Somlo 9521270
 sys.path.insert(0, os.path.abspath('.'))
Gabriel Somlo 9521270
-from markdown_code_symlinks import LinkParser, MarkdownSymlinksDomain
Gabriel Somlo 9521270
+from markdown_code_symlinks import MarkdownCodeSymlinks
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # -- General configuration ------------------------------------------------
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
@@ -36,13 +36,8 @@ from markdown_code_symlinks import LinkParser, MarkdownSymlinksDomain
Gabriel Somlo 9521270
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Gabriel Somlo 9521270
 # ones.
Gabriel Somlo 9521270
 extensions = [
Gabriel Somlo 9521270
-    'sphinx.ext.autodoc',
Gabriel Somlo 9521270
-    'sphinx.ext.autosummary',
Gabriel Somlo 9521270
-    'sphinx.ext.doctest',
Gabriel Somlo 9521270
-    'sphinx.ext.imgmath',
Gabriel Somlo 9521270
-    'sphinx.ext.napoleon',
Gabriel Somlo 9521270
-    'sphinx.ext.todo',
Gabriel Somlo 9521270
-    'sphinx_markdown_tables',
Gabriel Somlo 9521270
+    'sphinx.ext.imgmath', 'sphinx.ext.autodoc', 'sphinx.ext.doctest',
Gabriel Somlo 9521270
+    'sphinx.ext.autosummary', 'sphinx.ext.napoleon', 'sphinx.ext.todo'
Gabriel Somlo 9521270
 ]
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # Add any paths that contain templates here, relative to this directory.
Gabriel Somlo 9521270
@@ -52,7 +47,7 @@ templates_path = ['_templates']
Gabriel Somlo 9521270
 # You can specify multiple suffix as a list of string:
Gabriel Somlo 9521270
 source_suffix = ['.rst', '.md']
Gabriel Somlo 9521270
 source_parsers = {
Gabriel Somlo 9521270
-    '.md': 'markdown_code_symlinks.LinkParser',
Gabriel Somlo 9521270
+    '.md': 'recommonmark.parser.CommonMarkParser',
Gabriel Somlo 9521270
 }
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # The master toctree document.
Gabriel Somlo 9521270
@@ -63,24 +58,6 @@ project = u'Project Trellis'
Gabriel Somlo 9521270
 copyright = u'2018, SymbiFlow Team'
Gabriel Somlo 9521270
 author = u'SymbiFlow Team'
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
-# Enable github links when not on readthedocs
Gabriel Somlo 9521270
-on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
Gabriel Somlo 9521270
-if not on_rtd:
Gabriel Somlo 9521270
-    html_context = {
Gabriel Somlo 9521270
-        "display_github": True,  # Integrate GitHub
Gabriel Somlo 9521270
-        "github_user": "symbiflow",  # Username
Gabriel Somlo 9521270
-        "github_repo": "prjtrellis",  # Repo name
Gabriel Somlo 9521270
-        "github_version": "master",  # Version
Gabriel Somlo 9521270
-        "conf_py_path": "/doc/",
Gabriel Somlo 9521270
-    }
Gabriel Somlo 9521270
-else:
Gabriel Somlo 9521270
-    docs_dir = os.path.abspath(os.path.dirname(__file__))
Gabriel Somlo 9521270
-    print("Docs dir is:", docs_dir)
Gabriel Somlo 9521270
-    import subprocess
Gabriel Somlo 9521270
-    subprocess.call('git fetch origin --unshallow', cwd=docs_dir, shell=True)
Gabriel Somlo 9521270
-    subprocess.check_call('git fetch origin --tags', cwd=docs_dir, shell=True)
Gabriel Somlo 9521270
-    subprocess.check_call('make links', cwd=docs_dir, shell=True)
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
 # The version info for the project you're documenting, acts as replacement for
Gabriel Somlo 9521270
 # |version| and |release|, also used in various other places throughout the
Gabriel Somlo 9521270
 # built documents.
Gabriel Somlo 9521270
@@ -100,10 +77,10 @@ language = None
Gabriel Somlo 9521270
 # List of patterns, relative to source directory, that match files and
Gabriel Somlo 9521270
 # directories to ignore when looking for source files.
Gabriel Somlo 9521270
 # This patterns also effect to html_static_path and html_extra_path
Gabriel Somlo 9521270
-exclude_patterns = ['_build', 'venv', 'Thumbs.db', '.DS_Store']
Gabriel Somlo 9521270
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # The name of the Pygments (syntax highlighting) style to use.
Gabriel Somlo 9521270
-pygments_style = 'default'
Gabriel Somlo 9521270
+pygments_style = 'sphinx'
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # If true, `todo` and `todoList` produce output, else they produce nothing.
Gabriel Somlo 9521270
 todo_include_todos = True
Gabriel Somlo 9521270
@@ -113,67 +90,24 @@ todo_include_todos = True
Gabriel Somlo 9521270
 # The theme to use for HTML and HTML Help pages.  See the documentation for
Gabriel Somlo 9521270
 # a list of builtin themes.
Gabriel Somlo 9521270
 #
Gabriel Somlo 9521270
-html_theme = 'sphinx_materialdesign_theme'
Gabriel Somlo 9521270
+html_theme = 'sphinx_rtd_theme'
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # Theme options are theme-specific and customize the look and feel of a theme
Gabriel Somlo 9521270
 # further.  For a list of options available for each theme, see the
Gabriel Somlo 9521270
 # documentation.
Gabriel Somlo 9521270
 #
Gabriel Somlo 9521270
-html_theme_options = {
Gabriel Somlo 9521270
-    # Specify a list of menu in Header.
Gabriel Somlo 9521270
-    # Tuples forms:
Gabriel Somlo 9521270
-    #  ('Name', 'external url or path of pages in the document', boolean, 'icon name')
Gabriel Somlo 9521270
-    #
Gabriel Somlo 9521270
-    # Third argument:
Gabriel Somlo 9521270
-    # True indicates an external link.
Gabriel Somlo 9521270
-    # False indicates path of pages in the document.
Gabriel Somlo 9521270
-    #
Gabriel Somlo 9521270
-    # Fourth argument:
Gabriel Somlo 9521270
-    # Specify the icon name.
Gabriel Somlo 9521270
-    # For details see link.
Gabriel Somlo 9521270
-    # https://material.io/icons/
Gabriel Somlo 9521270
-    'header_links': [
Gabriel Somlo 9521270
-        ('Home', 'index', False, 'home'),
Gabriel Somlo 9521270
-        ("GitHub", "https://github.com/SymbiFlow/prjtrellis", True, 'link')
Gabriel Somlo 9521270
-    ],
Gabriel Somlo 9521270
+# html_theme_options = {}
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
-    # Customize css colors.
Gabriel Somlo 9521270
-    # For details see link.
Gabriel Somlo 9521270
-    # https://getmdl.io/customize/index.html
Gabriel Somlo 9521270
-    #
Gabriel Somlo 9521270
-    # Values: amber, blue, brown, cyan deep_orange, deep_purple, green, grey, indigo, light_blue,
Gabriel Somlo 9521270
-    #         light_green, lime, orange, pink, purple, red, teal, yellow(Default: indigo)
Gabriel Somlo 9521270
-    'primary_color':
Gabriel Somlo 9521270
-    'deep_purple',
Gabriel Somlo 9521270
-    # Values: Same as primary_color. (Default: pink)
Gabriel Somlo 9521270
-    'accent_color':
Gabriel Somlo 9521270
-    'purple',
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-    # Customize layout.
Gabriel Somlo 9521270
-    # For details see link.
Gabriel Somlo 9521270
-    # https://getmdl.io/components/index.html#layout-section
Gabriel Somlo 9521270
-    'fixed_drawer':
Gabriel Somlo 9521270
-    True,
Gabriel Somlo 9521270
-    'fixed_header':
Gabriel Somlo 9521270
-    True,
Gabriel Somlo 9521270
-    'header_waterfall':
Gabriel Somlo 9521270
-    True,
Gabriel Somlo 9521270
-    'header_scroll':
Gabriel Somlo 9521270
-    False,
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-    # Render title in header.
Gabriel Somlo 9521270
-    # Values: True, False (Default: False)
Gabriel Somlo 9521270
-    'show_header_title':
Gabriel Somlo 9521270
-    False,
Gabriel Somlo 9521270
-    # Render title in drawer.
Gabriel Somlo 9521270
-    # Values: True, False (Default: True)
Gabriel Somlo 9521270
-    'show_drawer_title':
Gabriel Somlo 9521270
-    True,
Gabriel Somlo 9521270
-    # Render footer.
Gabriel Somlo 9521270
-    # Values: True, False (Default: True)
Gabriel Somlo 9521270
-    'show_footer':
Gabriel Somlo 9521270
-    True
Gabriel Somlo 9521270
-}
Gabriel Somlo 9521270
+# Enable github links when not on readthedocs
Gabriel Somlo 9521270
+on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
Gabriel Somlo 9521270
+if not on_rtd:
Gabriel Somlo 9521270
+    html_context = {
Gabriel Somlo 9521270
+        "display_github": True,  # Integrate GitHub
Gabriel Somlo 9521270
+        "github_user": "symbiflow",  # Username
Gabriel Somlo 9521270
+        "github_repo": "prjtrellis",  # Repo name
Gabriel Somlo 9521270
+        "github_version": "master",  # Version
Gabriel Somlo 9521270
+        "conf_py_path": "/doc/",
Gabriel Somlo 9521270
+    }
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 # Add any paths that contain custom static files (such as style sheets) here,
Gabriel Somlo 9521270
 # relative to this directory. They are copied after the builtin static files,
Gabriel Somlo 9521270
@@ -250,17 +184,9 @@ intersphinx_mapping = {'https://docs.python.org/': None}
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 def setup(app):
Gabriel Somlo 9521270
-    github_code_repo = 'https://github.com/SymbiFlow/prjtrellis/'
Gabriel Somlo 9521270
-    github_code_branch = 'blob/master/'
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-    docs_root_dir = os.path.realpath(os.path.dirname(__file__))
Gabriel Somlo 9521270
-    code_root_dir = os.path.realpath(os.path.join(docs_root_dir, ".."))
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-    MarkdownSymlinksDomain.init_domain(
Gabriel Somlo 9521270
-        github_code_repo, github_code_branch, docs_root_dir, code_root_dir)
Gabriel Somlo 9521270
-    MarkdownSymlinksDomain.find_links()
Gabriel Somlo 9521270
-    app.add_domain(MarkdownSymlinksDomain)
Gabriel Somlo 9521270
+    MarkdownCodeSymlinks.find_links()
Gabriel Somlo 9521270
     app.add_config_value(
Gabriel Somlo 9521270
         'recommonmark_config', {
Gabriel Somlo 9521270
-            'github_code_repo': github_code_repo,
Gabriel Somlo 9521270
+            'github_code_repo': 'https://github.com/SymbiFlow/prjtrellis',
Gabriel Somlo 9521270
         }, True)
Gabriel Somlo 9521270
+    app.add_transform(MarkdownCodeSymlinks)
Gabriel Somlo 9521270
diff --git a/docs/markdown_code_symlinks.py b/docs/markdown_code_symlinks.py
Gabriel Somlo 9521270
new file mode 100644
Gabriel Somlo 9521270
index 0000000..1955493
Gabriel Somlo 9521270
--- /dev/null
Gabriel Somlo 9521270
+++ b/docs/markdown_code_symlinks.py
Gabriel Somlo 9521270
@@ -0,0 +1,179 @@
Gabriel Somlo 9521270
+import logging
Gabriel Somlo 9521270
+import os
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+from recommonmark import transform
Gabriel Somlo 9521270
+"""
Gabriel Somlo 9521270
+Allow linking of Markdown documentation from the source code tree into the Sphinx
Gabriel Somlo 9521270
+documentation tree.
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+The Markdown documents will have links relative to the source code root, rather
Gabriel Somlo 9521270
+than the place they are now linked too - this code fixes these paths up.
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+We also want links from two Markdown documents found in the Sphinx docs to
Gabriel Somlo 9521270
+work, so that is also fixed up.
Gabriel Somlo 9521270
+"""
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+def path_contains(parent_path, child_path):
Gabriel Somlo 9521270
+    """Check a path contains another path.
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    >>> path_contains("a/b", "a/b")
Gabriel Somlo 9521270
+    True
Gabriel Somlo 9521270
+    >>> path_contains("a/b", "a/b/")
Gabriel Somlo 9521270
+    True
Gabriel Somlo 9521270
+    >>> path_contains("a/b", "a/b/c")
Gabriel Somlo 9521270
+    True
Gabriel Somlo 9521270
+    >>> path_contains("a/b", "c")
Gabriel Somlo 9521270
+    False
Gabriel Somlo 9521270
+    >>> path_contains("a/b", "c/b")
Gabriel Somlo 9521270
+    False
Gabriel Somlo 9521270
+    >>> path_contains("a/b", "c/../a/b/d")
Gabriel Somlo 9521270
+    True
Gabriel Somlo 9521270
+    >>> path_contains("../a/b", "../a/b/d")
Gabriel Somlo 9521270
+    True
Gabriel Somlo 9521270
+    >>> path_contains("../a/b", "../a/c")
Gabriel Somlo 9521270
+    False
Gabriel Somlo 9521270
+    >>> path_contains("a", "abc")
Gabriel Somlo 9521270
+    False
Gabriel Somlo 9521270
+    >>> path_contains("aa", "abc")
Gabriel Somlo 9521270
+    False
Gabriel Somlo 9521270
+    """
Gabriel Somlo 9521270
+    # Append a separator to the end of both paths to work around the fact that
Gabriel Somlo 9521270
+    # os.path.commonprefix does character by character comparisons rather than
Gabriel Somlo 9521270
+    # path segment by path segment.
Gabriel Somlo 9521270
+    parent_path = os.path.join(os.path.normpath(parent_path), '')
Gabriel Somlo 9521270
+    child_path = os.path.join(os.path.normpath(child_path), '')
Gabriel Somlo 9521270
+    common_path = os.path.commonprefix((parent_path, child_path))
Gabriel Somlo 9521270
+    return common_path == parent_path
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+def relative(parent_dir, child_path):
Gabriel Somlo 9521270
+    """Get the relative between a path that contains another path."""
Gabriel Somlo 9521270
+    child_dir = os.path.dirname(child_path)
Gabriel Somlo 9521270
+    assert path_contains(parent_dir, child_dir), "{} not inside {}".format(
Gabriel Somlo 9521270
+        child_path, parent_dir)
Gabriel Somlo 9521270
+    return os.path.relpath(child_path, start=parent_dir)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+class MarkdownCodeSymlinks(transform.AutoStructify, object):
Gabriel Somlo 9521270
+    docs_root_dir = os.path.realpath(os.path.dirname(__file__))
Gabriel Somlo 9521270
+    code_root_dir = os.path.realpath(os.path.join(docs_root_dir, "..", ".."))
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    mapping = {
Gabriel Somlo 9521270
+        'docs2code': {},
Gabriel Somlo 9521270
+        'code2docs': {},
Gabriel Somlo 9521270
+    }
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    @classmethod
Gabriel Somlo 9521270
+    def relative_code(cls, url):
Gabriel Somlo 9521270
+        """Get a value relative to the code directory."""
Gabriel Somlo 9521270
+        return relative(cls.code_root_dir, url)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    @classmethod
Gabriel Somlo 9521270
+    def relative_docs(cls, url):
Gabriel Somlo 9521270
+        """Get a value relative to the docs directory."""
Gabriel Somlo 9521270
+        return relative(cls.docs_root_dir, url)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    @classmethod
Gabriel Somlo 9521270
+    def add_mapping(cls, docs_rel, code_rel):
Gabriel Somlo 9521270
+        assert docs_rel not in cls.mapping['docs2code'], """\
Gabriel Somlo 9521270
+Assertion error! Document already in mapping!
Gabriel Somlo 9521270
+    New Value: {}
Gabriel Somlo 9521270
+Current Value: {}
Gabriel Somlo 9521270
+""".format(docs_rel, cls.mapping['docs2code'][docs_rel])
Gabriel Somlo 9521270
+        assert code_rel not in cls.mapping['code2docs'], """\
Gabriel Somlo 9521270
+Assertion error! Document already in mapping!
Gabriel Somlo 9521270
+    New Value: {}
Gabriel Somlo 9521270
+Current Value: {}
Gabriel Somlo 9521270
+""".format(docs_rel, cls.mapping['code2docs'][code_rel])
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        cls.mapping['docs2code'][docs_rel] = code_rel
Gabriel Somlo 9521270
+        cls.mapping['code2docs'][code_rel] = docs_rel
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    @classmethod
Gabriel Somlo 9521270
+    def find_links(cls):
Gabriel Somlo 9521270
+        """Walk the docs dir and find links to docs in the code dir."""
Gabriel Somlo 9521270
+        for root, dirs, files in os.walk(cls.docs_root_dir):
Gabriel Somlo 9521270
+            for fname in files:
Gabriel Somlo 9521270
+                fpath = os.path.abspath(os.path.join(root, fname))
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+                if not os.path.islink(fpath):
Gabriel Somlo 9521270
+                    continue
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+                link_path = os.path.join(root, os.readlink(fpath))
Gabriel Somlo 9521270
+                # Is link outside the code directory?
Gabriel Somlo 9521270
+                if not path_contains(cls.code_root_dir, link_path):
Gabriel Somlo 9521270
+                    continue
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+                # Is link internal to the docs directory?
Gabriel Somlo 9521270
+                if path_contains(cls.docs_root_dir, link_path):
Gabriel Somlo 9521270
+                    continue
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+                docs_rel = cls.relative_docs(fpath)
Gabriel Somlo 9521270
+                code_rel = cls.relative_code(link_path)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+                cls.add_mapping(docs_rel, code_rel)
Gabriel Somlo 9521270
+        import pprint
Gabriel Somlo 9521270
+        pprint.pprint(cls.mapping)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    @property
Gabriel Somlo 9521270
+    def url_resolver(self):
Gabriel Somlo 9521270
+        return self._url_resolver
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    @url_resolver.setter
Gabriel Somlo 9521270
+    def url_resolver(self, value):
Gabriel Somlo 9521270
+        print(self, value)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+    # Resolve a link from one markdown to another document.
Gabriel Somlo 9521270
+    def _url_resolver(self, ourl):
Gabriel Somlo 9521270
+        """Resolve a URL found in a markdown file."""
Gabriel Somlo 9521270
+        assert self.docs_root_dir == os.path.realpath(self.root_dir), """\
Gabriel Somlo 9521270
+Configuration error! Document Root != Current Root
Gabriel Somlo 9521270
+Document Root: {}
Gabriel Somlo 9521270
+ Current Root: {}
Gabriel Somlo 9521270
+""".format(self.docs_root_dir, self.root_dir)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        src_path = os.path.abspath(self.document['source'])
Gabriel Somlo 9521270
+        src_dir = os.path.dirname(src_path)
Gabriel Somlo 9521270
+        dst_path = os.path.abspath(os.path.join(self.docs_root_dir, ourl))
Gabriel Somlo 9521270
+        dst_rsrc = os.path.relpath(dst_path, start=src_dir)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        src_rdoc = self.relative_docs(src_path)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        print
Gabriel Somlo 9521270
+        print("url_resolver")
Gabriel Somlo 9521270
+        print(src_path)
Gabriel Somlo 9521270
+        print(dst_path)
Gabriel Somlo 9521270
+        print(dst_rsrc)
Gabriel Somlo 9521270
+        print(src_rdoc)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        # Is the source document a linked one?
Gabriel Somlo 9521270
+        if src_rdoc not in self.mapping['docs2code']:
Gabriel Somlo 9521270
+            # Don't do any rewriting on non-linked markdown.
Gabriel Somlo 9521270
+            url = ourl
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        # Is the destination also inside docs?
Gabriel Somlo 9521270
+        elif dst_rsrc not in self.mapping['code2docs']:
Gabriel Somlo 9521270
+            # Return a path to the GitHub repo.
Gabriel Somlo 9521270
+            url = "{}/blob/master/{}".format(
Gabriel Somlo 9521270
+                self.config['github_code_repo'], dst_rsrc)
Gabriel Somlo 9521270
+        else:
Gabriel Somlo 9521270
+            url = os.path.relpath(
Gabriel Somlo 9521270
+                os.path.join(
Gabriel Somlo 9521270
+                    self.docs_root_dir, self.mapping['code2docs'][dst_rsrc]),
Gabriel Somlo 9521270
+                start=src_dir)
Gabriel Somlo 9521270
+            base_url, ext = os.path.splitext(url)
Gabriel Somlo 9521270
+            assert ext in (".md",
Gabriel Somlo 9521270
+                           ".markdown"), ("Unknown extension {}".format(ext))
Gabriel Somlo 9521270
+            url = "{}.html".format(base_url)
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+        print("---")
Gabriel Somlo 9521270
+        print(ourl)
Gabriel Somlo 9521270
+        print(url)
Gabriel Somlo 9521270
+        print
Gabriel Somlo 9521270
+        return url
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+
Gabriel Somlo 9521270
+if __name__ == "__main__":
Gabriel Somlo 9521270
+    import doctest
Gabriel Somlo 9521270
+    doctest.testmod()
Gabriel Somlo 9521270
diff --git a/docs/requirements.txt b/docs/requirements.txt
Gabriel Somlo 9521270
index ec9e872..56c1f78 100644
Gabriel Somlo 9521270
--- a/docs/requirements.txt
Gabriel Somlo 9521270
+++ b/docs/requirements.txt
Gabriel Somlo 9521270
@@ -1,13 +1,8 @@
Gabriel Somlo 9521270
-sphinx_materialdesign_theme
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
 docutils
Gabriel Somlo 9521270
 sphinx
Gabriel Somlo 9521270
 sphinx-autobuild
Gabriel Somlo 9521270
 
Gabriel Somlo 9521270
 breathe
Gabriel Somlo 9521270
 recommonmark
Gabriel Somlo 9521270
-sphinx-markdown-tables
Gabriel Somlo 9521270
+sphinx_rtd_theme
Gabriel Somlo 9521270
 sphinxcontrib-napoleon
Gabriel Somlo 9521270
-
Gabriel Somlo 9521270
-# Markdown cross-reference solver library
Gabriel Somlo 9521270
-git+https://github.com/SymbiFlow/sphinxcontrib-markdown-symlinks
Gabriel Somlo 9521270
-- 
Gabriel Somlo 9521270
2.21.0
Gabriel Somlo 9521270