How do I get Plone to read my pythonrc?

plone, python, readline

Solution

The instance controller uses two command-line switches; `-i` for interactive mode, and `-c` to load the Zope configuration and set up the `app` variable. The `-c` switch is what disables the `PYTHONSTARTUP` environment variable.

You could modify the `plone.recipe.zope2instance` package to run the script anyway.

In `plone.recipe.zope2instance`, find the `plone/recipe/zope2instance/ctl.py` file, alter the `do_debug()` method to:

def do_debug(self, arg):
    interactive_startup = ("import os;"
        "os.path.exists(os.environ.get('PYTHONSTARTUP', '')) "
        "and execfile(os.environ['PYTHONSTARTUP']); del os;"
        'import Zope2; app=Zope2.app()')
    cmdline = self.get_startup_cmd(self.options.python,
                                   interactive_startup,
                                   pyflags = '-i', )

In fact, I like the idea of supporting `PYTHONSTARTUP` so much I committed that change to the recipe already, see rev 536f8fc1c4!

Problem

I am using the collective.python buildout. I have the following `.pythonrc` (configured with `export PYTHONSTARTUP=~/.pythonrc`): ``` import readline import rlcompleter readline.parse_and_bind('tab: complete') ``` When I run `Python` in the shell, tab completion works. When I run `Plone` in debug mode it does not. Unless, I paste the contents of my `.pythonrc` into the Plone debug Python prompt. What am I missing here? Note: Pasting the contents of my .pythonrc only works when I install Plone via `python bootstrap.py` (i.e. bootstrapping Plone buildout with `collective.python` Python). If I install Plone inside a `virtualenv`, nothing works. But at least in that scenario, the missing functionality makes sense to me (i.e. something is probably missing from the `virtualenv` that is required to make tab completion work.)

Original source