You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
Love this repo. Am trying to work with it, but am seeing behavior in importing files that I cannot explain.
The simplest way to explain it is this: Consider a minimal set of 3 modules, say main, foo, and bar
main:
imports ihook.py
sets the import hook
imports foo
imports bar
foo:
imports bar
Now if the files are all unencrypted, what I see happening (with a print statement in the Finder function), is that the system tries to find foo, then since foo imports bar, it imports bar from foo. The behavior of this is different when the file is encrypted vs. when it is not.
If the files foo and bar are not encrypted, the Finder shows the calls to be:
Find (foo)
Find (bar)
if the files foo and bar are encrypted, the Finder shows the calls to be
Find (foo)
Find(foo.bar)
This lands up loading bar as foo.bar inside foo, which is a different instance of the module than the one that the main program loads when it imports bar.
What am I missing here. Why is the behavior different between loading the modules encrypted or unencrypted?
The text was updated successfully, but these errors were encountered:
After a bunch of looking at various examples and documentation, I have a partial answer.
In the code above I noticed that I was not setting module.__package__. Somewhere in the import process, that resulted in an entry of foo.__package__ = 'foo' being set in the module definition. This resulted in foo being considered a package and any imports it made being considered imports relative to the package directory.
When running against imports where I was not doing the module setup, I saw that the module.__package__ was set to None by the system. But setting module.__package__ = None in the code above did not work. Something reset it to foo.
The solution that worked was to set module.__package__ = '' (the null string). So the working piece of the code for adding the module is:
Love this repo. Am trying to work with it, but am seeing behavior in importing files that I cannot explain.
The simplest way to explain it is this: Consider a minimal set of 3 modules, say main, foo, and bar
main:
imports ihook.py
sets the import hook
imports foo
imports bar
foo:
imports bar
Now if the files are all unencrypted, what I see happening (with a print statement in the Finder function), is that the system tries to find foo, then since foo imports bar, it imports bar from foo. The behavior of this is different when the file is encrypted vs. when it is not.
If the files foo and bar are not encrypted, the Finder shows the calls to be:
Find (foo)
Find (bar)
if the files foo and bar are encrypted, the Finder shows the calls to be
Find (foo)
Find(foo.bar)
This lands up loading bar as foo.bar inside foo, which is a different instance of the module than the one that the main program loads when it imports bar.
What am I missing here. Why is the behavior different between loading the modules encrypted or unencrypted?
The text was updated successfully, but these errors were encountered: