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

Improve handling of command line arguments (esp for document-based apps) #3019

Open
freakboy3742 opened this issue Dec 5, 2024 · 1 comment
Labels
bug A crash or error in behavior. linux The issue relates Linux support. macOS The issue relates to Apple macOS support. windows The issue relates to Microsoft Windows support.

Comments

@freakboy3742
Copy link
Member

Describe the bug

If an app declares document types, any command line argument that isn't a document will result in a Don't know how to open documents with extension ... error.

Steps to reproduce

Run the testbed with a test specifier:

briefcase run --test -- tests/app/test_app.py

results in an error because the testbed doesn't know how to handle documents of type .py.

Expected behavior

Functionally, Testbed shouldn't raise an error or warning for any "normal" operation.

More generally, it should be possible for a document-based app to handle arguments that aren't documents. It might be helpful for this list of arguments to be processed using standard argparse handling, with the argparse instance being configured using a standard interface (with a default implementation).

Screenshots

No response

Environment

  • Operating System: Any desktop platform
  • Python version: All
  • Software versions:
    • Toga: 0.3.19+

Logs


Additional context

There may be an argument that this is a quirk of testbed - that testbed is a document-based app by necessity, but not representative of "real" document-based apps, and the API contract of document-based apps is "the command-line arguments can only be documents". This would be an extreme option, but not a completely indefensible one.

For GTK and Windows, this should be relatively straightforward - replace the sys.argv[] reference in App._create_initial_windows with something based on an argparse definition.

For cocoa it's a little more complex, because the document handling is managed by Cocoa (so as to enable "drop document onto app" handling). We either need to separate "first launch" argument handling from the application:openFiles: handler, or we need a strategy for how document names are handled in the context of a full list of arguments.

@freakboy3742 freakboy3742 added bug A crash or error in behavior. linux The issue relates Linux support. macOS The issue relates to Apple macOS support. windows The issue relates to Microsoft Windows support. labels Dec 5, 2024
@freakboy3742 freakboy3742 changed the title Improve handling of command line arguments Improve handling of command line arguments (esp for document-based apps) Dec 5, 2024
@HalfWhitt
Copy link
Contributor

HalfWhitt commented Dec 5, 2024

Even outside of the testbed, simply running a script (that launches an app) also generates such an error.

$ python test_script.py
test_script.py: Don't know how to open documents with extension .py

(Running it as a module with -m doesn't.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. linux The issue relates Linux support. macOS The issue relates to Apple macOS support. windows The issue relates to Microsoft Windows support.
Projects
None yet
Development

No branches or pull requests

2 participants