本文整理汇总了Python中pip._vendor.distlib.scripts.ScriptMaker类的典型用法代码示例。如果您正苦于以下问题:Python ScriptMaker类的具体用法?Python ScriptMaker怎么用?Python ScriptMaker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScriptMaker类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapScriptExe
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
示例2: test_make_exe
def test_make_exe(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_make_exe")
from pip._vendor.distlib.scripts import ScriptMaker
maker = ScriptMaker(os.path.join(temp, "..", "..", "..", "src"), temp)
maker.make('run_update_all = pymyinstall:update_all')
if sys.platform.startswith("win"):
exe = os.path.join(temp, "run_update_all.exe")
assert os.path.exists(exe)
示例3: move_wheel_files
#.........这里部分代码省略.........
assert info_dir, "%s .dist-info directory not found" % req
# Get the defined entry points
ep_file = os.path.join(info_dir[0], 'entry_points.txt')
console, gui = get_entrypoints(ep_file)
def is_entrypoint_wrapper(name):
# EP, EP.exe and EP-script.py are scripts generated for
# entry point EP by setuptools
if name.lower().endswith('.exe'):
matchname = name[:-4]
elif name.lower().endswith('-script.py'):
matchname = name[:-10]
elif name.lower().endswith(".pya"):
matchname = name[:-4]
else:
matchname = name
# Ignore setuptools-generated scripts
return (matchname in console or matchname in gui)
for datadir in data_dirs:
fixer = None
filter = None
for subdir in os.listdir(os.path.join(wheeldir, datadir)):
fixer = None
if subdir == 'scripts':
fixer = fix_script
filter = is_entrypoint_wrapper
source = os.path.join(wheeldir, datadir, subdir)
dest = scheme[subdir]
clobber(source, dest, False, fixer=fixer, filter=filter)
maker = ScriptMaker(None, scheme['scripts'])
# Ensure old scripts are overwritten.
# See https://github.com/pypa/pip/issues/1800
maker.clobber = True
# Ensure we don't generate any variants for scripts because this is almost
# never what somebody wants.
# See https://bitbucket.org/pypa/distlib/issue/35/
maker.variants = set(('', ))
# This is required because otherwise distlib creates scripts that are not
# executable.
# See https://bitbucket.org/pypa/distlib/issue/32/
maker.set_mode = True
# Simplify the script and fix the fact that the default script swallows
# every single stack trace.
# See https://bitbucket.org/pypa/distlib/issue/34/
# See https://bitbucket.org/pypa/distlib/issue/33/
def _get_script_text(entry):
return maker.script_template % {
"module": entry.prefix,
"import_name": entry.suffix.split(".")[0],
"func": entry.suffix,
}
maker._get_script_text = _get_script_text
maker.script_template = """# -*- coding: utf-8 -*-
import re
import sys
from %(module)s import %(import_name)s
示例4: move_wheel_files
#.........这里部分代码省略.........
assert info_dir, "%s .dist-info directory not found" % req
# Get the defined entry points
ep_file = os.path.join(info_dir[0], 'entry_points.txt')
console, gui = get_entrypoints(ep_file)
def is_entrypoint_wrapper(name):
# EP, EP.exe and EP-script.py are scripts generated for
# entry point EP by setuptools
if name.lower().endswith('.exe'):
matchname = name[:-4]
elif name.lower().endswith('-script.py'):
matchname = name[:-10]
elif name.lower().endswith(".pya"):
matchname = name[:-4]
else:
matchname = name
# Ignore setuptools-generated scripts
return (matchname in console or matchname in gui)
for datadir in data_dirs:
fixer = None
filter = None
for subdir in os.listdir(os.path.join(wheeldir, datadir)):
fixer = None
if subdir == 'scripts':
fixer = fix_script
filter = is_entrypoint_wrapper
source = os.path.join(wheeldir, datadir, subdir)
dest = scheme[subdir]
clobber(source, dest, False, fixer=fixer, filter=filter)
maker = ScriptMaker(None, scheme['scripts'])
# Ensure old scripts are overwritten.
# See https://github.com/pypa/pip/issues/1800
maker.clobber = True
# Ensure we don't generate any variants for scripts because this is almost
# never what somebody wants.
# See https://bitbucket.org/pypa/distlib/issue/35/
maker.variants = {''}
# This is required because otherwise distlib creates scripts that are not
# executable.
# See https://bitbucket.org/pypa/distlib/issue/32/
maker.set_mode = True
# Simplify the script and fix the fact that the default script swallows
# every single stack trace.
# See https://bitbucket.org/pypa/distlib/issue/34/
# See https://bitbucket.org/pypa/distlib/issue/33/
def _get_script_text(entry):
if entry.suffix is None:
raise InstallationError(
"Invalid script entry point: %s for req: %s - A callable "
"suffix is required. Cf https://packaging.python.org/en/"
"latest/distributing.html#console-scripts for more "
"information." % (entry, req)
)
return maker.script_template % {
"module": entry.prefix,
"import_name": entry.suffix.split(".")[0],
"func": entry.suffix,
}
示例5: return
# Ignore setuptools-generated scripts
return (matchname in console or matchname in gui)
for datadir in data_dirs:
fixer = None
filter = None
for subdir in os.listdir(os.path.join(wheeldir, datadir)):
fixer = None
if subdir == 'scripts':
fixer = fix_script
filter = is_entrypoint_wrapper
source = os.path.join(wheeldir, datadir, subdir)
dest = scheme[subdir]
clobber(source, dest, False, fixer=fixer, filter=filter)
maker = ScriptMaker(None, scheme['scripts'])
<<<<<<< HEAD
=======
# Ensure old scripts are overwritten.
# See https://github.com/pypa/pip/issues/1800
maker.clobber = True
>>>>>>> 54eef0be98b1b67c8507db91f4cfa90b64991027
# Ensure we don't generate any variants for scripts because this is almost
# never what somebody wants.
# See https://bitbucket.org/pypa/distlib/issue/35/
maker.variants = set(('', ))
# This is required because otherwise distlib creates scripts that are not
# executable.