Skip to content
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

Dollar formatter for ! shell calls #1020

Merged
merged 3 commits into from Nov 20, 2011
Merged

Conversation

takluyver
Copy link
Member

This uses a subclass of FullEvalFormatter for filling in variables in shell commands like !echo $spam, instead of Itpl. It seems to fix #822.

I've retained the {foo} style standard formatting for complex expressions, so it can be picked up by the more powerful built in parser. $foo works for names and attribute access.

FullEvalFormatter now always outputs unicode, even if you gave it a bytes string. This avoids problems when you mix 8-bit non-ascii strings and unicode (which e.g. StringIO.StringIO suffers from).

@fperez
Copy link
Member

fperez commented Nov 20, 2011

Awesome, great cleanup. Thanks! Merging now.

Just a question for future reference: why do those doctests need to be skipped on py3? Eventually we'll be running fully on py3, so I want to make sure we're not setting ourselves up for a restricted test suite there. Anything we can start doing to make the doctests more py3-compatible?

@takluyver
Copy link
Member Author

Good question. The u'abc' syntax in the output from the doctests is incorrect on Python 3. Generally, I've got a workaround where you write {u}'abc', and then apply a @py3compat.u_format decorator to transform it. But these doctests involve a lot of {foo} style formatting, which would all have to be changed to {{foo}} if we wanted to use that.

The same code is covered by proper functional tests, so I decided to keep it simple and skip the doctests in Python 3.

fperez added a commit that referenced this pull request Nov 20, 2011
Dollar formatter for ! shell calls.

This uses a subclass of `FullEvalFormatter` for filling in variables in shell commands like `!echo $spam`, instead of Itpl.

I've retained the `{foo}` style standard formatting for complex expressions, so it can be picked up by the more powerful built in parser. `$foo` works for names and attribute access.

FullEvalFormatter now always outputs unicode, even if you gave it a bytes string. This avoids problems when you mix 8-bit non-ascii strings and unicode (which e.g. `StringIO.StringIO` suffers from).

Closes #822 (test was added in 31ab23f).
@fperez fperez merged commit 09c9952 into ipython:master Nov 20, 2011
@fperez
Copy link
Member

fperez commented Nov 20, 2011

Sounds good. Once we're more fully in py3 mode we can revisit this and come up with some best practices moving forward, for now it looks like we're OK.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Dollar formatter for ! shell calls.

This uses a subclass of `FullEvalFormatter` for filling in variables in shell commands like `!echo $spam`, instead of Itpl.

I've retained the `{foo}` style standard formatting for complex expressions, so it can be picked up by the more powerful built in parser. `$foo` works for names and attribute access.

FullEvalFormatter now always outputs unicode, even if you gave it a bytes string. This avoids problems when you mix 8-bit non-ascii strings and unicode (which e.g. `StringIO.StringIO` suffers from).

Closes ipython#822 (test was added in 31ab23f).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unicode bug in Itpl when expanding shell variables in syscalls with !
2 participants