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
"Interactive mode" via editable file #362
Conversation
53686d4
to
f1cca87
Compare
… to ignore or comment options when generating examples for `--edit`
… see discussion in pyscaffold#333 for description
… this way we can also recognise custom subclasses or equivalent data types such as sets.
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.
Really nice code! I really dig the implementation of the class Interactive. Tons of small functions are used like Lego to get the job done. That's clean code for me!
from zope import subpackage | ||
# zope is the namespace and subpackage is the package name | ||
|
||
To be honest, there is really only the `Zope project <http://www.zope.org/>`_ | ||
that comes to my mind which is using this exotic feature of Python's packaging system. | ||
Chances are high, that you will never ever need a namespace package in your life. |
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 comment! I think statements like that help users a lot in figuring out which features are important for them.
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.
Hi @FlorianWilhelm thanks for the comment, the original idea of mentioning Zope is yours 😝, I added the code example with the namespaces to make it more concrete...
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.
But the sentence Chances are high, that you will never ever need a namespace package in your life.
is from you right? That's the one I was referring to.
config_from_ext = getattr(ext, CONFIG_KEY, fallback_config) | ||
return acc | set(config_from_ext.get(kind, [])) | ||
|
||
return reduce(_reducer, list_all_extensions(), initial_value) |
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.
General note: It always takes me several minutes to understand what's happening in a reduce
function and I think I am not the only one as Guido von Rossum once stated something similar. At that point, I have no better idea and this functional style is really smart but makes it also hard to understand what's going on.
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 can revert it to a more procedural approach.
The main idea is to collect all the interactive
configuration dicts from the extensions and merge them with CONFIG
.
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.
Or you add your last sentence as a comment just before the return statement to make it easier for future contributors to understand what's going on.
""" | ||
|
||
|
||
@lru_cache(maxsize=2) |
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.
Does this speed things up a lot? Just asking as introducing caching can always lead to quite subtle bugs later on.
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.
So the idea is that I call this function for every action, and everytime it loads the extensions from the entrypoints (so Python goes to setuptools files collecting entries and then do some just-in-time file loading). I am not sure how long it takes, I added the cache there just intuitively to be sincere. I agree the best would be to measure before doing any premature optimisation 😅
To be fair, once all the extension classes and entrypoints are defined, this thing should be pretty much immutable (it is config metadata after all and works as a "distributed" constant across the extensions)... There could be problems if we are messing around with stubbing and mocking in the tests, but instead I am stubbing the get_config
function itself instead of the things it depends on, so the cache is also taken away.
|
||
from .exceptions import ShellCommandException | ||
from .log import logger | ||
|
||
PathLike = Union[str, os.PathLike] | ||
EDITORS = ("sensible-editor", "nvim", "vim", "nano", "subl", "code", "notepad", "vi") |
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 have a comment here for the Sphinx module reference?
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 will add that, thank you!
Thank you very much for the review @FlorianWilhelm, I conducted a series of tests and tried to have 100% coverage on this extension... Hopefully it should work fine now. Just in case I added some docs saying it is experimental and asking for feedback from devs. Hopefully this fulfils the interactive needs of PyScaffold. |
Yes! 🥳 This was the last open todo for version 4.0, right @abravalheri? As your PR resolves issue #191. |
Precisely! Now I guess it is just a matter of checking if the docs are in good shape, and we could have a release 😄 I am happy in terms of features for v4. I think everything else can wait until v5 (even removing |
So far I found the docs in quite good shape. Regarding |
I will release a final beta before hand and wait a couple of weeks yet, just to be on the conservative side 😝 ... Meanwhile I can have a look on the docs and also release updated versions of the extensions. |
#333 got accidentally closed, this is a continuation of that PR.
TODO list:
argparse
functions (parser._actions
, parser._actions) in a centralised location so they can be easily changed if necessary--edit
to-i/--interactive