Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py2app should byte-compile the script file #47

Open
ronaldoussoren opened this issue May 25, 2012 · 6 comments
Open

py2app should byte-compile the script file #47

ronaldoussoren opened this issue May 25, 2012 · 6 comments
Labels
enhancement New feature or request

Comments

@ronaldoussoren
Copy link
Owner

Original report by RajeshVaidheeswarran (Bitbucket: RajeshVaidheeswarran, ).


Hello,

I am looking at creating an app that parses a config file and does stuff..

When I run the app directly, it works well, but when I create a binary using py2app, the configparser doesn't parse anymore. The solution to this problem eludes me.

I have a very distilled down version of this problem with just a single script.

The python script - foo.py

The script:

import ConfigParser

a = ConfigParser.ConfigParser()
r = a.read("foo.cfg")
print r
print a
print a.sections()
for s in a.sections():
print s
for i in a.items(s):
	print "\t", i

The config file: foo.cfg

The file:

[main]
hello=world

[section1]
cup=cake

[section2]
tom=jerry

The execution from source:

Output:

Rajesh-Vaidheeswarrans-MacBook-Pro:scratch rvaidhee$ python foo.py
['foo.cfg']
<ConfigParser.ConfigParser instance at 0x10997af38>
['main', 'section1', 'section2']
main
('hello', 'world')
section1
('cup', 'cake')
section2
('tom', 'jerry')

The app was created as follows:

python setup.py py2app --includes ConfigParser --argv-emulation -a

I tried not including the ConfigParser first, and then tried including it. Both produce the same result.

The execution from the binary app:

Rajesh-Vaidheeswarrans-MacBook-Pro:scratch rvaidhee$        ./dist/foo.app/Contents/MacOS/foo 

[]
<ConfigParser.ConfigParser instance at 0x102c5a3f8>
[]

As you can see above, the sections and file list are both empty

The setup.py file to create the app

Source:

"""
This is a setup.py script generated by py2applet

Usage:
python setup.py py2app
"""

from setuptools import setup

APP = ['foo.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)
@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


This is almost certainly related to the current working directory of your script: py2app by default changes the current working directory to the 'Resources' directory inside of the application bundle.

The reason for this is that when you double-click the application icon (the usual way to start the application) the Finder will start your application with an arbitrary working directory (although IIRC this was the root directory from OSX 10.0 until now).

You have to use an absolute path to read the configuration file.

@ronaldoussoren
Copy link
Owner Author

Original comment by RajeshVaidheeswarran (Bitbucket: RajeshVaidheeswarran, ).


Thank you! You were right. It works with an absolute path.

However, I see that py2app uses the pyc files inside a zip file and also copies the actual script to Resources. Is there any way to make it can actually embed the zip inside the binary?

@ronaldoussoren
Copy link
Owner Author

Original comment by RajeshVaidheeswarran (Bitbucket: RajeshVaidheeswarran, ).


not sure how I accidentally changed the state.. reverting it to new

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


The easiest workaround to include the script in the zipfile: add a wrapper script that just imports the real script.

That said, I will add the script to the zipfile in a future release but haven't gotten around to that yet.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


BTW. The primary reason why the script is not in the zipfile is that py2app ensures that the script is loaded as the 'main' module.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Changed the title to document why this issue is still open

@ronaldoussoren ronaldoussoren added major bug Something isn't working labels Jan 14, 2020
@ronaldoussoren ronaldoussoren added enhancement New feature or request and removed bug Something isn't working labels Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant