Conversation
joeperpetua
left a comment
There was a problem hiding this comment.
Thanks for the PR! It is very well explained and researched.
I made a few minor suggestions inline, please take a look.
Regarding the new parsing approach, since extract_file_info is effectively becoming a custom AST parser, I think we should move it to its own module. Keeping it separate from the main logic and helpers would make the parser much more approachable for new contributors (we could do the same for the styling helpers, too).
Let me know if you have time/would like to tackle that refactor in this PR. If not, we can merge this as-is and handle the cleanup in the future.
Co-authored-by: Joel Perpetua <[email protected]>
Thanks for the follow up. Factoring out the parser and formatter as their own modules would certainly look cleaner. I can take care of that directly in the PR. Where do you suggest these new files be created ? Maybe some new 'docs_parser' folder ? |
|
I think we can move the docs_parser.py For example:
Then we should be able to run it as a module from root What do you think? |
|
I think that |
|
I've made some further modification to I took the liberty of changing the yaml syntax from single-key-dict lists to standard dict listing. I believe this has a few advantages: warnings/error on duplicates + more direct parsing. Also, the sorting (for sidebar display positions) is explicitly performed in the code now instead of relying on manual item ordering. This is minor but can be reverted if preferable in the previous form. |
…removed 'docstring_extractor' package)
…string_parser' package version)
|
Things look good now. I'm marking the PR ready for review, but don't hesitate to let me know if some more tweaks are needed. One last suggestion would be to bump the docusaurus version (latest is |
joeperpetua
left a comment
There was a problem hiding this comment.
Everything looks good to me, great job!
The parser will be now way easier to maintain/scale. The changes for the docs_status is a good addition 👍
I will make a new issue for the docusaurus update as it is not that much related to this PR.
|
Validation checks should now pass: fixed the pre-commit failure. |
Improvement suggestion for
docs_parser.pyscriptMotivation
Add more flexibility for the parsing of internal api names. Current implementation relies on regex parsing of each .py file's source, looking for
"api_name = <...>"(e.g.api_name = "SYNO.Core.X.Y") in methods of the implemented classes.One suggestion, implemented in this PR, is to allow for class-scope attributes
_API_NAME = ...or_api_name = ..., to be interpreted as the default internal API for methods of that class, if not otherwise specified (byapi_name = ...).In addition, current regex implementation comes with at least two bugs:
The
METHOD_API_NAME_PATTERN()regex leaks from a given method'sdef x():to subsequent ones: if a method does not includeapi_name = ...but a subsequent one in the file does, it is the latter that gets wrongly matched as "internal API" of the method. No warning is issued in the process. This currently concerns the following methods:core_certificate.py, classCertificatephotos.py, classPhotosdirectory_server.py: classDirectoryServercore_package.py: classPackageFor files implementing multiple classes, the "Supported APIs" list doesn't properly gather API names by class. See the (only) example of
Share/SharePermission/KeyManagerStore/KeyManagerAutoKeyclasses fromcore_share.py. Currently, all APIs of a file are listed under each class of that file.Proposition
File parsing is now performed through recursive walk of
ast.tree. This operation was performed anyway throughdocstring_extractorpackage helpers. It is now explicit and allows for a more flexible identification of the file structure, in particular of api_names. More specifically, theastparser now looks up for assignments of the form_API_NAME = ...or_api_name = ...in class-scope nodesapi_name = ...in method-scope nodesWhen provided, class-level attribute
_API_NAMEacts as the default internal API name for all contained methods. It gets overridden by method-scopeapi_name = ...when also provided.Misc. changes and improvements
docs/apis/readme.md) is now sorted alphabetically. Idem for per-class sublists of internal APIs..mdfiles, yielding better looking raw markdown docfiles (in particular<div></div>blocks featuring markdown text decoration)docs-parsertask underTaskfile.yamlto include-largument when executingdocs_parser.py. The task now generates the API list (docs/apis/readme.md)Tests & output
Proposed implementation seems to provide expected output at the markdown and docusaurus level. Correcting bugs 1. and 2. above removed internal API names for cited methods (previously off). This will be corrected by updating mis-formed methods in the concerned classes.