Skip to content
New issue

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

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

Already on GitHub? # to your account

Move command-line args out of dev-mode Python invocation #1413

Merged

Conversation

jeamland
Copy link
Contributor

For some reason NSApplication/CoreFoundation gets very confused if we pass certain command-line arguments to the outer Python interpreter when running in dev mode.

This patch removes all command-line arguments from the invocation, using environment variables to achieve the equivalent outcomes. The remaining argument, the actual code to start the application, appears to not cause problems.

@jeamland jeamland force-pushed the jeamland/briefcase-dev-argv-hilarity branch 2 times, most recently from dfbbc23 to 7c1c45a Compare August 21, 2023 06:00
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 minor suggestions listed inline, but otherwise looks good.

On macOS CoreFoundation/NSApplication will do its own independent
parsing of argc/argv. This means that whatever we pass to the
Python interpreter on start-up will also be visible to
NSApplication which will interpret things like `-u` (used to make
I/O unbuffered in CPython) as `-u [URL]` (a request to open a
document by URL). This is, rather patently, Not Good.

To avoid this causing unwanted hilarity, we use environment
variables to configure the Python interpreter rather than
command-line options.
@jeamland jeamland force-pushed the jeamland/briefcase-dev-argv-hilarity branch from 7c1c45a to c3cc4ee Compare August 21, 2023 06:57
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@freakboy3742 freakboy3742 merged commit a800db1 into beeware:main Aug 21, 2023
Comment on lines +31 to +35
# Equivalent of passing "-X dev"
"PYTHONMALLOC": "debug",
"PYTHONASYNCIODEBUG": "1",
"PYTHONFAULTHANDLER": "1",
"PYTHONWARNINGS": "default",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious....was there a reason that PYTHONDEVMODE=1 wasn't used instead?

Setting just PYTHONDEVMODE seems more likely to be forward-compatible with enabling this mode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...we didn't realise the setting existed :-)

It's obvious now that I'm looking at the docs; no objection replacing these 4 settings with the single PYTHONDEVMODE=1

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants