-
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
Add local_imports
context manager (allow to disable tunnelled imports)
#57
base: master
Are you sure you want to change the base?
Conversation
Example: def remote_function(): with chopsticks.tunnel.local_imports(): import psycopg2 ...
@lordmauve Also, I just realize this after making the pull request but in some case, one might want to wrap a whole function with the context manager. In this case I should add an exception to this local_imports thing in order to always use tunneling for module chopsticks.* |
... and I could also add some information about this context manager + an example in |
This is a good idea. I'm not sure about the context manager though. We could add this as a setting in the chopsticks.IMPORT_LOCAL = ['psycopg2'] There's already some code for transferring these settings ( |
The settings in the I'll have a look tomorrow about the settings See, in my case I want to PS: are you ok with the |
@lordmauve I don't see an easy way to make the whitelist Not impossible but pretty ugly and overkill don't you think ? So if I summarize properly, the options are:
|
Maybe I'm misunderstanding the requirement, then. You want certain modules and everything they depend on to be imported "locally"? This runs the risk of importing different versions of libraries on different remote hosts, which on the whole I think might be best avoided. The advantage of the setting is that you can name specific packages to be imported from the local sys.path without potentially picking up anything else from the local path. |
That's it ! (in some cases at least) Most of the cases could be (and would better be) handled by the But in some case you might want to execute python code using a locally installed python stack in a remote machine, container, ... Let's replace my odoo example with django. Hence: with local_imports():
import django
import some_other_stack_modules
# ...continue your stuff and use your stack... I guess one could spawn another |
Hi @lordmauve , It seems that you don't like the idea of the context manager, could you confirm ? So if you want me to implement Thanks. |
Example:
@lordmauve I admit the name
local_imports
is not right. Technically, using it make the remote machine use local imports (relative to itself). But when the developer is reasoning about chopsticks code, one might argue that he wants to use the remote imports (relative to it's workstation), hence might findremote_imports
more relevant. This make me think we should use a completely different name.If you're not against this patch, may I ask you some guidance about a good name to use for this context manager, then I'll update my branch. Thanks!