-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Fix load_session() and restrict loading a session in a different module #507
Conversation
@mmckerns, I'm progressing with this issue, but I can't find a way to allow a user to restore a common session into a module created with |
That's ok. It should be a pretty small corner case. Some options are: (1) don't allow it, (2) allow it but also restore the original module where (a) the original module is imported then removed, (b) the original module is imported with an alias... or (c) something else. I'd look at the |
What I ended doing is to create a separate function The problem with the options 2.a and 2.b that you suggested is that the CPython 3.7 import system seems to be somewhat broken. As I mentioned in this comment (#463 (comment)) and a couple ones before it, the sequence of commands The |
9fb7d23
to
bea5627
Compare
I've found at least one project that would benefit from this PR: https://github.com/SAME-Project/same-project/blob/main/sameproject/ops/execution.py (introduced a week ago by SAME-Project/same-project#176) |
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 address the review comments.
I did various changes in the commit "adjustments":
|
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 code really LGTM. However, before we merge... let's iterate once or twice more purely on the names of the functions I've identified.
I changed the
The settings API I'm aiming at is somewhat as this: >>> from dill import FilterRules, settings
>>> mod_settings = settings['module']
>>> mod_settings['imported_byref'] # item access
False
>>> mod_settings.imported_byref = True # attribute access
>>> mod_settings.__main__ = {'imported_byref': False} # a module specific session setting
>>> mod_settings.__main__.imported_byref # instead of mod_settings['__main__']['imported_byref']
False
>>> mod_settings['my.submodule'] = {'rules': FilterRules()} # create a 'submodule' entry under a 'my' entry
>>> mod_settings.my.submodule.rules.exclude.add('somevar') |
I see... so you want to (for example) have a settings "tree" as opposed to a flat settings dict. This might take a bit of design discussion. How about we tackle that in a separate PR? |
I'm refining the idea. Indeed, a settings "tree" as I was imagining may have an implementation too complex. I'm thinking now of having just the filter rules for However, I'm still thinking of a format for a config file, including the filter rules for specific modules. Maybe we should use [dill]
byref = true
protocol = 3
[dump_module]
exclude.types = [FunctionType, ModuleType, TypeType] # or [function, module, type]
[dump_module.__main__]
exclude.regexes = "_.*" |
Oops! My two last messages were intended to go to #475... |
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 documentation could use going over once more to clean it up a bit, but otherwise LGTM. If you feel like you don't want to make another pass at the documentation, I'll pull it and then tweak the docs a bit myself.
I'm sorry? Didn't understand a word. I'm happy by now. Merge it, please, so you can tweak it as you like, and I can merge it with the filter PR and finish that. I'm going to complement the code annotation and the private functions' documentation there if necessary. Or... Can't you add suggested changes directly here, in a way that I could just accept and include in a new commit? I think I saw a button in the desktop web interface, in the comment box. |
Resolves #498. Ongoing work, I'm adding a fix/feature per commit. The plan:
Operations allowed by
load_session()
:ModuleType()
) and restore to another runtime module with the same nameSave an importable module and restore to a runtime created module with the same name (allow unpickling multiple sessions, for comparing versions of objects for example).Operations disallowed by
load_session()
:Other changes:
main
parameter is now also optional for simply loading modules other than__main__
main
parameter accepts a runtime module, or a name forload_session()
to create it withModuleType(main)
main
module is other than__main__
, it is returned: