I've got a program/joke that needs a reasonably large data structure to operate, (a dictionary that takes a few开发者_JS百科 seconds to construct) and I would like to create and pickle it into the installation dir when running python setup.py install
.
setup()
in distutils.core
looks like it shouldn't exit, so I thought that I could just import my module and call the function after calling setup()
in setup.py, but it doesn't seem to be working, even though installation does work.
This is what my setup.py looks like right now:
from distutils.core import setup
setup(...
)
from phoneoops import utils
utils.get_hashed_dictionary(save=True)
I created a dummy setup.py as:
from distutils.core import setup
setup()
print 'after'
and my print statement prints just fine after running python setup.py install
.
I tried an invalid command like python setup.py xx
, and the after print didn't get called.
Are you sure it didn't raise an Exception or SystemExit?
When I modified this simple example to:
try:
setup()
except SystemExit as e:
print e
print 'after'
and ran python setup.py xx
, the after statement ran fine.
Edit:
Agreed, @AndiDog, this is better (unless for some reason you want to swallow the exception):
try:
setup()
finally:
print 'after'
精彩评论