import textwrap import os import shutil import subprocess import contextlib def make_file(file_path, content=''): base = os.path.dirname(file_path) if base: if not os.path.exists(base): os.makedirs(base) with open(file_path, 'w') as out: out.write(content) @contextlib.contextmanager def make_tree(): try: make_file('pkg/__init__.py') make_file('pkg/file with spaces.py') make_file('setup.py', textwrap.dedent(""" from distutils.core import setup setup(name='issue21153-package', packages=['pkg']) """)) yield finally: if os.path.exists('pkg'): shutil.rmtree('pkg') def run(): with make_tree(): subprocess.check_call(['python', 'setup.py', 'bdist_rpm']) if __name__ == '__main__': run()