From c410f8d4eaaba5575453fbee26948419bbc2a247 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Mar 2014 13:58:43 +0100 Subject: Create stub template from a multiline string. --- setuptools/command/bdist_egg.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'setuptools/command/bdist_egg.py') diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index 383eb5f8..0d1cc65e 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -6,6 +6,7 @@ Build .egg distributions""" import sys import os import marshal +import textwrap from setuptools import Command from distutils.dir_util import remove_tree, mkpath try: @@ -34,19 +35,17 @@ def strip_module(filename): return filename def write_stub(resource, pyfile): + _stub_template = textwrap.dedent(""" + def __bootstrap__(): + global __bootstrap__, __loader__, __file__ + import sys, pkg_resources, imp + __file__ = pkg_resources.resource_filename(__name__, %r) + __loader__ = None; del __bootstrap__, __loader__ + imp.load_dynamic(__name__,__file__) + __bootstrap__() + """).lstrip() f = open(pyfile,'w') - f.write( - '\n'.join([ - "def __bootstrap__():", - " global __bootstrap__, __loader__, __file__", - " import sys, pkg_resources, imp", - " __file__ = pkg_resources.resource_filename(__name__,%r)" - % resource, - " __loader__ = None; del __bootstrap__, __loader__", - " imp.load_dynamic(__name__,__file__)", - "__bootstrap__()", - "" # terminal \n - ])) + f.write(_stub_template % resource) f.close() -- cgit v1.2.3