[Distutils] install_scripts and install_data commands

Bastian Kleineidam calvin@cs.uni-sb.de
Fri, 12 May 2000 13:15:54 +0200 (CEST)


Hello,

>However, I just realized a problem: we probably should have a
>"build_scripts" command, to ensure that the proper "#!" line is in the
>installed scripts.  
Do we have always Python scripts? What about shell scripts, and
specifically Windows Batch scripts?
See below for my current "Windows" hack in setup.py.

>But I don't think we should rely on everyone using the
>"#!/usr/bin/env" hack, either: the first python on the path isn't
>necessarily the right one.  
The "first python on the path" is the correct thing for the user,
otherwise the path is wrong. So "/usr/bin/env pyton" yields the correct
interpreter to execute.


  Bastian


PS. Here is my Distribution class form setup.py for LinkChecker:
# Autodetect the existence of an SSL library (this is pretty shitty)
# Autodetect Windows platforms to include the linkchecker.bat script
class LCDistribution(Distribution):
    default_include_dirs = ['/usr/include/openssl',
                            '/usr/local/include/openssl']
    def run_commands (self):
        self.check_ssl()
        self.check_windows()
        for cmd in self.commands:
            self.run_command (cmd)

    def check_ssl(self):
        incldir = self.has_ssl()
        if incldir:
            self.announce("SSL header file ssl.h found, "
                          "enabling SSL compilation.")
            self.ext_modules = [('ssl', {'sources': ['ssl.c'],
                        'include_dirs': [incldir],
                        'library_dirs': ['/usr/lib'],
                        'libs': ['ssl']})]
        else:
            self.announce("SSL header file ssl.h missing, "
                          "disabling SSL compilation.\n"
                          "Use the -I option for the build_ext command.")

    def check_windows(self):
        if sys.platform=='win32':
            inst = self.find_command_obj("install")
            inst.ensure_ready()
            t = Template("linkchecker.bat.tmpl")
            f = open("linkchecker.bat","w")
            # replace "path_to_linkchecker" with install path 
            f.write(t.fill_in({"path_to_linkchecker": inst.install_scripts}))
            f.close()
            self.scripts.append('linkchecker.bat')

    def has_ssl(self):
        incls = self.find_command_obj("build_ext").include_dirs
        incls = (incls and string.split(incls, os.pathsep)) or []
        for d in incls + self.default_include_dirs:
            if os.path.exists(os.path.join(d, "ssl.h")):
                return d
        return 0