我试图使用Py2Exe从ReviewBoard的postreview.py构建Windows可执行文件,因此我的用户不需要安装Python即可发布审阅请求。

我遇到了一个问题,其中编译版本找不到任何注册的SCM客户端。我已经在代码的以下行中进行了跟踪:

for ep in pkg_resources.iter_entry_points(group='rbtools_scm_clients'):


这些入口点在EGG-INFO \ entry_points.txt中的RBTools鸡蛋中列出。在编译的exe中,iter_entry_points()函数返回一个空列表。

有没有办法通过Py2Exe使编译的exe知道这些入口点?还是我坚持自定义postreview(本质上是对入口点进行硬编码)以使其正常工作?

感谢您的提示!

最佳答案

如果有人遇到这个问题寻找答案,我可以通过对入口点进行硬编码来使其正常工作。我必须按以下方式更新load_scmclients()中的rbtools/clients/__init__.py函数:

import imp
def main_is_frozen():
    return (hasattr(sys, "frozen") or # new py2exe
            hasattr(sys, "importers") # old py2exe
            or imp.is_frozen("__main__")) # tools/freeze

from rbtools.clients.svn import SVNClient
from rbtools.clients.git import GitClient
from rbtools.clients.mercurial import MercurialClient
from rbtools.clients.cvs import CVSClient
from rbtools.clients.perforce import PerforceClient
from rbtools.clients.plastic import PlasticClient
from rbtools.clients.clearcase import ClearCaseClient
from rbtools.clients.bazaar import BazaarClient
def load_scmclients(options):
    global SCMCLIENTS

    SCMCLIENTS = {}

    if not main_is_frozen():
        for ep in pkg_resources.iter_entry_points(group='rbtools_scm_clients'):
            try:
                SCMCLIENTS[ep.name] = ep.load()(options=options)
            except Exception, e:
                logging.error('Could not load SCM Client "%s": %s' % (ep.name, e))
    else:
        temp_clients = {}
        temp_clients['svn'] = SVNClient
        temp_clients['git'] = GitClient
        temp_clients['mercurial'] = MercurialClient
        temp_clients['cvs'] = CVSClient
        temp_clients['perforce'] = PerforceClient
        temp_clients['plastic'] = PlasticClient
        temp_clients['clearcase'] = ClearCaseClient
        temp_clients['bazaar'] = BazaarClient
        for ep in temp_clients:
            try:
                SCMCLIENTS[ep] = temp_clients[ep](options=options)
            except Exception, e:
                logging.error('Could not load SCM Client "%s": %s' % (str(ep), e))

关于python - Py2Exe和pkg_resources.iter_entry_points(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19099097/

10-13 05:17