-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Markdown to SpecObject refactoring #4330
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
base: dev
Are you sure you want to change the base?
Conversation
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.
Hey @leolara, thanks for cleaning this up. I agree this is better than the current code. I've left some comments with various changes I'd like to see.
pysetup/mk_to_spec.py
Outdated
def run(self) -> SpecObject: | ||
""" | ||
Orchestrates the parsing and processing of the markdown spec file. | ||
- Calls _parse_document() | ||
- Iterates over self.document.children and processes each child | ||
- Calls _finalize_types() and _build_spec_object() after processing | ||
Returns: | ||
SpecObject: The constructed specification object. | ||
""" | ||
while (child := self._get_next_element()) is not None: | ||
self._process_child(child) | ||
self._finalize_types() | ||
return self._build_spec_object() |
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'm not a fan of comments which just outline what the function does. Especially when it's wrong... For example, this function does not call _parse_document()
. Also the list items are missing punctuation. Let's just simplify this (and remove the fancy "orchestrates" word, did AI write this function?). Maybe something like:
"""
Returns parsed markdown specification.
"""
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.
Sorry, it was the original implementation that was calling _parse_document, I will review the comments
pysetup/mk_to_spec.py
Outdated
def _has_decorator(decorateable: ast.ClassDef | ast.FunctionDef, name: str) -> bool: | ||
return any(_is_decorator(d, name) for d in decorateable.decorator_list) |
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.
Why is this function outside of the class? It's only used in the class.
tests/infra/test_mk_to_spec.py
Outdated
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.
Testing this is a good idea, thanks. Reminder to rename the file.
Hey @leolara, I've merged the following PR. Could you pull in these changes & run |
Also regarding this, the current version of
|
I updated the comment because it was explained wrong:
|
5df98f3
to
af4b2b4
Compare
Ah but this is intentional. I want this to happen 🙂 |
Current status:
To be discussed:
After review:
|
Yes, that one, it is solved now because it uses the AST to get the name of the class |
I changed it to |
I understand there are two categories, what I am saying that perhaps the rule for which category could be simpler. Like Currently the rule is:
Should it be like this or is there a simplified version that doesn't have error? Like:
|
There's sort of an implicit check here. I don't think we want to allow classes that aren't one of those categories. I get what you're suggesting, I'm just not sure if it's a good idea. Might be best to save this for later, so we can think more about it. |
I think I have done everything you mentioned @jtraglia ; have another look and then I will remove the old implementation |
Yup, it looks great 😄 let's proceed. |
Summary
This pull request introduces a refactoring effort, focusing on modularizing and improving the maintainability of the specification parsing logic. The changes include updates to the Makefile, the addition of a new Python module (
mk_to_spec.py
). The primary goal is to replace theget_spec
function with the newMarkdownToSpec
class, ensuring functional equivalence during the transition phase.Questions
@dataclass
in one category, and if they don't have@dataclass
and inherit fromContainer
in another one. Error in any other case. For the second category wouldn't it make sense to belong there if you inherit fromContainer
? Regardless if you have@dataclass
or not?None
as index. I assumed this was a bug and I fixed it.config_vars: Dict[str, VariableDefinition]
but we are not using them that way, I guess I should change the typing to reflect how it is actually used?Changes
1. New Module:
mk_to_spec.py
mk_to_spec.py
under thepysetup
directory.SpecObject
).get_spec
function where dataclass names were not being parsed correctly.2. Makefile Updates
test
target to include thetests/infra
directory in the test suite.clean
target to only remove files that are generated by the build, and not remove all the files that are not being tracked.3. Dependency Updates
deepdiff==8.5.0
to thepyproject.toml
file for deep comparison of Python objects.4. Enhancements to
setup.py
MarkdownToSpec
class frommk_to_spec.py
.get_spec_new
to utilize theMarkdownToSpec
class for generating specification objects.build_spec
function to compare the new and old specification generation methods usingDeepDiff
to ensure consistency.Refactoring Details
MarkdownToSpec
class is a refactored and enhanced version of theget_spec
function, offering better modularity, maintainability, and feature support.MarkdownToSpec
identical in input/output toget_spec
with the only difference that was previously adding classes withNone
index to thedataclass
dictionary, and I think this was a bug.get_spec
function remains in place temporarily to validate the functional equivalence of the new implementation.build_spec
function includes assertions to compare the outputs ofget_spec
andMarkdownToSpec
usingDeepDiff
.MarkdownToSpec
class is reviewed and validated, theget_spec
function will be removed, as well as auxiliary functions copied topysetup/mk_to_spec.py
andDeedDiff
dependency.Testing
MarkdownToSpec
class produces consistent results with the existingget_spec
function.setup.py
to ensure that the new and old methods produce identical outputs.tests/infra
directory. And added there test for the newMarkdownToSpec
class.Impact