簡體   English   中英

如何讓Plone讀取我的pythonrc?

[英]How do I get Plone to read my pythonrc?

我正在使用collective.python buildout。

我有以下.pythonrc (使用export PYTHONSTARTUP=~/.pythonrc ):

import readline
import rlcompleter
readline.parse_and_bind('tab: complete')

當我在shell中運行Python時,選項卡完成工作。 當我在調試模式下運行Plone ,它沒有。 除非,我將.pythonrc的內容粘貼到Plone調試Python提示符中。 我在這里錯過了什么?

注意 :粘貼我的.pythonrc的內容只有在我通過python bootstrap.py安裝Plone時(即使用collective.python Python引導Plone buildout)。 如果我在一個virtualenv安裝Plone,沒有任何作用。 但至少在那種情況下,缺少的功能對我來說是有意義的(即,可能缺少使用制表符完成工作所需的virtualenv 。)

實例控制器使用兩個命令行開關; -i用於交互模式, -c用於加載Zope配置並設置app變量。 -c開關禁用PYTHONSTARTUP環境變量。

可以修改plone.recipe.zope2instance包來運行腳本。

plone.recipe.zope2instance ,找到plone/recipe/zope2instance/ctl.py文件,將do_debug()方法更改為:

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', )

事實上,我非常喜歡支持PYTHONSTARTUP的想法,我已經對配方進行了更改,請參閱rev 536f8fc1c4

我做import user 這讀取~/.pythonrc.py 請注意.py擴展名。 我已將該文件設置為PYTHONSTARTUP

我會粘貼該文件以獲得良好的衡量標准。 幾年前我把它拼湊在一起。 不確定它是否仍然是最好的,因為我看到關於2006和python2.3的評論。 它可以做到這一點。

$ cat ~/.pythonrc.py 
# See http://blog.partecs.com/2006/02/27/source-inspector/
#import pydoc
import inspect
import rlcompleter, readline

readline.parse_and_bind('tab: complete')

# def source(obj):
#     """source of the obj."""
#     try:
#         pydoc.pipepager(inspect.getsource(obj), 'less')
#     except IOError:
#         pass

# From /usr/local/lib/python2.3/user.py
import os
home = os.curdir                        # Default
if 'HOME' in os.environ:
    home = os.environ['HOME']
elif os.name == 'posix':
    home = os.path.expanduser("~/")
# Make sure home always ends with a directory separator:
home = os.path.realpath(home) + os.sep

# From http://wiki.python.org/moin/PdbRcIdea
# Command line history:
histfile = home + '.pyhist'
try:
    readline.read_history_file(histfile)
except IOError:
    pass
import atexit
atexit.register(readline.write_history_file, histfile)
readline.set_history_length(200)

# Cleanup namespace
# del atexit
# del home
# del histfile
# del os
# del readline
# del rlcompleter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM