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
[MAINTENANCE] Use shortened dotted paths in api docs #6831
[MAINTENANCE] Use shortened dotted paths in api docs #6831
Conversation
✅ Deploy Preview for niobium-lead-7998 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
👇 Click on the image for a new way to code review
Legend |
def get_shortest_dotted_path( | ||
definition: Definition, repo_root_path: pathlib.Path | ||
) -> str: |
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.
❤️
while path_parts: | ||
# Keep traversing, shortening path if shorter path is found. | ||
path_parts.pop() | ||
# if __init__.py is found, ast parse and check for import of the class | ||
init_path = repo_root_path / pathlib.Path(*path_parts, "__init__.py") | ||
if init_path.is_file(): | ||
|
||
import_names = [] | ||
with open(init_path) as f: | ||
file_contents: str = f.read() | ||
|
||
import_names.extend(_get_import_names(file_contents)) | ||
|
||
# If name is found in imports, shorten path to where __init__.py is found | ||
if definition.name in import_names: | ||
shortest_path_prefix = str(".".join(path_parts)) | ||
shortest_path = f"{shortest_path_prefix}.{definition.name}" | ||
|
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.
❤️
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.
love it. Thank you @anthonyburdi
Changes proposed in this pull request:
__init__.py
file use that instead of the file with the class definition. For example,great_expectations.core.ExpectationSuite
instead ofgreat_expectations.core.expectation_suite.ExpectationSuite
. This appears in API docs in the class definitions.Definition of Done