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

Too Easy for Briefcase Apps to Clash with (semi-)Reserved Python Names #853

Closed
rmartin16 opened this issue Sep 6, 2022 · 4 comments
Closed
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start!

Comments

@rmartin16
Copy link
Member

Describe the bug
When a user creates a Briefcase app, the Formal Name is used as the internal name to reference and invoke the app. It includes the app's module name and entry point name among others. Therefore, unintuitive runtime errors can occur when this name collides with the standard library's module namespace or even its (pseudo-)entry points.

To Reproduce
Some examples:

  • a formal name of socket will immediately error since this is an existing module in the standard library that's imported early.
  • a formal name of test may run the CPython test suite (as in does with a packaged Flatpak).
  • a formal name of main incurs a RecursionError because default Briefcase entry point is also named main.

Expected behavior
Briefcase should tell the user these names are not allowed or avoid name clashes altogether.

  • Create a blocklist of names users should not use.
    • This sets up a situation of whack-a-mole.
  • Rework how internal naming works to make clashes less likely.
    • I think the current naming is elegant and intuitive....so prepending briefcase_ (for instance) seems undesirable.
@rmartin16 rmartin16 added the bug A crash or error in behavior. label Sep 6, 2022
@freakboy3742
Copy link
Member

We already have a blocklist, populated with Python, Java, and Windows reserved words; this was introduced in #565 specifically as a response to #460 - the name "switch" is a reserved word in Java.

That list only uses language reserved words; extending it to include "names of modules in the Python standard library", plus some other key names of interest like "test" and "main" seems like a simple fix. It probably doesn't even need to be the full standard library - I'd be surprised if someone called their app wsgiref or this or distutils - but for the sake of completeness, I guess it couldn't hurt.

Yes, this will ultimately be whack-a-mole - but I think the moles will eventually become fairly endangered species as we add classes of names to this list :-)

@rmartin16
Copy link
Member Author

I meant to add that I created this when I realized there wasn't a reliable list of semi-reserved names in Python. To that end, Python 3.10 introduced sys.stdlib_module_names...although, I found at least some debate about how this should be used/trusted. The isort team apparently created things like isort.stdlibs.py39 to determine what was part of the standard library in lieu of any support previously.

Another (bit half baked) idea I had was to preform a check to see if the user-provided name could be imported...the user could at least be warned about potentially creating a name clash then,

A bit aged but this is documenting in some depth how to find available modules.

At any rate....briefcase didn't create this problem....but it makes usability here a bit easier. I'll probably just implement an additional list of words to avoid for now.

@freakboy3742 freakboy3742 added the good first issue Is this your first time contributing? This could be a good place to start! label Sep 21, 2022
@newbery
Copy link
Contributor

newbery commented Apr 25, 2023

I'm looking into this for the sprint

@freakboy3742
Copy link
Member

Fixed in #1238.

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. good first issue Is this your first time contributing? This could be a good place to start!
Projects
None yet
Development

No branches or pull requests

3 participants