Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

pip install loads terrain file, causing import errors #220

SystemParadox opened this Issue Jan 12, 2012 · 4 comments


None yet
2 participants

SystemParadox commented Jan 12, 2012

Hi. I'm using lettuce with django in a virtualenv setup. It's all working well- one incredibly useful package- thanks.

Unfortunately, now that I have a terrain file, 'pip install lettuce' fails. If I remove the terrain file, install lettuce and then replace it everything works fine.

The question is, why does lettuce load the terrain file during installation? This is always going to have import errors because at this stage not everything is installed or in the path yet. Here is the console output:

$ pip install lettuce
Downloading/unpacking lettuce (from -r requirements.all (line 18))
  Running setup.py egg_info for package lettuce
    Lettuce has tried to load the conventional environment module "terrain"
    but it has errors, check its contents and try to run lettuce again.

    Original traceback below:

    Traceback (most recent call last):
      File "lettuce/__init__.py", line 53, in <module>
        terrain = fs.FileSystem._import("terrain")
      File "lettuce/fs.py", line 74, in _import
        module = imp.load_module(name, fp, pathname, description)
      File "/home/simon/django/dms/terrain.py", line 2, in <module>
        from django.test.utils import setup_test_environment, teardown_test_environment
    ImportError: No module named django.test.utils
    Complete output from command python setup.py egg_info:
    Lettuce has tried to load the conventional environment module "terrain"

but it has errors, check its contents and try to run lettuce again.



SystemParadox commented Jan 12, 2012

It appears that setup.py has 'from lettuce import version', which causes lettuce.init.py to be run, and this file has the terrain loader in it. At the point pip runs 'setup.py egg_info' no packages have been installed yet.

According to the example in the documentation at http://lettuce.it/reference/terrain.html I should be able to put the terrain.py inside the features directory. Unfortunately this does not work, even when using the harvest command.

I cannot currently see any way to get lettuce to load the terrain from anywhere other than the python path/current directory.

The only workaround I can think of at the moment is to wrap the whole terrain file in a try-catch, which is just awful.


SystemParadox commented Jan 12, 2012

The documentation for Runner.init says that lettuce.Runner is responsible for loading the terrain file, but this does not appear to be the case.


SystemParadox commented Mar 23, 2012

According to http://lettuce.it/recipes/django-lxml.html#lettuce-terrain-also-available-in-django-projects, when using Django the terrain has to be located at the project root, unlike normal lettuce which can use features/terrain.py.


SystemParadox commented Apr 17, 2012

Update: Even wrapping the entire terrain file in a try-catch for ImportError is not sufficient. You have to catch any Exception.

This is because any modules imported by the terrain file are likely to throw arbitrary exceptions, if importing them also results in code being run the relies on certain packages being installed (which may not be at this point).

In my case, importing django.test.utils.setup_test_environment initiates a check for database connections and then tries to log to sentry, which fails because pip doesn't install sentry/raven until after lettuce. Whilst the failure was due to an ImportError, the traversal up the sentry stack results in it being wrapped in a ValueError.

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