briefcase icon indicating copy to clipboard operation
briefcase copied to clipboard

Allow duplicated package names in `sources` list

Open mhsmith opened this issue 3 years ago • 2 comments

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.

mhsmith avatar Nov 23 '22 16:11 mhsmith

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 dev is when none of the directories contain an __init__.py file (an implicit namespace package). It may also be OK if the first directory contains an __init__.py file with an appropriate call to pkgutil.extend_path or pkg_resources.declare_namespace, but we can't easily verify that, so I think these cases should also give a warning.

mhsmith avatar Dec 03 '22 18:12 mhsmith

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.

freakboy3742 avatar Apr 15 '23 04:04 freakboy3742