gpt4 book ai didi

python - Py2Exe 和 pkg_resources.iter_entry_points()

转载 作者:太空宇宙 更新时间:2023-11-04 06:10:21 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com