def _collect_package_prefixes(package_dir, packages):
    '\n    Collect the list of prefixes for all packages\n\n    The list is used to match paths in the install manifest to packages\n    specified in the setup.py script.\n\n    The list is sorted in decreasing order of prefix length so that paths are\n    matched with their immediate parent package, instead of any of that\n    package\'s ancestors.\n\n    For example, consider the project structure below.  Assume that the\n    setup call was made with a package list featuring "top" and "top.bar", but\n    not "top.not_a_subpackage".\n\n    ::\n\n        top/                -> top/\n          __init__.py       -> top/__init__.py                 (parent: top)\n          foo.py            -> top/foo.py                      (parent: top)\n          bar/              -> top/bar/                        (parent: top)\n            __init__.py     -> top/bar/__init__.py             (parent: top.bar)\n\n          not_a_subpackage/ -> top/not_a_subpackage/           (parent: top)\n            data_0.txt      -> top/not_a_subpackage/data_0.txt (parent: top)\n            data_1.txt      -> top/not_a_subpackage/data_1.txt (parent: top)\n\n    The paths in the generated install manifest are matched to packages\n    according to the parents indicated on the right.  Only packages that are\n    specified in the setup() call are considered.  Because of the sort order,\n    the data files on the bottom would have been mapped to\n    "top.not_a_subpackage" instead of "top", proper -- had such a package been\n    specified.\n    '
    return list(sorted(((package_dir[package].replace('.', '/'), package) for package in packages), key=(lambda tup: len(tup[0])), reverse=True))
Collect the list of prefixes for all packages

The list is used to match paths in the install manifest to packages
specified in the setup.py script.

The list is sorted in decreasing order of prefix length so that paths are
matched with their immediate parent package, instead of any of that
package's ancestors.

For example, consider the project structure below.  Assume that the
setup call was made with a package list featuring "top" and "top.bar", but
not "top.not_a_subpackage".

::

    top/                -> top/
      __init__.py       -> top/__init__.py                 (parent: top)
      foo.py            -> top/foo.py                      (parent: top)
      bar/              -> top/bar/                        (parent: top)
        __init__.py     -> top/bar/__init__.py             (parent: top.bar)

      not_a_subpackage/ -> top/not_a_subpackage/           (parent: top)
        data_0.txt      -> top/not_a_subpackage/data_0.txt (parent: top)
        data_1.txt      -> top/not_a_subpackage/data_1.txt (parent: top)

The paths in the generated install manifest are matched to packages
according to the parents indicated on the right.  Only packages that are
specified in the setup() call are considered.  Because of the sort order,
the data files on the bottom would have been mapped to
"top.not_a_subpackage" instead of "top", proper -- had such a package been
specified.
def _collect_package_prefixes(package_dir, packages):
    '\n    Collect the list of prefixes for all packages\n\n    The list is used to match paths in the install manifest to packages\n    specified in the setup.py script.\n\n    The list is sorted in decreasing order of prefix length so that paths are\n    matched with their immediate parent package, instead of any of that\n    package\'s ancestors.\n\n    For example, consider the project structure below.  Assume that the\n    setup call was made with a package list featuring "top" and "top.bar", but\n    not "top.not_a_subpackage".\n\n    ::\n\n        top/                -> top/\n          __init__.py       -> top/__init__.py                 (parent: top)\n          foo.py            -> top/foo.py                      (parent: top)\n          bar/              -> top/bar/                        (parent: top)\n            __init__.py     -> top/bar/__init__.py             (parent: top.bar)\n\n          not_a_subpackage/ -> top/not_a_subpackage/           (parent: top)\n            data_0.txt      -> top/not_a_subpackage/data_0.txt (parent: top)\n            data_1.txt      -> top/not_a_subpackage/data_1.txt (parent: top)\n\n    The paths in the generated install manifest are matched to packages\n    according to the parents indicated on the right.  Only packages that are\n    specified in the setup() call are considered.  Because of the sort order,\n    the data files on the bottom would have been mapped to\n    "top.not_a_subpackage" instead of "top", proper -- had such a package been\n    specified.\n    '
    return list(sorted(((package_dir[package].replace('.', '/'), package) for package in packages), key=(lambda tup: len(tup[0])), reverse=True))