-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tweak docs and add links between sites
- Loading branch information
1 parent
7fc2966
commit 5eca95d
Showing
8 changed files
with
167 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Code taken from: | ||
https://github.com/scikit-learn/scikit-learn/blob/8721245511de2f225ff5f9aa5f5fadce663cd4a3/doc/sphinxext/github_link.py | ||
""" | ||
import inspect | ||
import os | ||
import subprocess | ||
import sys | ||
from functools import partial | ||
from operator import attrgetter | ||
|
||
REVISION_CMD = "git rev-parse --short HEAD" | ||
|
||
|
||
def _get_git_revision(): | ||
try: | ||
revision = subprocess.check_output(REVISION_CMD.split()).strip() | ||
except (subprocess.CalledProcessError, OSError): | ||
print("Failed to execute git to get revision") | ||
return None | ||
return revision.decode("utf-8") | ||
|
||
|
||
def _linkcode_resolve(domain, info, package, url_fmt, revision): | ||
"""Determine a link to online source for a class/method/function | ||
This is called by sphinx.ext.linkcode | ||
An example with a long-untouched module that everyone has | ||
>>> _linkcode_resolve('py', {'module': 'tty', | ||
... 'fullname': 'setraw'}, | ||
... package='tty', | ||
... url_fmt='https://hg.python.org/cpython/file/' | ||
... '{revision}/Lib/{package}/{path}#L{lineno}', | ||
... revision='xxxx') | ||
'https://hg.python.org/cpython/file/xxxx/Lib/tty/tty.py#L18' | ||
""" | ||
if revision is None: | ||
return | ||
if domain not in ("py", "pyx"): | ||
return | ||
if not info.get("module") or not info.get("fullname"): | ||
return | ||
|
||
class_name = info["fullname"].split(".")[0] | ||
module = __import__(info["module"], fromlist=[class_name]) | ||
|
||
try: | ||
obj = attrgetter(info["fullname"])(module) | ||
except AttributeError: | ||
return | ||
|
||
# Unwrap the object to get the correct source | ||
# file in case that is wrapped by a decorator | ||
obj = inspect.unwrap(obj) | ||
|
||
try: | ||
fn = inspect.getsourcefile(obj) | ||
except Exception: | ||
fn = None | ||
if not fn: | ||
try: | ||
fn = inspect.getsourcefile(sys.modules[obj.__module__]) | ||
except Exception: | ||
fn = None | ||
if not fn: | ||
return | ||
|
||
fn = os.path.relpath(fn, start=os.path.dirname(__import__(package).__file__)) | ||
try: | ||
lineno = inspect.getsourcelines(obj)[1] | ||
except Exception: | ||
lineno = "" | ||
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno) | ||
|
||
|
||
def make_linkcode_resolve(package, url_fmt): | ||
"""Returns a linkcode_resolve function for the given URL format | ||
revision is a git commit reference (hash or name) | ||
package is the name of the root module of the package | ||
url_fmt is along the lines of ('https://github.com/USER/PROJECT/' | ||
'blob/{revision}/{package}/' | ||
'{path}#L{lineno}') | ||
""" | ||
revision = _get_git_revision() | ||
return partial( | ||
_linkcode_resolve, revision=revision, package=package, url_fmt=url_fmt | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters