-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: Improved __init__.py
for skeletons
and modules
#137
base: main
Are you sure you want to change the base?
Conversation
This PR changes the current __init__.py-scripts to allow for module- and skeleton restructuring using folders. - `skeletons/__init__.py` imports skeletons from any sub-folders now - `modules/__init__.py` imports modules from any sub-folder, but registers them as they where defined just in modules, so there's no prefixing like before. As the latter one "breaks" a current behavior, IMHO this was only requested for the viur-shop module and was solved differently there, as there is a `Shop()`-module which is imported.
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 basically don't care what the recursive behavior is. I have the importer in my projects so that the order structure simply acts as a grouping of the modules for a better overview, but does not cause any name changes.
In the end, everyone has their own expectations as to how they would like this to work in their project or how it fits there.
I would be interested to hear @KadirBalku 's opinion, as he implemented it that way back then in #112.
Otherwise, the behavior would be okay for me.
I just think the technical implementation is a step backwards. Why are you using this old fashion os
lib again, but still handling path objects? Please use the pathlib
consistently. I think you can save yourself these __find_py_files
completely if you simply use directory.rglob("*.py")
. You would only have to do the blacklist manually.
for name, obj in inspect.getmembers(__module, inspect.isclass): | ||
if issubclass(obj, __viur_Module) and obj.__module__ == __module.__name__: | ||
# Import the class into the current namespace | ||
print(name.lower(), obj) |
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.
Please don't use print and use the logging framework.
Even if it is not established, maybe also a custom logger
log = logging.getLogger("my-project").getChild(__name__).getChild("autoloader")
Using the root logger is actually mostly a bad idea, but that's another problem in ViUR and ViUR projects ...
This PR changes the current
__init__.py
-scripts to allow for module- and skeleton restructuring using folders.skeletons/__init__.py
imports skeletons from any sub-folders nowmodules/__init__.py
imports modules from any sub-folder, but registers them as they where defined just in modules, so there's no prefixing like before.As the latter one "breaks" a current behavior, IMHO this was only requested for the viur-shop module and was solved differently there, as there is a
Shop()
-module which is imported.