[Zope-dev] docs.zope.org automation
Chris Withers
chris at simplistix.co.uk
Wed Aug 4 04:50:03 EDT 2010
Jens Vagelpohl wrote:
> I understand that. But it must be possible to do that programatically in
> my code. I mean, "setup.py --long-description" obviously executes Python
> code, which I may be able to execute myself in my current interpreter
> session by importing and executing stuff from setuptools.
Yeah, this is why setup.py sucks ;-)
I've just been doing some build and release tools for a customer that
involve this sort of stuff, I resorted to:
with nested(Replacer(),OutputCapture()) as (r,o):
r.replace('sys.argv',['X','egg_info'])
try:
sys.path.insert(0,path)
curdir = os.getcwd()
os.chdir(path)
# yuk, but setup.py is yuk anyway!
if 'setup' in sys.modules:
del sys.modules['setup']
import setup
finally:
os.chdir(curdir)
sys.path.pop(0)
..in my tests, the del from sys.modules is to allow this to by done
multiple times in one process.
Replacer is
http://packages.python.org/testfixtures/mocking.html#the-context-manager
OutputCapture looks like:
class OutputCapture:
def __enter__(self):
self.original_stdout = sys.stdout
self.original_stderr = sys.stderr
self.output = sys.stdout = sys.stderr = StringIO()
return self
def __exit__(self,*args):
sys.stdout = self.original_stdout
sys.stderr = self.original_stderr
def compare(self,expected):
compare(expected.strip(),self.output.getvalue().strip())
> Having to
> invoke another Python interpreter in a subshell because that's too
> complicated to do any other way is awful.
Yeah, I do resort to this for some things too ;-)
http://packages.python.org/execute/use.html
cheers,
Chris
More information about the Zope-Dev
mailing list