The embedding machinery ignores user_ns #1136

Closed
g2p opened this Issue Dec 9, 2011 · 6 comments

Comments

Projects
None yet
3 participants
@g2p
Contributor

g2p commented Dec 9, 2011

Quick demonstration:

from IPython import embed

user_ns = dict(cookie='monster')
embed(user_ns=user_ns, banner1='Please type: cookie')

Bisecting shows the last good revision was 5397fc8, the following revisions don't have working embedding until 9a2ec9f, which has embedding but lost user_ns functionality.
I don't know how to write automated tests for embedding (can stdin be hijacked?).
Paging @takluyver.

@ghost ghost assigned takluyver Dec 10, 2011

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Dec 10, 2011

Member

I think I see the issue. user_ns when we create the shell is overridden by local_ns when we activate it. I'll think about the best way to resolve it.

Member

takluyver commented Dec 10, 2011

I think I see the issue. user_ns when we create the shell is overridden by local_ns when we activate it. I'll think about the best way to resolve it.

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Dec 10, 2011

Member

This looks pretty serious, I really would hate for 0.12 to come out with broken embedding, seeing as it will be the ubuntu LTS ipython...

Member

fperez commented Dec 10, 2011

This looks pretty serious, I really would hate for 0.12 to come out with broken embedding, seeing as it will be the ubuntu LTS ipython...

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Dec 10, 2011

Member

Right, there are four possibilities for each of user_ns and user_module when embedding:

  1. Not specified at instantiation or activation - use the auto-detected namespace/module at activation
  2. Specified at instantiation only - use that, and do not auto-detect (this is what we're getting wrong)
  3. Specified at activation only - use that, don't auto-detect
  4. Specified at instantiation and activation - what's specified at activation overrides what's specified at instantiation.

I've got an idea how to resolve this. I'll put together a PR, hopefully this evening.

Member

takluyver commented Dec 10, 2011

Right, there are four possibilities for each of user_ns and user_module when embedding:

  1. Not specified at instantiation or activation - use the auto-detected namespace/module at activation
  2. Specified at instantiation only - use that, and do not auto-detect (this is what we're getting wrong)
  3. Specified at activation only - use that, don't auto-detect
  4. Specified at instantiation and activation - what's specified at activation overrides what's specified at instantiation.

I've got an idea how to resolve this. I'll put together a PR, hopefully this evening.

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Dec 10, 2011

Member

Funny coincidence: #136 and this (#1136) are both on scoping problems with the embedding code :)

Member

fperez commented Dec 10, 2011

Funny coincidence: #136 and this (#1136) are both on scoping problems with the embedding code :)

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Dec 10, 2011

Member

Have a look at PR #1140.

Member

takluyver commented Dec 10, 2011

Have a look at PR #1140.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Dec 13, 2011

Member

Merged PR #1140, which resolves this.

Member

takluyver commented Dec 13, 2011

Merged PR #1140, which resolves this.

@takluyver takluyver closed this Dec 13, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment