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

"SyntaxError: invalid syntax" when installing master via pip #496

Closed
hheimbuerger opened this issue Sep 24, 2014 · 15 comments
Closed

"SyntaxError: invalid syntax" when installing master via pip #496

hheimbuerger opened this issue Sep 24, 2014 · 15 comments

Comments

@hheimbuerger
Copy link

When installing the latest master (89024b4) via pip (pip install -U git+https://github.com/getsentry/raven-python) on Python 2.7, I'm getting a "SyntaxError: invalid syntax" for the following line: https://github.com/getsentry/raven-python/blob/master/raven/transport/aiohttp.py#L30

Looks reasonable, the asterisk really doesn't look like Python (2.x) syntax, or am I missing something?

@xordoquy
Copy link
Contributor

Actually it's not.
I'm curious about whether this is a side effect of raven loading tons of things on initial import or whether it's the installation that parses the files

@dcramer
Copy link
Member

dcramer commented Sep 24, 2014

I believe all transports get loaded on initial import. This is only on master so I'm going to call it safe and we can push ahead with a fix, but we'll need to sort out something before releasing a new version.

@gmixo
Copy link

gmixo commented Sep 29, 2014

https://readthedocs.org/builds/raven/1689292/
here "SyntaxError: invalid syntax" is called Environment Standard Error
so seems it's ok

@mattrobenolt
Copy link
Contributor

@hheimbuerger This should be fine. It's more or less just a warning when installing. The transport is lazily loaded so when running, this doesn't happen.

For example, gunicorn also errors the same way when installing for it's aiohttp worker.

$ pip install gunicorn
Downloading/unpacking gunicorn
  Downloading gunicorn-19.1.1-py2.py3-none-any.whl (104kB)
    100% |################################| 106kB 1.8MB/s
Installing collected packages: gunicorn
Compiling /Users/matt/.virtualenvs/pip/build/gunicorn/gunicorn/workers/_gaiohttp.py ...
  File "/Users/matt/.virtualenvs/pip/build/gunicorn/gunicorn/workers/_gaiohttp.py", line 64
    yield from self.wsgi.close()
             ^

Successfully installed gunicorn

Same idea. :) I agree it's confusing, but all tests pass and whatnot for python2, so I wouldn't be worried. We'll also be cutting a new release from master soon.

@mattrobenolt
Copy link
Contributor

Also for context, https://github.com/getsentry/raven-python/blob/master/raven/transport/__init__.py#L25-L26

The module isn't even imported in < python 3.3.

@mattrobenolt
Copy link
Contributor

Lastly, this is a similar Issue filed against gunicorn for what I just pointed out: benoitc/gunicorn#860

Turns out, it's a bug in pip confusingly showing the error. If you test against pip master, it doesn't complain.

@hheimbuerger
Copy link
Author

@mattrobenolt I know it works alright, I've actually lived with this for a while. But I have some less technical people running the code (and doing pip updates) and for them it's very confusing to see an error that looks so fatal.

It's kinda undermining my efforts to try to empower them to judge for themselves whether there was a problem with the upgrade they have to deal with (or contact me). ;)

I really think a stable package should not show this during installation. Is there nothing you can do? Can you link to the pip issue you were talking about?

@mattrobenolt
Copy link
Contributor

pypa/pip#1984

And I just submit another patch since this didn't cover installing from wheels very well: pypa/pip#2071

@lkiss80
Copy link

lkiss80 commented Jun 6, 2015

When compiling raven, I see the SyntaxError tagged above, but the exit code for "python -m compileall" is still 1. Shouldn't the exit code be 0 if this were truly not an issue? This only came up when I ran a deployment, and my tool pays attention to the exit codes.

@mattrobenolt
Copy link
Contributor

This isn't an issue, and exists in any library that tries to be python 2 and python 3 compatible in the same codebase. Similarly, this happens to gunicorn as well. The only fix we could do is to remove the python 3 specific syntax from our codebase, but I don't really think that's reasonable.

@xordoquy
Copy link
Contributor

xordoquy commented Jun 6, 2015

Upgrading your pip version might solve the issue.
I just tested a Raven install with Python 2.7 and pip 7.0.3, didn't saw a warning.

@mattrobenolt
Copy link
Contributor

@xordoquy The underlying problem is from python -m compileall, which people run across their projects outside of pip. pip happens to call this internally and just masks the output so it's not surfaced to the user. So anyone who runs python -m compileall explicitly would be seeing this, which is a bit awkward.

@mattrobenolt
Copy link
Contributor

And to clarify, compileall is naive to all of this. It just generates pyc files for every python file in the source tree, it doesn't actually import modules or anything, so it doesn't understand that certain files aren't even accessed based on conditional imports, etc.

@xordoquy
Copy link
Contributor

xordoquy commented Jun 6, 2015

Right, I assumed the compilall was part of the installation process.

@mattrobenolt
Copy link
Contributor

Yeah, it totally is. pip just masks those errors by literally using a regular expression to parse them out. :) It's kinda gross. But it's not an error by any means, just noise.

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

No branches or pull requests

6 participants