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


Python easy_install.get_script_header函数代码示例

本文整理汇总了Python中setuptools.command.easy_install.get_script_header函数的典型用法代码示例。如果您正苦于以下问题:Python get_script_header函数的具体用法?Python get_script_header怎么用?Python get_script_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_get_script_header_jython_workaround

    def test_get_script_header_jython_workaround(self):
        platform = sys.platform
        sys.platform = 'java1.5.0_13'
        stdout = sys.stdout
        try:
            # A mock sys.executable that uses a shebang line (this file)
            exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py')
            self.assertEqual(
                get_script_header('#!/usr/local/bin/python', executable=exe),
                '#!/usr/bin/env %s\n' % exe)

            # Ensure we generate what is basically a broken shebang line
            # when there's options, with a warning emitted
            sys.stdout = StringIO.StringIO()
            self.assertEqual(get_script_header('#!/usr/bin/python -x',
                                               executable=exe),
                             '#!%s  -x\n' % exe)
            self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
            sys.stdout = StringIO.StringIO()
            self.assertEqual(get_script_header('#!/usr/bin/python',
                                               executable=self.non_ascii_exe),
                             '#!%s -x\n' % self.non_ascii_exe)
            self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
        finally:
            sys.platform = platform
            sys.stdout = stdout
开发者ID:nsimplex,项目名称:ds_mod_tools,代码行数:26,代码来源:test_resources.py

示例2: test_get_script_header_jython_workaround

    def test_get_script_header_jython_workaround(self, tmpdir):
        # Create a mock sys.executable that uses a shebang line
        header = DALS("""
            #!/usr/bin/python
            # -*- coding: utf-8 -*-
            """)
        exe = tmpdir / 'exe.py'
        with exe.open('w') as f:
            f.write(header)
        exe = str(exe)

        header = get_script_header('#!/usr/local/bin/python', executable=exe)
        assert header == '#!/usr/bin/env %s\n' % exe

        expect_out = 'stdout' if sys.version_info < (2,7) else 'stderr'

        with contexts.quiet() as (stdout, stderr):
            # When options are included, generate a broken shebang line
            # with a warning emitted
            candidate = get_script_header('#!/usr/bin/python -x',
                executable=exe)
            assert candidate == '#!%s  -x\n' % exe
            output = locals()[expect_out]
            assert 'Unable to adapt shebang line' in output.getvalue()

        with contexts.quiet() as (stdout, stderr):
            candidate = get_script_header('#!/usr/bin/python',
                executable=self.non_ascii_exe)
            assert candidate == '#!%s -x\n' % self.non_ascii_exe
            output = locals()[expect_out]
            assert 'Unable to adapt shebang line' in output.getvalue()
开发者ID:amarin,项目名称:rssler,代码行数:31,代码来源:test_easy_install.py

示例3: test_get_script_header_jython_workaround

    def test_get_script_header_jython_workaround(self):
        # This test doesn't work with Python 3 in some locales
        if (sys.version_info >= (3,) and os.environ.get("LC_CTYPE")
            in (None, "C", "POSIX")):
            return
        platform = sys.platform
        sys.platform = 'java1.5.0_13'
        stdout = sys.stdout
        try:
            # A mock sys.executable that uses a shebang line (this file)
            exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py')
            self.assertEqual(
                get_script_header('#!/usr/local/bin/python', executable=exe),
                '#!/usr/bin/env %s\n' % exe)

            # Ensure we generate what is basically a broken shebang line
            # when there's options, with a warning emitted
            sys.stdout = sys.stderr = StringIO.StringIO()
            self.assertEqual(get_script_header('#!/usr/bin/python -x',
                                               executable=exe),
                             '#!%s  -x\n' % exe)
            self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
            sys.stdout = sys.stderr = StringIO.StringIO()
            self.assertEqual(get_script_header('#!/usr/bin/python',
                                               executable=self.non_ascii_exe),
                             '#!%s -x\n' % self.non_ascii_exe)
            self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
        finally:
            sys.platform = platform
            sys.stdout = stdout
开发者ID:007lva,项目名称:mmddpp,代码行数:30,代码来源:test_resources.py

