-
-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Added API link in examples #1013
Changes from 3 commits
956bf19
0dfb396
2057b29
1960c82
8b2b091
4d3722c
c3836bb
cdbb491
f38487b
2db39c2
08f36a4
23fd65d
878e4e3
dc25a7b
d09f07c
c013176
691d8af
a2b9bfd
0033ddf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ def execfile(filename, globals=None, locals=None): | |
.. image:: {img_file} | ||
|
||
**Python source code:** :download:`[download source: {fname}]<{fname}>` | ||
**API documentation:** `{api_name} <../../generated/arviz.{api_name}>`_ | ||
|
||
.. literalinclude:: {fname} | ||
:lines: {end_line}- | ||
|
@@ -54,6 +55,7 @@ def execfile(filename, globals=None, locals=None): | |
:source-position: none | ||
|
||
**Python source code:** :download:`[download source: {fname}]<{fname}>` | ||
**API documentation:** `{api_name} <../../generated/arviz.{api_name}>`_ | ||
|
||
.. literalinclude:: {fname} | ||
:lines: {end_line}- | ||
|
@@ -236,6 +238,16 @@ def thumbfilename(self): | |
pngfile = self.modulename + "_thumb.png" | ||
return pngfile | ||
|
||
@property | ||
def apiname(self): | ||
name="" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just return None if nothing is found? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, make sense. |
||
with open(op.join(self.target_dir, self.pyfilename), "r") as file: | ||
regex = r"az\.(plot\_[a-z_]+)\(" | ||
percygautam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matches = re.finditer(regex, file.read(), re.MULTILINE) | ||
for matchNum, match in enumerate(matches, start=1): | ||
name = match.group(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this return the last found Do you think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the first is enough, there is only a couple of cases where more than a function is called, and in these cases the function called is always the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahartikainen @OriolAbril I worked some examples and let's say we have a hypothetical code as:
If we run our code, it will return the last found match as 'plot_density'. As in our example files, we are only calling the function one time, so I don't think it'll be a problem.
And then maybe check the length when rendering it in the template.
How should we do it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using only the first function is good enough for that. Returning the list with all occurrences seems like an overkill which complicates the code without much gain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll do it. |
||
return name | ||
|
||
@property | ||
def sphinxtag(self): | ||
return self.modulename | ||
|
@@ -380,6 +392,7 @@ def main(app): | |
fname=ex.pyfilename, | ||
absfname=op.join(target_dir, ex.pyfilename), | ||
img_file=ex.pngfilename, | ||
api_name=ex.apiname, | ||
) | ||
with open(op.join(target_dir, ex.rstfilename), "w") as f: | ||
f.write(output) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be changed to
{api_text}
so that below, if api_name is None nothing is written?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OriolAbril , I have done the changes, now it'll show
None <None>
and not the directory link.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more clear replacing the whole line, so that when no match is fount (e.g. styles case) instead of
**API doc...
a white line is written. Or alternatively something like:I see myself some months from now confusing the
None <None>
with a doc generation error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OriolAbril I understand your point. I have done the changes. Now, it'll show something like:
We can't specify the name of documentation available because
api_name
would be an open string and other params likemodulename
will be in the form ofbackend_xyz
. If we must do this then we have to use regex again or split the name and then pass to the new variable.