src/setup.py
author ymh <ymh.work@gmail.com>
Fri, 26 Aug 2016 13:36:05 +0200
changeset 154 79b70254a5e0
child 159 a2e6d314da2f
permissions -rw-r--r--
add setup file to build lib. Move things arouch a little bit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
154
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import os
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from distutils.core import setup
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from distutils.command.install_data import install_data
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
from distutils.command.install import INSTALL_SCHEMES
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import sys
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
class osx_install_data(install_data):
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    # for this in distutils.command.install_data#306. It fixes install_lib but not
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    # install_data, which is why we roll our own install_data class.
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    def finalize_options(self):
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
        # By the time finalize_options is called, install.install_lib is set to the
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        # fixed directory, so we set the installdir to install_lib. The
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        # install_data class uses ('install_data', 'install_dir') instead.
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        self.set_undefined_options('install', ('install_lib', 'install_dir'))
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        install_data.finalize_options(self)
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
def fullsplit(path, result=None):
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    """
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    Split a pathname into components (the opposite of os.path.join) in a
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    platform-neutral way.
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    """
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    if result is None:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        result = []
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    head, tail = os.path.split(path)
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    if head == '':
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
        return [tail] + result
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    if head == path:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        return result
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    return fullsplit(head, [tail] + result)
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
def launch_setup(script_name, script_args):
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    if sys.platform == "darwin":
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        cmdclasses = {'install_data': osx_install_data}
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    else:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        cmdclasses = {'install_data': install_data}
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    root_dir = os.path.dirname(__file__)
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    if root_dir != '':
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        os.chdir(root_dir)
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    source_dirs = ['iconolab',]
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    version_variables = {}
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    try:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
        with open(os.path.join(source_dirs[0], "__init__.py")) as f:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
            code = compile(f.read(), "__init__.py", 'exec')
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
            exec(code, version_variables)
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    except:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        pass
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    version = version_variables['__version__']
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    packages, data_files = [], []
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    for source_dir in source_dirs:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
        for dirpath, dirnames, filenames in os.walk(source_dir):
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
            # Ignore dirnames that start with '.'
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
            for i, dirname in enumerate(dirnames):
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
                if dirname.startswith('.') or dirname.startswith('__pycache__'): del dirnames[i]
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
            if '__init__.py' in filenames:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
                packages.append('.'.join(fullsplit(dirpath)))
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
            elif filenames:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
                data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    # Tell distutils to put the data_files in platform-specific installation
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    # locations. See here for an explanation:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    for scheme in INSTALL_SCHEMES.values():
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        scheme['data'] = scheme['purelib']
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    # Small hack for working with bdist_wininst.
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
        for file_info in data_files:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
            file_info[0] = '\\PURELIB\\%s' % file_info[0]
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    #write MANIFEST.in
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
    with open("MANIFEST.in", "w") as m:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        m.write("include CHANGES\n")
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        m.write("include LICENSE\n")
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
        m.write("include README.md\n")
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
        m.write("include MANIFEST.in\n")
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
        for entry in data_files:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
            file_list = entry[1]
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
            for filename in file_list:
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
                m.write("include %s\n" % (filename))
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
    setup(
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
        script_name = script_name,
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
        script_args = script_args,
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
        name='iconolab',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        version=version,
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        author='IRI',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
        author_email='contact@iri.centrepompidou.fr',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        packages=packages,
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
        data_files=data_files,
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        cmdclass = cmdclasses,
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        scripts=[],
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
        url='http://www.iri.centrepompidou.fr/dev/hg/iconolab',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        license='LICENSE',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        description='projet Iconolab',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
        long_description=open('README.md').read(),
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        classifiers=['Development Status :: 4 - Beta',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
                       'Environment :: Web Environment',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
                       'Framework :: Django',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
                       'Intended Audience :: Developers',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
                       'License :: Ceccil-B',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
                       'Operating System :: OS Independent',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
                       'Programming Language :: Python',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
                       'Topic :: Utilities',
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
        ],
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
    )
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
if __name__ == "__main__":
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    script_name = os.path.basename(sys.argv[0])
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
    script_args = sys.argv[1:]
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
79b70254a5e0 add setup file to build lib. Move things arouch a little bit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
    launch_setup(script_name, script_args)