-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix cite decorator * Remove dead references in docs * Update CHANGELOG.md
- Loading branch information
1 parent
c40fa70
commit 099bc55
Showing
5 changed files
with
22 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
def cite(bibtex): | ||
"""A decorator which adds a reference to the docstring of the given object. The docstring must contain ':bib:' which | ||
is then replaced with the given bibtex string at runtime. | ||
"""A decorator which adds a reference to the **Google style** docstring of the given object. The ``Args:`` or | ||
``Returns:`` line is then prepended with the given bibtex string at runtime. Otherwise, the last line is used. | ||
Args: | ||
bibtex (str): The bibtex string to insert | ||
Returns: | ||
The decorator | ||
""" | ||
to_insert = '::\n\n' + ' '*8 | ||
to_insert += bibtex.strip().replace('\n', '\n' + ' '*8).rstrip() | ||
|
||
def decorator(inner): | ||
inner.__doc__ = inner.__doc__.replace(':bib:', to_insert) | ||
doc = inner.__doc__.split('\n') | ||
i = 0 | ||
s = 0 | ||
for line in doc: | ||
sline = line.strip() | ||
if sline == 'Args:' or sline == 'Returns:': | ||
for char in line: | ||
if char == ' ': | ||
s += 1 | ||
break | ||
i += 1 | ||
|
||
spaces = ' ' * (s + 4) | ||
to_insert = ' ' * s + '::\n\n' + spaces | ||
to_insert += bibtex.strip().replace('\n', '\n' + spaces).rstrip() | ||
|
||
doc.insert(i, '') | ||
doc.insert(i, to_insert) | ||
inner.__doc__ = '\n'.join(doc) | ||
return inner | ||
return decorator |
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
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