Re: docs.zope.org automation

Chris Withers <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
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


_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.