Commit 90d6a2d5 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Licence update. New setuptools 'fsl_sdist' command, which inserts

licence text and FSL hashbang into every source file.
parent 0ee2c168
props library, 2016, The University of Oxford (the "Software")
The props library
Part of FSL - FMRIB's Software Library
Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance
Imaging of the Brain), Department of Clinical Neurology, Oxford
University, Oxford, UK
FMRIB Software Library, Release 5.0 (c) 2012, The University of
Oxford (the "Software")
The Software remains the property of the University of Oxford ("the
......@@ -46,4 +61,4 @@ external organisation for which payment is received. If you are
interested in using the Software commercially, please contact Isis
Innovation Limited ("Isis"), the technology transfer company of the
University, to negotiate a licence. Contact details are: quoting reference BS/9564. quoting reference DE/9564.
include LICENSE
include requirements.txt
recursive-include doc *
......@@ -5,22 +5,106 @@
# Author: Paul McCarthy <>
import os
import os.path as op
from setuptools import setup
from setuptools import find_packages
import props
from setuptools import setup
from setuptools import find_packages
from setuptools.command.sdist import sdist
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)
if link is not None: = 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):
with open(licence, 'rt') as f:
licence =
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')
licence = ['# {}'.format(l) for l in licence]
with open(filename, 'rt') as f:
lines ='\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
lines = ['{}\n'.format(l) for l in lines]
with open(filename, 'wt') as f:
basedir = op.dirname(__file__)
install_requires = open(op.join(basedir, 'requirements.txt'), 'rt').readlines()
# Extract the vesrion number from props/
version = {}
with open(op.join(basedir, "props", "")) as f:
for line in f:
if line.startswith('__version__'):
exec(line, version)
description='Python descriptor framework',
......@@ -43,5 +127,7 @@ setup(
cmdclass={'fsl_sdist' : fsl_sdist},
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment