当前位置: 首页>>代码示例>>Python>>正文


Python ScriptMaker._get_launcher方法代码示例

本文整理汇总了Python中pip._vendor.distlib.scripts.ScriptMaker._get_launcher方法的典型用法代码示例。如果您正苦于以下问题:Python ScriptMaker._get_launcher方法的具体用法?Python ScriptMaker._get_launcher怎么用?Python ScriptMaker._get_launcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pip._vendor.distlib.scripts.ScriptMaker的用法示例。


在下文中一共展示了ScriptMaker._get_launcher方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wrapScriptExe

# 需要导入模块: from pip._vendor.distlib.scripts import ScriptMaker [as 别名]
# 或者: from pip._vendor.distlib.scripts.ScriptMaker import _get_launcher [as 别名]
def wrapScriptExe(script, shebang = u"#!python.exe"):
# ==============================================================================
    u"""Wraps a single script into a MS-Win ``.exe``.

    Only the ``script`` file contents is wraped into the ``.exe``, not the whole
    python environment!

    This is usefull to create ``.exe`` console scripts for python entry points,
    which can be called directly (``myscript.exe`` instead ``python
    myscript.py``).

    .. caution::

       * This is in an experimental state!
       * This makes use of undocumented pip APIs (ATM pip has no offical API)
       * Use it with care!
       * Shebang is always ``#!python.exe``

    """

    from pip._vendor.distlib.scripts import ScriptMaker
    from pip._vendor.distlib.compat import ZipFile

    origin   = FSPath(script)
    exec_out = origin.suffix('.exe')
    shebang  = six.b(shebang + u"\r\n")
    linesep  = os.linesep.encode('utf-8')

    script   = origin.readFile()
    script   = six.b(script)

    maker    = ScriptMaker(source_dir    = origin.DIRNAME
                           , target_dir  = origin.DIRNAME)

    if origin.SUFFIX == '.py':
        launcher = maker._get_launcher('t') # pylint: disable=protected-access
    else:
        launcher = maker._get_launcher('w') # pylint: disable=protected-access

    stream = io.BytesIO()
    with ZipFile(stream, 'w') as _f:
        if six.PY2:
            _f.writestr('__main__.py', str(script))
        else:
            _f.writestr('__main__.py', script)

    zip_data = stream.getvalue()
    if six.PY2:
        script = launcher + str(shebang + linesep) + zip_data
    else:
        script = launcher + shebang + linesep + zip_data

    with open(exec_out, "wb") as out:
        out.write(script)

    #print("created %s" % exec_out)
    return exec_out
开发者ID:return42,项目名称:fspath,代码行数:59,代码来源:win.py


注:本文中的pip._vendor.distlib.scripts.ScriptMaker._get_launcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。