Allow duplicated package names in `sources` list
If any of the sources lists contain directories with the same basenames, Briefcase gives an error like this:
The `sources` list for 'toga-test' contains duplicated package names.
However, there are legitimate reasons for wanting to merge together multiple directories into a single package. There's even a PEP about it. ~~And it would make the Toga test code organization a bit simpler if both the common code and the backend-specific code were in the same tests package.~~ (see below)
The Briefcase documentation already indicates how this would work:
If an application defines sources at the global level, application level, and platform level, the final set of sources will be the concatenation of sources from all levels, starting from least to most specific.
However, "concatenation" is a bit vague, so this should be clarified.
I've changed my mind about using this in the test app: see https://github.com/beeware/toga/pull/1687#discussion_r1035482562. So there's no immediate need to fix this. But when we do, it's important to minimize any differences between briefcase dev and briefcase run. Here's how we can do that:
- For
briefcase dev, the directories would be added to the PYTHONPATH in order from most to least specific, so most specific takes priority. - For
briefcase run, the directories would be copied into the app in order from most to least specific:- Files with the same path would not overwrite, and would give a warning if they had different content, because this may indicate a user error.
- Directories with the same path would be merged. The only case which guarantees consistency with
briefcase devis when none of the directories contain an__init__.pyfile (an implicit namespace package). It may also be OK if the first directory contains an__init__.pyfile with an appropriate call topkgutil.extend_pathorpkg_resources.declare_namespace, but we can't easily verify that, so I think these cases should also give a warning.
An implementation note - if/when this is done, there are some paths that shouldn't be copied as part of a merge process - see #986 for a discussion.