setup.py 3.98 KB
Newer Older
1
2
3
4
5
6
7
#!/usr/bin/env python
#
# setup.py - setuptools configuration for installing the fslpy package.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#

8
import            os
9
10
import os.path as op

11
12
13
from setuptools               import setup
from setuptools               import find_packages
from setuptools.command.sdist import sdist
14
15


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class fsl_sdist(sdist):
    """Custom sdist command which inserts the LICENSE text at the
    beginning of every source file.
    """

    def make_distribution(self):

        # Force distutils.command.sdist to copy
        # files instead of hardlinking them. This
        # hack is performed by setuptools >= 24.3.0,
        # but is not done by earlier versions. 
        link = getattr(os, 'link', None)
        try:
            del(os.link)
        except:
            pass
        
        sdist.make_distribution(self)

        if link is not None:
            os.link = link
    
    
    def make_release_tree(self, base_dir, files):

        # Make the release tree
        sdist.make_release_tree(self, base_dir, files)

        licence = op.abspath('LICENSE')

        if not op.exists(licence):
            return

        with open(licence, 'rt') as f:
            licence = f.read()

        patchfuncs = {

            '.py' : self.__patch_py_file,
        }

        # Walk through the release 
        # tree, and patch the license 
        # into every relevant file.
        for root, dirs, files in os.walk(base_dir):
            for filename in files:

                filename  = op.join(root, filename)
                ext       = op.splitext(filename)[1]
                patchfunc = patchfuncs.get(ext)

                if patchfunc is not None:
                    patchfunc(filename, licence)


    def __patch_py_file(self, filename, licence):

        licence = licence.split('\n')
74
        licence = ['# {0}'.format(l) for l in licence]
75
76
77
78
79
80
81
82
83
84

        with open(filename, 'rt') as f:
            lines = f.read().split('\n')

        # Remove any existing hashbang line
        if len(lines) > 0 and lines[0].startswith('#!'):
            lines = lines[1:]

        # Insert the fsl hashbang and the licence
        lines = ['#!/usr/bin/env fslpython'] + ['#'] + licence + lines
85
        lines = ['{0}\n'.format(l) for l in lines]
86
87
88
89
90
91
92

        with open(filename, 'wt') as f:
            f.writelines(lines)



# The directory in which this setup.py file is contained.
93
94
95
96
97
98
99
100
101
basedir = op.dirname(__file__)


# Figure out the current fslpy version, as defined in fsl/version.py. We
# don't want to import the fsl package,  as this may cause build problems.
# So we manually parse the contents of fsl/version.py to extract the
# version number.
version = {}
with open(op.join(basedir, "fsl", "version.py")) as f:
102
103
104
105
    for line in f:
        if line.startswith('__version__'):
            exec(line, version)
            break 
106

107
108
109
110
111
install_requires = open(op.join(basedir, 'requirements.txt'), 'rt').readlines()

dependency_links = [i for i in install_requires if     i.startswith('git')]
install_requires = [i for i in install_requires if not i.startswith('git')]

112
113
114
115
setup(

    name='fslpy',

116
    version=version['__version__'],
117

Paul McCarthy's avatar
Paul McCarthy committed
118
    description='FSL Python library',
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

    url='https://git.fmrib.ox.ac.uk/paulmc/fslpy',

    author='Paul McCarthy',

    author_email='pauldmccarthy@gmail.com',

    license='FMRIB',

    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'License :: Free for non-commercial use',
        'Programming Language :: Python :: 2.7',
        'Topic :: Software Development :: Libraries :: Python Modules'],

Paul McCarthy's avatar
Paul McCarthy committed
135
    packages=find_packages(exclude=('doc')),
136

137
138
139
140
141
142
    install_requires=install_requires,
    dependency_links=dependency_links,

    setup_requires=['pytest-runner'],
    tests_require=['pytest', 'pytest-runner'],
    test_suite='tests',
143

144
145
146

    cmdclass={'fsl_sdist' : fsl_sdist},

147
148
149
150
151
152
    entry_points={
        'console_scripts' : [
            'fslpy_imcp = fsl.scripts.imcp:main',
            'fslpy_immv = fsl.scripts.immv:main'
        ]
    }
153
)