python - Py2Exe 和 pkg_resources.iter_entry_points()

标签 python py2exe review-board

我正在尝试使用 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 egg 中。在编译后的 exe 中,iter_entry_points() 函数返回一个空列表。

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

感谢任何提示!

最佳答案

如果其他人在寻找答案时遇到这个问题,我通过对入口点进行硬编码来让它工作。我不得不更新 rbtools/clients/__init__.py 中的 load_scmclients() 函数,如下所示:

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/

相关文章:

python - 创建Python .exe文件: py2exe invalid image error

svn - 在审查委员会中自动提交已批准的差异

python - Python中多处理或多线程的动态刷新打印

python - py2exe 不包括来自 "includes"的模块

python - 使用通用键值对对字典列表中的值求和

python - PhantomJS 可以与 py2exe 一起使用吗?

apache - 审查委员会差异未上传

git - 审查板 's post-review can' 无法与 git 一起使用,为什么?

python - 使用 Cygwin 编译并从 Python 调用的 C 程序挂起

python - 将 Python 转换为 Haskell/Lambda 演算