Skip to content

Commit 92b73af

Browse files
authored
MNT: update vendored docs script github_link.py (#3144)
<!-- Text in these brackets are comments, and won't be visible when you submit your pull request. If this is your first contribution, please take the time to read these, in particular the comment beginning "Welcome, new contributors!". --> ## Changes proposed in this pull request As far as I can see, we had just added a few lines to tell this vendored script originates in scikit-learn. File initially copied in #1258, and [not changed since](https://github.com/nipreps/fmriprep/commits/master/docs/sphinxext/github_link.py), except for #3097 which I shouldn't have applied to a vendored file.
2 parents 41d0eeb + be2168f commit 92b73af

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

docs/sphinxext/github_link.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
"""
2-
This script comes from scikit-learn:
2+
This vendored script comes from scikit-learn:
33
https://github.com/scikit-learn/scikit-learn/blob/master/doc/sphinxext/github_link.py
44
"""
5-
from operator import attrgetter
65
import inspect
7-
import subprocess
86
import os
7+
import subprocess
98
import sys
109
from functools import partial
10+
from operator import attrgetter
1111

12-
REVISION_CMD = 'git rev-parse --short HEAD'
12+
REVISION_CMD = "git rev-parse --short HEAD"
1313

1414

1515
def _get_git_revision():
1616
try:
1717
revision = subprocess.check_output(REVISION_CMD.split()).strip()
1818
except (subprocess.CalledProcessError, OSError):
19-
print('Failed to execute git to get revision')
19+
print("Failed to execute git to get revision")
2020
return None
21-
return revision.decode('utf-8')
21+
return revision.decode("utf-8")
2222

2323

2424
def _linkcode_resolve(domain, info, package, url_fmt, revision):
@@ -30,25 +30,26 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision):
3030
>>> _linkcode_resolve('py', {'module': 'tty',
3131
... 'fullname': 'setraw'},
3232
... package='tty',
33-
... url_fmt='https://hg.python.org/cpython/file/'
33+
... url_fmt='http://hg.python.org/cpython/file/'
3434
... '{revision}/Lib/{package}/{path}#L{lineno}',
3535
... revision='xxxx')
36-
'https://hg.python.org/cpython/file/xxxx/Lib/tty/tty.py#L18'
36+
'http://hg.python.org/cpython/file/xxxx/Lib/tty/tty.py#L18'
3737
"""
3838

3939
if revision is None:
4040
return
41-
if domain not in ('py', 'pyx'):
41+
if domain not in ("py", "pyx"):
4242
return
43-
if not info.get('module') or not info.get('fullname'):
43+
if not info.get("module") or not info.get("fullname"):
4444
return
4545

46-
class_name = info['fullname'].split('.')[0]
47-
if type(class_name) != str:
48-
# Python 2 only
49-
class_name = class_name.encode('utf-8')
50-
module = __import__(info['module'], fromlist=[class_name])
51-
obj = attrgetter(info['fullname'])(module)
46+
class_name = info["fullname"].split(".")[0]
47+
module = __import__(info["module"], fromlist=[class_name])
48+
obj = attrgetter(info["fullname"])(module)
49+
50+
# Unwrap the object to get the correct source
51+
# file in case that is wrapped by a decorator
52+
obj = inspect.unwrap(obj)
5253

5354
try:
5455
fn = inspect.getsourcefile(obj)
@@ -62,14 +63,12 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision):
6263
if not fn:
6364
return
6465

65-
fn = os.path.relpath(fn,
66-
start=os.path.dirname(__import__(package).__file__))
66+
fn = os.path.relpath(fn, start=os.path.dirname(__import__(package).__file__))
6767
try:
6868
lineno = inspect.getsourcelines(obj)[1]
6969
except Exception:
70-
lineno = ''
71-
return url_fmt.format(revision=revision, package=package,
72-
path=fn, lineno=lineno)
70+
lineno = ""
71+
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)
7372

7473

7574
def make_linkcode_resolve(package, url_fmt):
@@ -84,5 +83,6 @@ def make_linkcode_resolve(package, url_fmt):
8483
'{path}#L{lineno}')
8584
"""
8685
revision = _get_git_revision()
87-
return partial(_linkcode_resolve, revision=revision, package=package,
88-
url_fmt=url_fmt)
86+
return partial(
87+
_linkcode_resolve, revision=revision, package=package, url_fmt=url_fmt
88+
)

0 commit comments

Comments
 (0)