【问题标题】:Python setuptools entrypoints and subapplications as child processesPython setuptools 入口点和子应用程序作为子进程
【发布时间】:2013-08-08 19:42:22
【问题描述】:

我在 Windows 上工作并开发一个将分发给最终用户的应用程序。

我有一个 setupttools 发行版,其中包含大量 python 包。此发行版声明了一些指向我代码中各种函数的 console_scripts 入口点。

其中一个入口点注定要成为更新程序应用程序。我目前正在使用子进程将其作为子进程启动并指定 python 脚本的完整路径。

我想做的是使用生成的 setuptools 入口点存根可执行文件作为要启动的子进程。

我可以通过以下方式获取子应用程序的入口点:

import pkg_resources
updatefunc = pkg_resources.load_entry_point('iti_reporter', 'console_scripts', 'my_update_ui')

这给了我它的python函数。有没有办法从这个函数到生成的 setuptools 脚本包装器,它驻留在我的 venv 中?

感谢您的帮助。

【问题讨论】:

    标签: python subprocess setuptools entry-point pkg-resources


    【解决方案1】:

    通过执行脚本无论如何都会做的事情来解决这个问题:

    def _get_entry_script(dist, entrytype, entryname):
        import pkg_resources
        mainfunc = pkg_resources.load_entry_point(dist, entrytype, entryname)
        entry_load_script = """import sys; from pkg_resources import load_entry_point;
        sys.exit(
            load_entry_point('%s', '%s', '%s')()
        )"""
        script = entry_load_script%(dist, entrytype, entryname)
        script = ''.join(x.strip() for x in script.split('\n') if x.strip())
        return script
    
    def _get_updater_script_arg_dev():
        return _get_entry_script('mydist', 'console_scripts', 'mypkg_update_ui')
    
    def launch_updater():
        cmd = (os.path.abspath(sys.executable), '-c', _get_updater_script_arg_dev(), '--arg1', '--arg2')
        return subprocess.Popen(cmd)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多