示例4: test_get_script_header

 def test_get_script_header(self):
     if not sys.platform.startswith('java') or not is_sh(sys.executable):
         # This test is for non-Jython platforms
         self.assertEqual(get_script_header('#!/usr/local/bin/python'),
                          '#!%s\n' % os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python -x'),
                          '#!%s  -x\n' % os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python',
                                            executable=self.non_ascii_exe),
                          '#!%s -x\n' % self.non_ascii_exe)
开发者ID:007lva,项目名称:mmddpp,代码行数:10,代码来源:test_resources.py

示例5: test_get_script_header

 def test_get_script_header(self):
     expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
     assert get_script_header('#!/usr/local/bin/python') == expected
     expected = '#!%s  -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
     assert get_script_header('#!/usr/bin/python -x') == expected
     candidate = get_script_header('#!/usr/bin/python',
         executable=self.non_ascii_exe)
     assert candidate == '#!%s -x\n' % self.non_ascii_exe
     candidate = get_script_header('#!/usr/bin/python',
         executable=self.exe_with_spaces)
     assert candidate == '#!"%s"\n' % self.exe_with_spaces
开发者ID:amarin,项目名称:rssler,代码行数:11,代码来源:test_easy_install.py

示例6: test_get_script_header

 def test_get_script_header(self):
     if not sys.platform.startswith('java') or not is_sh(sys.executable):
         # This test is for non-Jython platforms
         expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
         assert get_script_header('#!/usr/local/bin/python') == expected
         expected = '#!%s  -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
         assert get_script_header('#!/usr/bin/python -x') == expected
         candidate = get_script_header('#!/usr/bin/python',
             executable=self.non_ascii_exe)
         assert candidate == '#!%s -x\n' % self.non_ascii_exe
         candidate = get_script_header('#!/usr/bin/python',
             executable=self.exe_with_spaces)
         assert candidate == '#!"%s"\n' % self.exe_with_spaces
开发者ID:4115019,项目名称:ArrangeCourse,代码行数:13,代码来源:test_resources.py

示例7: override_get_script_args

def override_get_script_args(
        dist, executable=os.path.normpath(sys.executable), is_wininst=False):
    """Override entrypoints console_script."""
    header = easy_install.get_script_header("", executable, is_wininst)
    for group, template in ENTRY_POINTS_MAP.items():
        for name, ep in dist.get_entry_map(group).items():
            yield (name, generate_script(group, ep, header, template))
开发者ID:Row,项目名称:SickRage,代码行数:7,代码来源:packaging.py

示例8: _make_wsgi_scripts_only

 def _make_wsgi_scripts_only(self, dist, executable, is_wininst):
     header = easy_install.get_script_header("", executable, is_wininst)
     wsgi_script_template = ENTRY_POINTS_MAP['wsgi_scripts']
     for name, ep in dist.get_entry_map('wsgi_scripts').items():
         content = generate_script(
             'wsgi_scripts', ep, header, wsgi_script_template)
         self.write_script(name, content)
开发者ID:Row,项目名称:SickRage,代码行数:7,代码来源:packaging.py

示例9: _get_script_args

def _get_script_args(dist, executable, is_wininst):
    """Override entrypoints console_script."""
    header = easy_install.get_script_header("", executable, is_wininst)
    for group in 'console_scripts', 'gui_scripts':
        for name, ep in dist.get_entry_map(group).items():
            script_text = _script_text % dict(
                group=group,
                module_name=ep.module_name,
                func=ep.attrs[0])
            yield (name, header+script_text)
开发者ID:troytoman,项目名称:pbr,代码行数:10,代码来源:packaging.py

示例10: override_get_script_args

def override_get_script_args(dist, executable=os.path.normpath(sys.executable), is_wininst=False):
    """Override entrypoints console_script."""
    header = easy_install.get_script_header("", executable, is_wininst)
    for group, template in ENTRY_POINTS_MAP.items():
        for name, ep in dist.get_entry_map(group).items():
            if not ep.attrs or len(ep.attrs) > 2:
                raise ValueError("Script targets must be of the form " "'func' or 'Class.class_method'.")
            script_text = template % dict(
                group=group, module_name=ep.module_name, import_target=ep.attrs[0], invoke_target=".".join(ep.attrs)
            )
            yield (name, header + script_text)
开发者ID:neogoku,项目名称:nfv_api,代码行数:11,代码来源:packaging.py

示例11: test_get_script_header_jython_workaround

    def test_get_script_header_jython_workaround(self):
        # This test doesn't work with Python 3 in some locales
        if PY3 and os.environ.get("LC_CTYPE") in (None, "C", "POSIX"):
            return

        class java:
            class lang:
                class System:
                    @staticmethod
                    def getProperty(property):
                        return ""
        sys.modules["java"] = java

        platform = sys.platform
        sys.platform = 'java1.5.0_13'
        stdout, stderr = sys.stdout, sys.stderr
        try:
            # A mock sys.executable that uses a shebang line (this file)
            exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py')
            assert (
                get_script_header('#!/usr/local/bin/python', executable=exe)
                ==
                '#!/usr/bin/env %s\n' % exe
            )

            # Ensure we generate what is basically a broken shebang line
            # when there's options, with a warning emitted
            sys.stdout = sys.stderr = StringIO()
            candidate = get_script_header('#!/usr/bin/python -x',
                executable=exe)
            assert candidate == '#!%s  -x\n' % exe
            assert 'Unable to adapt shebang line' in sys.stdout.getvalue()
            sys.stdout = sys.stderr = StringIO()
            candidate = get_script_header('#!/usr/bin/python',
                executable=self.non_ascii_exe)
            assert candidate == '#!%s -x\n' % self.non_ascii_exe
            assert 'Unable to adapt shebang line' in sys.stdout.getvalue()
        finally:
            del sys.modules["java"]
            sys.platform = platform
            sys.stdout, sys.stderr = stdout, stderr
开发者ID:4115019,项目名称:ArrangeCourse,代码行数:41,代码来源:test_resources.py

示例12: get_script_args

    def get_script_args(dist, executable=sys_executable, wininst=False):
        """Yield write_script() argument tuples for a distribution's entrypoints"""
        spec = str(dist.as_requirement())
        header = get_script_header("", executable, wininst)
        for group in 'console_scripts', 'gui_scripts':
            for name, ep in dist.get_entry_map(group).items():
                script_text = (
                    "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n"
                    "__requires__ = %(spec)r\n"
                    "import sys\n"
                    "from pkg_resources import load_entry_point\n"
                    "\n"
                    "if __name__ == '__main__':"
                    "\n"
                    "    sys.exit(\n"
                    "        load_entry_point(%(spec)r, %(group)r, %(name)r)()\n"
                    "    )\n"
                ) % locals()
                if sys.platform=='win32' or wininst:
                    # On Windows/wininst, add a .py extension and an .exe launcher
                    if group=='gui_scripts':
                        ext, launcher = '-script.pyw', 'gui.exe'
                        old = ['.pyw']
                        new_header = re.sub('(?i)python.exe','pythonw.exe',header)
                    else:
                        ext, launcher = '-script.py', 'cli.exe'
                        old = ['.py','.pyc','.pyo']
                        new_header = re.sub('(?i)pythonw.exe','python.exe',header)

                    if (sys.platform=='win32' and is_64bit()) or ('--plat-name=win-amd64' in sys.argv):
                        launcher = launcher.replace(".", "-64.")
                    else: # on linux (build system) always fall back to this
                        launcher = launcher.replace(".", "-32.")
                    if os.path.exists(new_header[2:-1]) or sys.platform!='win32':
                        hdr = new_header
                    else:
                        hdr = header
                    yield (name+ext, hdr+script_text, 't', [name+x for x in old])
                    yield (
                        name+'.exe', resource_string('setuptools', launcher),
                        'b' # write in binary mode
                    )
                else:
                    # On other platforms, we assume the right thing to do is to
                    # just write the stub with no extension.
                    yield (name, header+script_text)
开发者ID:science-automation,项目名称:scicloud,代码行数:46,代码来源:setup.py

示例13: get_script_args

def get_script_args(dist, executable=os.path.normpath(sys.executable), wininst=False):
    """Yield write_script() argument tuples for a distribution's entrypoints"""
    header = easy_install.get_script_header("", executable, wininst)
    for group in 'console_scripts', 'gui_scripts':
        for name, _ep in dist.get_entry_map(group).items():
            script_text = runner_script_template
            if sys.platform=='win32' or wininst:
                # On Windows/wininst, add a .py extension and an .exe launcher
                if group=='gui_scripts':
                    launcher_type = 'gui'
                    ext = '-script.pyw'
                    old = ['.pyw']
                    new_header = re.sub('(?i)python.exe','pythonw.exe',header)
                else:
                    launcher_type = 'cli'
                    ext = '-script.py'
                    old = ['.py','.pyc','.pyo']
                    new_header = re.sub('(?i)pythonw.exe','python.exe',header)
                if os.path.exists(new_header[2:-1].strip('"')) or sys.platform!='win32':
                    hdr = new_header
                else:
                    hdr = header
                yield (name+ext, hdr+script_text, 't', [name+x for x in old])
                yield (
                    name+'.exe', easy_install.get_win_launcher(launcher_type),
                    'b' # write in binary mode
                )
                if not easy_install.is_64bit():
                    # install a manifest for the launcher to prevent Windows
                    #  from detecting it as an installer (which it will for
                    #  launchers like easy_install.exe). Consider only
                    #  adding a manifest for launchers detected as installers.
                    #  See Distribute #143 for details.
                    m_name = name + '.exe.manifest'
                    yield (m_name, easy_install.load_launcher_manifest(name), 't')
            else:
                # On other platforms, we assume the right thing to do is to
                # just write the stub with no extension.
                yield (name, header+script_text)
开发者ID:kayhayen,项目名称:Nuitka,代码行数:39,代码来源:setup.py

示例14: get_script_args

def get_script_args(dist, executable=sys_executable, wininst=False):
    """Yield write_script() argument tuples for a distribution's entrypoints"""
    header = get_script_header("", executable, wininst)
    for group in 'console_scripts', 'gui_scripts':
        for name, ep in dist.get_entry_map(group).items():
            script_text = """import sys
if __name__ == '__main__':
    import {module_name}
    sys.exit({module_name}.{attrs}())
""".format(module_name=ep.module_name, attrs='.'.join(ep.attrs),
           )
            if sys.platform == 'win32' or wininst:
                # On Windows/wininst, add a .py extension and an .exe launcher
                if group == 'gui_scripts':
                    ext, launcher = '-script.pyw', 'gui.exe'
                    old = ['.pyw']
                    new_header = re.sub('(?i)python.exe', 'pythonw.exe', header)
                else:
                    ext, launcher = '-script.py', 'cli.exe'
                    old = ['.py', '.pyc', '.pyo']
                    new_header = re.sub('(?i)pythonw.exe', 'python.exe', header)
                if is_64bit():
                    launcher = launcher.replace(".", "-64.")
                else:
                    launcher = launcher.replace(".", "-32.")
                if os.path.exists(new_header[2:-1]) or sys.platform != 'win32':
                    hdr = new_header
                else:
                    hdr = header
                yield (name+ext, hdr+script_text, 't', [name+x for x in old])
                yield (
                    name+'.exe', resource_string('setuptools', launcher),
                    'b'  # write in binary mode
                )
            else:
                # On other platforms, we assume the right thing to do is to
                # just write the stub with no extension.
                yield (name, header+script_text)
开发者ID:agiledata,项目名称:pkglib,代码行数:38,代码来源:easy_install.py

示例15: install_wrapper_scripts

 def install_wrapper_scripts(self, dist):
     develop.develop.install_wrapper_scripts(self, dist)
     header = easy_install.get_script_header(
         "", easy_install.sys_executable, False)
     self.write_script("gnocchi-api", header + SCRIPT_TMPL)
开发者ID:luo-zn,项目名称:gnocchi,代码行数:5,代码来源:setuptools.py


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