bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.44k stars 1.46k forks source link

Bottle doesn't work under a relocatable virtualenv #367

Closed pvicente closed 12 years ago

pvicente commented 12 years ago

On heroku platform virtualenvs are relocatable (--relocatable parameter) and it add an activation line at the top of bottle.py file and the import line from __future__ import with_statement dumps an exception like it:

Exception

  File "/private/tmp/venv/bin/bottle.py", line 19
    from __future__ import with_statement
SyntaxError: from __future__ imports must occur at the beginning of the file

Steps to reproduce this problem

1. virtualenv --distribute venv
2. source venv/bin/activate
3. pip install bottle==0.10.11
4. virtualenv --relocatable venv/
5. bottle.py 

Original File bottle.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Bottle is a fast and simple micro-framework for small web applications. It
offers request dispatching (Routes) with url parameter support, templates,
a built-in HTTP Server and adapters for many third party WSGI/HTTP-server and
template engines - all in a single file and with no dependencies other than the
Python Standard Library.

Homepage and documentation: http://bottlepy.org/

Copyright (c) 2011, Marcel Hellkamp.
License: MIT (see LICENSE.txt for details)
"""

from __future__ import with_statement

With virtualenv --relocatable

#!/usr/bin/env python2.7

import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); execfile(activate_this, dict(__file__=activate_this)); del os, activate_this

# -*- coding: utf-8 -*-
"""
Bottle is a fast and simple micro-framework for small web applications. It
offers request dispatching (Routes) with url parameter support, templates,
a built-in HTTP Server and adapters for many third party WSGI/HTTP-server and
template engines - all in a single file and with no dependencies other than the
Python Standard Library.

Homepage and documentation: http://bottlepy.org/

Copyright (c) 2011, Marcel Hellkamp.
License: MIT (see LICENSE.txt for details)
"""

from __future__ import with_statement

__author__ = 'Marcel Hellkamp'
__version__ = '0.10.11'
__license__ = 'MIT'
defnull commented 12 years ago

Um, how am I supposed to fix this? Is there a virtualenv issue for this?

pvicente commented 12 years ago

You are right

1.8 (2012-09-01)

Fix --relocatable when a script uses future imports. Thanks Branden Rolston.

It has been fixed recently.

http://pypi.python.org/pypi/virtualenv

I will open an issue on Heroku Platform they are using virtualenv 1.7.2