Determining top-level import package names programmatically

Yeah; as I mention in my reply above:

Sorry I was unclear; your comment I was originally responding to was referring to Setuptools setup.py dynamic build scripts in sdists, in which the Setuptools-specific location for metadata is under the .egg-info directory. As mentioned, top_level.txt is indeed under .dist-info for wheels and in installed projects, just not backend-specific sdists.

Right, though as mentioned for wheels you can determine the top-level import names from the RECORD as well as from the ZIP contents with a bit of light filtering (for .pth files and .dist-info directories, and possibly looking at .data to resolve any purelib/platlib complexities), and my comment here was specifically in the context of checking a setup.py in a sdist, which is only relevant for Setuptools ofc.

As mentioned, there’s a recent discussion about that

It’s a holdover from Setuptools’ legacy Egg binary distribution format:

This data is used by pkg_resources at runtime to issue a warning if an egg is added to sys.path when its contained packages may have already been imported.

(It was also once used to detect conflicts with non-egg packages at installation time, but in more recent versions, setuptools installs eggs in such a way that they always override non-egg packages, thus preventing a problem from arising.)

1 Like