-
Notifications
You must be signed in to change notification settings - Fork 14
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
Create and test Node and ItemNode #72
Conversation
d0a6722
to
9e8eb4f
Compare
Codecov Report
@@ Coverage Diff @@
## master #72 +/- ##
=========================================
Coverage ? 87.64%
=========================================
Files ? 7
Lines ? 688
Branches ? 0
=========================================
Hits ? 603
Misses ? 85
Partials ? 0
Continue to review full report at Codecov.
|
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.
Great start! I have some nits in-line.
Thanks for the feedback! I addressed some of the comments-- I'll try to address the rest of them with the following:
|
Documentation/testing sprint done! While doing that I also changed the constructor a bit-- I moved the I pushed a branch at |
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 have some more nitpicks for your consideration. I hope you do not mind (yet). ;-)
@etingof this is ready for more review, when you have time ^_^ Biggest change is moving the docs to Napoleon per your suggestion-- the docs are definitely a lot cleaner now. |
Awesome! Thank you for the heads up - I've been sidetracked by the upcoming conference. I will get back to this shortly. |
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 am sorry for it has taken that long!
I've done another round, I think the code is in a good shape! I have a couple of nits for your consideration.
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.
First of all, I am terribly sorry for long delays! But the good news is that I am hopefully back from my conference preparations!
I've posted some more nits, these are the side-effect of my trying to understand the new design. Those are mostly nits, in my mind they might be helpful for the human reader to understand the arrangements. WDYT?
I will now proceed to the next PRs.
apacheconfig/wloader.py
Outdated
[_restore_original(word) for word in self._raw]))) | ||
|
||
|
||
def native_apache_parser(options=None): |
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 seems that this method mainly applies some specific options to lexer/parser/config objects. In some sense, the instantiation code is not relevant to this purpose, right?
So what if we introduce some sort of syntax "flavors" i.e. sets of options, perhaps as global constants, that the user can just pick or mix and match to specialize parsing suite to the desired syntax?
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.
Yes, I like the idea of having and exporting a set of common option configurations. Something like NATIVE_APACHE_PARSER_OPTIONS
?
The motivation behind this was primarily to have a simpler interface for creating a native Apache parser-- would you prefer not to increase the surface area of exported functions to maintain? Either way is fine by me.
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.
Yes, I like the idea of having and exporting a set of common option configurations. Something like
NATIVE_APACHE_PARSER_OPTIONS
?
Yeah... BTW, with current design the options are not only for the parser, but for lexer and loader as well.
The motivation behind this was primarily to have a simpler interface for creating a native Apache parser-- would you prefer not to increase the surface area of exported functions to maintain? Either way is fine by me.
I'd try not to introduce something overly specific and not likely reusable whenever possible.
How about this:
from apacheconfig import flavors
from apachaconfig import make_loader
with make_loader(**flavors.NATIVE_APACHE) as loader:
...
If we also need just parser or just lexer, would it make sense to have similar functions for them? Or may be we can rename & parameterize make_loader
so that it would become a universal factory function?
Either way, this factory function(s) would be driven by pre-defined and/or user-specified options (flavors, in my snippet).
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 a fan of exposing the option sets (flavors
, as you put it) for the time being-- I have to think a bit more on what the factory function might look like, maybe once the other interfaces are in.
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 am thinking, that functionally we specialize parser to work on a specific kind (flavor) of grammar. Each flavor can be composed from a bunch of options.
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 gave it a shot with a flavors.py
-- lmk what you think!
No worries at all! Thanks for working with us on this :)
Naming is difficult, so I appreciate your input here! I think they make sense. Took your suggestions. |
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.
The new code makes sense to me so far!
I am curious if this factory context manager:
@contextmanager
def make_loader(**options):
ApacheConfigLexer = make_lexer(**options)
ApacheConfigParser = make_parser(**options)
yield ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()),
**options)
Could be generalized to simplify this code:
ApacheConfigLexer = make_lexer(**flavors.NATIVE_APACHE)
ApacheConfigParser = make_parser(**flavors.NATIVE_APACHE)
self.parser = ApacheConfigParser(ApacheConfigLexer(), start="contents")
Re: the |
Alright, so what's remaining for this PR to be merged? My only question so far is possible repetitive parser re-creation. Is this a valid concern? |
That fix should be coming in the downstream PR! |
(To be specific, since the LeafNode doesn't contain any other config items, it doesn't need a reference to a parser since it doesn't do any parsing) |
Thank you! \o/ |
We should probably update |
Another unrelated thought: would it make sense to add "default" flavor essentially enumerating all options and their defaults? That won't technically change anything, but would probably be more illustrative and easier to change defaults. |
I think that would be good! a lot of the defaults are scattered in the codebase (using |
Fleshing out API as described in #49. Starting with generic Node and a more specific ItemNode implementation.