Providing a common initial run-time for python scripts at a workplace doesn't seem to get much attention (or I'm googling incorrectly ;). Common initializations make debugging and other maintenance tasks easier since you know what to expect from the runtime.
I claim that the simplest way to do this = put the following at the top of your script prior to importing libraries.
exec open("/etc/company_name/boot.py")
where /etc/company_name/boot.py contains routines to add library paths relative to the script running (most likely from an exported repository), logging setup, and any other items.
#!/usr/bin/python """ setup the pythonpath """ import sys sys.path.insert(0, "/etc/company_name/") def bootpy_merge_paths(*relative_paths): path = "" # get path from cwd to this program if "/" in sys.argv[0]: path = sys.argv[0].split('/') path[-1] = "" path = '/'.join(path) # merge relative path from cwd -> program -> library for r in relative_paths: sys.path.insert(0, path + r) # merge in library paths in our repo bootpy_merge_paths("../lib", "../../lib", "../../../lib") """ set up logging """ import logging """ anything else? """
Or does a better way exist?