Skip to content

Instantly share code, notes, and snippets.

@jackmaney
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmaney/afcc8802283c8232e513 to your computer and use it in GitHub Desktop.
Save jackmaney/afcc8802283c8232e513 to your computer and use it in GitHub Desktop.
Using distutils to parse MANIFEST.in and grab files against the manifest
# Adapted from https://github.com/python/cpython/blob/2.7/Lib/distutils/command/sdist.py#L386
from distutils.text_file import TextFile
from distutils.filelist import FileList
template = TextFile("MANIFEST.in", strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1)
filelist = FileList()
try:
while True:
line = template.readline()
if line is None:
break
try:
filelist.process_template_line(line)
except:
print "Crap, couldn't process line: %s" % line
finally:
template.close()
# filelist.files now contains the files accepted by MANIFEST.in:
for file in filelist.files:
print file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment