Commit e4830940 authored by Christoph Groth's avatar Christoph Groth
Browse files

generate MANIFEST from the output of "git ls-files" (less error-prone)

parent d504d5d8
# This file specifies the files to be included in the source distribution
# in addition to the default ones.
# We explicitly include both pyx and c files, so that both are shipped in
# source tarballs independently of whether " sdist" is run with
# --no-cython or not.
recursive-include kwant *.pyx
recursive-include kwant *.pxd
recursive-include kwant *.c
recursive-include kwant *.h
recursive-include examples *.py
include doc/other/*[a-zA-Z]
include doc/Makefile
recursive-include doc/source *.rst *.py *.svg *.sh *.diff
recursive-include doc/source/_static *[a-zA-Z]
recursive-exclude doc/source/images [a-zA-Z]*.py
recursive-include doc/templates *[a-zA-Z]
prune doc/source/reference/generated
recursive-include doc/sphinxext *.py *.txt *.in
......@@ -48,6 +48,8 @@ if cythonize and cython_version:
from distutils.command.build_ext import build_ext
kwant_dir = os.path.dirname(os.path.abspath(__file__))
class kwant_build_ext(build_ext):
def run(self):
......@@ -96,7 +98,18 @@ class build_tut(Command):
# that the tutorial is present.
class kwant_build(distutils_build):
sub_commands = [('build_tut', None)] + distutils_build.sub_commands
def git_lsfiles():
p = subprocess.Popen(['git', 'ls-files'], cwd=kwant_dir,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError:
if p.wait() != 0:
return p.communicate()[0].split('\n')[:-1]
# Make the command "sdist" depend on "build". This verifies that the
......@@ -105,14 +118,54 @@ class kwant_build(distutils_build):
# distribution and that they will be up-to-date.
class kwant_sdist(distutils_sdist):
sub_commands = [('build', None)] + distutils_sdist.sub_commands
def run(self):
names = git_lsfiles()
trustworthy = True
if names is None:
# Check that MANIFEST exists and has not been generated by
# distutils.
with open(kwant_dir + '/MANIFEST', 'r') as f:
line =
except IOError:
print >>sys.stderr, "error: MANIFEST file is missing and " \
"Git is not available to regenerate it."
trustworthy = not line.strip().startswith('#')
# Generate MANIFEST file.
with open(kwant_dir + '/MANIFEST', 'w') as f:
for name in names:
a, sep, b = name.rpartition('/')
if b == '.gitignore':
stem, dot, extension = b.rpartition('.')
if extension == 'pyx':
f.write(''.join([a, sep, stem, dot, 'c', '\n']))
f.write(name + '\n')
f.write(STATIC_VERSION_FILE + '\n')
if names is None:
print >>sys.stderr, \
"""**************** Warning ****************
Git was not available for re-generating the MANIFEST file (the list of file
names to be included in the source distribution). The old MANIFEST was used."""
if not trustworthy:
print >>sys.stderr, \
"""**************** Warning ****************
The existing MANIFEST file seems to have been generated by distutils (it begins
with a comment). It may well be incomplete."""
# This is an exact copy of the function from kwant/ We can't import
# it here (because kwant is not yet built when this scipt is run), so we just
# include a copy.
def get_version_from_git():
kwant_dir = os.path.dirname(os.path.abspath(__file__))
p = subprocess.Popen(['git', 'describe'], cwd=kwant_dir,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
......@@ -297,7 +350,7 @@ def ext_modules(extensions):
for f in cythonized_files)
except OSError:
print >>sys.stderr, \
"Error: Cython-generated file {0} is missing.".format(f)
"error: Cython-generated file {0} is missing.".format(f)
if cythonize:
print >>sys.stderr, "Install Cython so it can be made" \
" or use a source distribution of kwant."
Markdown is supported
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