gui2exe - post compile code

Andrea,

I added some post compile code but it is getting executed before the setup() call, shouldn't the code be added after:

# And we are done. That's a setup script :smiley:

# Run setup standalone...
if __name__ == "__main__":
    setup()

I noted that e.g. library.zip and some other files stays around, so I do this:

cwdFolder = os.getcwd()
libFile = os.path.join(cwdFolder, 'dist\\library.zip')
if os.path.exists(libFile):
    print 'deleting duplicate files'
    os.remove(libFile)
    os.remove(os.path.join(cwdFolder, 'dist\\bz2.pyd'))
    os.remove(os.path.join(cwdFolder, 'dist\\select.pyd'))
    os.remove(os.path.join(cwdFolder, 'dist\\unicodedata.pyd'))

But if I have this before the setup() call I still see the files.

Note that these files only stick around if I run "\python26\python setup.py py2exe" from the command line, if I compile from within gui2exe they are not there.

Can you see where I go wrong?

Werner

Hi Werner,

Andrea,

I added some post compile code but it is getting executed before the setup()
call, shouldn't the code be added after:

# And we are done. That's a setup script :smiley:

# Run setup standalone...
if __name__ == "__main__":
setup()

I noted that e.g. library.zip and some other files stays around, so I do
this:

cwdFolder = os.getcwd()
libFile = os.path.join(cwdFolder, 'dist\\library.zip')
if os.path.exists(libFile):
print 'deleting duplicate files'
os.remove(libFile)
os.remove(os.path.join(cwdFolder, 'dist\\bz2.pyd'))
os.remove(os.path.join(cwdFolder, 'dist\\select.pyd'))
os.remove(os.path.join(cwdFolder, 'dist\\unicodedata.pyd'))

But if I have this before the setup() call I still see the files.

Note that these files only stick around if I run "\python26\python setup.py
py2exe" from the command line, if I compile from within gui2exe they are not
there.

Can you see where I go wrong?

No, not really: actually, now that I look at the setup.py code more
closely, what was the point of having these lines:

if __name__ == "__main__":
    setup()

? The setup code is executed anyway, it's not inside a function or a
class... it's just a module with code in it. I may have my brain not
connected today, but I can't remember why we put those lines there.

Anyway, a quick solution to implement in GUI2Exe is to move these lines:

if __name__ == "__main__":
    setup()

*before* the post-compilation code. Do you think it will be good enough?

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On Sat, May 16, 2009 at 2:31 PM, Werner F. Bruhin wrote:

Hi Andrea,

Andrea Gavana wrote:
...

No, not really: actually, now that I look at the setup.py code more
closely, what was the point of having these lines:

if __name__ == "__main__":
    setup()

? The setup code is executed anyway, it's not inside a function or a
class... it's just a module with code in it. I may have my brain not
connected today, but I can't remember why we put those lines there.

Anyway, a quick solution to implement in GUI2Exe is to move these lines:

if __name__ == "__main__":
    setup()

*before* the post-compilation code. Do you think it will be good enough?
  

That should probably be fine, as that is basically what I did to the exported file.

But are these lines really needed, i.e. when will they be used? I just did a little test by commenting them and then running setup.py py2exe from the command line or from within Boa (has a special run button for py2exe) it works fine without this code.

So, unless someone comes up with why they are needed you might just remove them all together.

Werner