-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Add support for Property and missing content #41
Conversation
docfx_yaml/extension.py
Outdated
# Only add summary to parts of the code that we don't get it from the monkeypatch | ||
if _type == MODULE: | ||
summary_info = { | ||
'variables': {}, # Stores mapping of variables and its description, types |
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.
Missing something after "types" in the comment?
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.
meant to say and, will add &
'exceptions': [] # Stores the exception info | ||
} | ||
|
||
# Add extracted summary |
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.
Is there any of this we can pull out into separate functions? The indentation gets pretty deep here, making it more difficult to follow.
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.
+1
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'll create a separate function for it. I agree it was slightly hectic to follow myself.
docfx_yaml/extension.py
Outdated
|
||
if args or sig: | ||
# Clean the string by cleaning newlines and backlashes, then split by white space. | ||
parsed_text = " ".join(filter(None, re.split('\n| |\\\\',summary))).split(" ") |
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.
Should we handle all forms of whitespace (\s
)?
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 we should, given that we're not sure how Sphinx might port over the docs (it gets easily littered with newlines and carriage returns)
docfx_yaml/extension.py
Outdated
|
||
if args or sig: | ||
# Clean the string by cleaning newlines and backlashes, then split by white space. | ||
parsed_text = " ".join(filter(None, re.split('\n| |\\\\',summary))).split(" ") |
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.
Use r'...'
to avoid escaping issues?
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.
Will update for readability.
docfx_yaml/extension.py
Outdated
|
||
# Using counter iteration to easily extract names rather than | ||
# coming up with more complicated stopping logic for each tags. | ||
while index <= len(parsed_text): |
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.
Overall comment: I'm surprised Sphinx doesn't handle this parsing under the hood. If it doesn't and we have to do this, that's fine. But, just commenting to confirm there isn't some sort of already-parsed representation of the comment?
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.
After some research I've found this docstring module which helps take in GoogleDocstrings and clean things up. This would help clean the above few lines.
Given this reStructuredText
format, Sphinx is able to display them nicely like shown here; however since we need to port these into the YAMLs the parser here would be necessary to implement.
I'll clean the code here as much as I can!
@@ -70,7 +70,9 @@ class Bcolors: | |||
REFMETHOD = 'meth' | |||
REFFUNCTION = 'func' | |||
INITPY = '__init__.py' | |||
REF_PATTERN = ':(py:)?(func|class|meth|mod|ref):`~?[a-zA-Z_\.<> ]*?`' | |||
REF_PATTERN = ':(py:)?(func|class|meth|mod|ref|attr|exc):`~?[a-zA-Z0-9_\.<> ]*?`' |
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.
Overall comment (not just this line): Any tests for this file/these changes?
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'll add some files for tests since we have the infrastructure for it already.
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.
Are there tests that verify the 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.
I've realized the test simply generates content but it doesn't seem to verify the output. Filed #44 to track this, after offline chat moving forward at the moment with generation part and adding back the verification after.
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.
It's odd that this needs to be handled separately. The docstrings in spanner are considered "default" by sphinx. The docstrings you see in the generated libraries and most newer libraries are "google style" and are processed through the Napoleon package. https://sphinxcontrib-napoleon.readthedocs.io/en/latest/index.html
docfx_yaml/extension.py
Outdated
try: | ||
lines = inspect.getdoc(obj) | ||
lines = lines.split("\n") if lines else [] | ||
except Exception as e: |
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.
Is it possible to capture a more specific Exception type?
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.
Will update to reflect more specific types.
'exceptions': [] # Stores the exception info | ||
} | ||
|
||
# Add extracted summary |
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.
+1
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.
Thanks for the feedback! @busunkim96 I was able to find the napoleon module however since Sphinx stops after having reStructuredText
I'd still have to take that and convert them to YAML friendly structure, needing this parser. I'll clean the code up in a bit.
docfx_yaml/extension.py
Outdated
# Only add summary to parts of the code that we don't get it from the monkeypatch | ||
if _type == MODULE: | ||
summary_info = { | ||
'variables': {}, # Stores mapping of variables and its description, types |
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.
meant to say and, will add &
'exceptions': [] # Stores the exception info | ||
} | ||
|
||
# Add extracted summary |
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'll create a separate function for it. I agree it was slightly hectic to follow myself.
docfx_yaml/extension.py
Outdated
|
||
if args or sig: | ||
# Clean the string by cleaning newlines and backlashes, then split by white space. | ||
parsed_text = " ".join(filter(None, re.split('\n| |\\\\',summary))).split(" ") |
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 we should, given that we're not sure how Sphinx might port over the docs (it gets easily littered with newlines and carriage returns)
docfx_yaml/extension.py
Outdated
|
||
if args or sig: | ||
# Clean the string by cleaning newlines and backlashes, then split by white space. | ||
parsed_text = " ".join(filter(None, re.split('\n| |\\\\',summary))).split(" ") |
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.
Will update for readability.
docfx_yaml/extension.py
Outdated
try: | ||
lines = inspect.getdoc(obj) | ||
lines = lines.split("\n") if lines else [] | ||
except Exception as e: |
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.
Will update to reflect more specific types.
@@ -70,7 +70,9 @@ class Bcolors: | |||
REFMETHOD = 'meth' | |||
REFFUNCTION = 'func' | |||
INITPY = '__init__.py' | |||
REF_PATTERN = ':(py:)?(func|class|meth|mod|ref):`~?[a-zA-Z_\.<> ]*?`' | |||
REF_PATTERN = ':(py:)?(func|class|meth|mod|ref|attr|exc):`~?[a-zA-Z0-9_\.<> ]*?`' |
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'll add some files for tests since we have the infrastructure for it already.
docfx_yaml/extension.py
Outdated
|
||
# Using counter iteration to easily extract names rather than | ||
# coming up with more complicated stopping logic for each tags. | ||
while index <= len(parsed_text): |
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.
After some research I've found this docstring module which helps take in GoogleDocstrings and clean things up. This would help clean the above few lines.
Given this reStructuredText
format, Sphinx is able to display them nicely like shown here; however since we need to port these into the YAMLs the parser here would be necessary to implement.
I'll clean the code here as much as I can!
Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
Updated to address the following:
|
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.
Overall, looks good. Still more manual parsing than I'd like, but it sounds like it's necessary.
@@ -70,7 +70,9 @@ class Bcolors: | |||
REFMETHOD = 'meth' | |||
REFFUNCTION = 'func' | |||
INITPY = '__init__.py' | |||
REF_PATTERN = ':(py:)?(func|class|meth|mod|ref):`~?[a-zA-Z_\.<> ]*?`' | |||
REF_PATTERN = ':(py:)?(func|class|meth|mod|ref|attr|exc):`~?[a-zA-Z0-9_\.<> ]*?`' |
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.
Are there tests that verify the output?
Before you open a pull request, note that this repository is forked from here.
Unless the issue you're trying to solve is unique to this specific repository,
please file an issue and/or send changes upstream to the original as well.
While investigating for adding support for property, I managed to add a section for content discrepancy as both fo them seem to be missing with the newer Sphinx upgrade from 1.x to 2.1.0+
This PR achieves the following:
:type
,:rtype:
,:returns:
,:raises
, and:param
@busunkim96 I added handlers for subsections based on the 5 given above from
python-spanner
, for example:given with such documentation support. Should I expect the client libraries to be accustomed to this, or should I take a more general approach and try to guess based on given parameters or simply leave them blank if I'm not given these in the documentation?
Fixes #40