Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Can't print to stderr #23

Open
henridwyer opened this issue Jan 23, 2015 · 2 comments
Open

Can't print to stderr #23

henridwyer opened this issue Jan 23, 2015 · 2 comments
Labels

Comments

@henridwyer
Copy link

When printing to stderr, nothing shows up in the console.

    import sys
    print >> sys.stderr, "test"
    import sys
    sys.stderr.write("test2")

Both of these ways work if you replace stderr with stdout.

This raises an error for both stderr and stdout:

    from __future__ import print_function
    print('spam', file=sys.stderr)
Traceback (most recent call last):
  File "~/Library/Application Support/LightTable/plugins/Python/py-src/ltmain.py", line 267, in ipyEval
    compile(ensureUtf(code), ensureUtf(data[2]["name"]), 'exec')
  File "test.py", line 9
    print("test", file=sys.stdout)
                      ^
SyntaxError: invalid syntax
@hayd
Copy link

hayd commented Jul 1, 2015

It's unclear if the stderr part is

ipy = subprocess.Popen([cmd, 'kernel', '--pylab=inline'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=os.environ)
or
next_line = ipy.stdout.readline().decode('utf-8')
(those are my guesses).

The print_function bug is different... scoping of exec?

Edit: I can reproduce this locally:

In [2]: exec(compile("from __future__ import print_function", "hello.py", 'exec'))

In [3]: exec(compile("print('spam', file=sys.stderr)", "hello.py", 'exec'))
  File "hello.py", line 1
    print('spam', file=sys.stderr)
                      ^
SyntaxError: invalid syntax

@dosmoc
Copy link

dosmoc commented Sep 7, 2015

Had a look at the print_function bug. It appears to be related to the fact LightTable compiles each form in the file in sequence in py-src/ltmain.py:

  for form in toExec:
      code = form[1]
      loc = form[0]
      #conditional stuff for eval vs. exec
          code= compile(code, data[2]["name"], 'exec')

and the fact that the print_function is a monkey patch to syntax that exists only at runtime.

Attaching the from __future__ import print_function line to the code in py-src/ltmain.py allows something like print('spam', file=sys.stderr) to be evaluated successfully:

if "print" in code:
  code = "from __future__ import print_function\n" + code

code= compile(code, data[2]["name"], 'exec')

I'm not familiar with Python/LightTable internals, so can't propose an actual solution.

Edit: just realized that I've got an older version of the Python plugin installed, will need to check out the issue with the latest, but it looks like he basic problem remains the same.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants