예제 #1
0
    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 = io.StringIO()
            self.assertEqual(
                get_script_header('#!/usr/bin/python -x', executable=exe),
                '#!%s  -x\n' % exe)
            self.assertTrue(
                'Unable to adapt shebang line' in sys.stdout.getvalue())
            sys.stdout = io.StringIO()
            self.assertEqual(
                get_script_header('#!/usr/bin/python',
                                  executable=self.non_ascii_exe),
                '#!%s -x\n' % self.non_ascii_exe)
            self.assertTrue(
                'Unable to adapt shebang line' in sys.stdout.getvalue())
        finally:
            sys.platform = platform
            sys.stdout = stdout
예제 #2
0
    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
예제 #3
0
    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()
예제 #4
0
    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 = io.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 = io.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
예제 #5
0
    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
예제 #6
0
    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()
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 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
예제 #10
0
 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
예제 #11
0
 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
예제 #12
0
 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))
         self.assertEqual(get_script_header('#!/usr/local/bin/python'),
             expected)
         expected = '#!%s  -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python -x'),
             expected)
         self.assertEqual(get_script_header('#!/usr/bin/python',
                                            executable=self.non_ascii_exe),
                          '#!%s -x\n' % self.non_ascii_exe)
         candidate = get_script_header('#!/usr/bin/python',
             executable=self.exe_with_spaces)
         self.assertEqual(candidate, '#!"%s"\n' % self.exe_with_spaces)
예제 #13
0
파일: packaging.py 프로젝트: rrbutani/pbr
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))
예제 #14
0
파일: packaging.py 프로젝트: Row/SickRage
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))
예제 #15
0
파일: packaging.py 프로젝트: Row/SickRage
 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)
예제 #16
0
 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)
예제 #17
0
 def install_wrapper_scripts(self, dist):
     develop.develop.install_wrapper_scripts(self, dist)
     if self.exclude_scripts:
         return
     script = easy_install.get_script_header("") + SCRIPT_TMPL
     if PY3:
         script = script.encode('ascii')
     self.write_script("gnocchi-api", script, 'b')
예제 #18
0
파일: packaging.py 프로젝트: troytoman/pbr
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)
예제 #19
0
    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')
            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()
            self.assertEqual(
                get_script_header('#!/usr/bin/python -x', executable=exe),
                '#!%s  -x\n' % exe)
            self.assertTrue(
                'Unable to adapt shebang line' in sys.stdout.getvalue())
            sys.stdout = sys.stderr = StringIO()
            self.assertEqual(
                get_script_header('#!/usr/bin/python',
                                  executable=self.non_ascii_exe),
                '#!%s -x\n' % self.non_ascii_exe)
            self.assertTrue(
                'Unable to adapt shebang line' in sys.stdout.getvalue())
        finally:
            del sys.modules["java"]
            sys.platform = platform
            sys.stdout, sys.stderr = stdout, stderr
 def _make_wsgi_scripts_only(self, dist, executable):
     # get_script_header() is deprecated since Setuptools 12.0
     try:
         header = easy_install.ScriptWriter.get_header("", executable)
     except AttributeError:
         header = easy_install.get_script_header("", executable)
     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)
예제 #21
0
def override_get_script_args(dist,
                             executable=os.path.normpath(sys.executable)):
    """Override entrypoints console_script."""
    # get_script_header() is deprecated since Setuptools 12.0
    try:
        header = easy_install.ScriptWriter.get_header("", executable)
    except AttributeError:
        header = easy_install.get_script_header("", executable)
    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))
예제 #22
0
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)
예제 #23
0
    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
예제 #24
0
 def run(self):
     install_scripts.install_scripts.run(self)
     # NOTE(sileht): Build wheel embed custom script as data, and put sheban
     # in script of the building machine. To workaround that build_scripts
     # on bdist_whell return '#!python' and then during whl install it's
     # replaced by the correct interpreter. We do the same here.
     bs_cmd = self.get_finalized_command('build_scripts')
     executable = getattr(bs_cmd, 'executable', easy_install.sys_executable)
     script = easy_install.get_script_header("", executable) + SCRIPT_TMPL
     if PY3:
         script = script.encode('ascii')
     self.write_script("gnocchi-api", script, 'b')
예제 #25
0
 def run(self):
     install_scripts.run(self)
     orig_install_dir = self.install_dir
     self.install_dir = self.install_agents
     eps = EntryPoint.parse_map(self.distribution.entry_points)
     header = get_script_header('')
     for ep in eps.get('resource_agents', {}).values():
         filename = os.path.join(*(ep.name.split('.')))
         contents = header + self.agent_template % {
             'module': ep.module_name,
             'class': ep.attrs[0],
             'method': '.'.join(ep.attrs),
         }
         self.write_script(filename, contents)
     self.install_dir = orig_install_dir
예제 #26
0
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 in 'console_scripts', 'gui_scripts':
        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 = _script_text % dict(
                group=group,
                module_name=ep.module_name,
                import_target=ep.attrs[0],
                invoke_target='.'.join(ep.attrs),
            )
            yield (name, header + script_text)
예제 #27
0
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)
예제 #28
0
    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)
예제 #29
0
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)
예제 #30
0
파일: setup.py 프로젝트: kayhayen/Nuitka
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)
예제 #31
0
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)
예제 #32
0
파일: setup.py 프로젝트: baverman/jeque
def install_script(self, dist, script_name, script_text, dev_path=None):
    script_text = easy_install.get_script_header(script_text) + (
        ''.join(script_text.splitlines(True)[1:]))

    self.write_script(script_name, script_text, 'b')
예제 #33
0
 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)
예제 #34
0
 def run(self):
     install_scripts.install_scripts.run(self)
     header = easy_install.get_script_header(
         "", easy_install.sys_executable, False)
     self.write_script("gnocchi-api", header + SCRIPT_TMPL)