[Distutils] Q about best practices now (or near future)
Vinay Sajip
vinay_sajip at yahoo.co.uk
Thu Jul 18 18:49:26 CEST 2013
Marcus Smith <qwcode <at> gmail.com> writes:
> the idea to have pip vendor setuptools crumbles a bit due to console
scripts
needing pkg_resources.
They don't *need* pkg_resources. All they're doing is taking a module name
and the name of a nested object in the form 'a.b.c', and distlib-generated
scripts show that no external references are needed. Here's the template for
a distlib-generated script:
SCRIPT_TEMPLATE = '''%(shebang)s
if __name__ == '__main__':
import sys, re
def _resolve(module, func):
__import__(module)
mod = sys.modules[module]
parts = func.split('.')
result = getattr(mod, parts.pop(0))
for p in parts:
result = getattr(result, p)
return result
try:
sys.argv[0] = re.sub('-script.pyw?$', '', sys.argv[0])
func = _resolve('%(module)s', '%(func)s')
rc = func() # None interpreted as 0
except Exception as e: # only supporting Python >= 2.6
sys.stderr.write('%%s\\n' %% e)
rc = 1
sys.exit(rc)
'''
I don't see any reason why setuptools couldn't be updated to use this
approach.
Regards,
Vinay Sajip
More information about the Distutils-SIG
mailing list