6

Background

From The Internal Structure of Python Eggs (hosted by python.org), I learned that there's a file called top_level.txt that is installed alongside Python eggs that says what top-level modules or packages are installed.

packaging.python.org does not list top_level.txt as a file that is to be created and added to dist-info. However when I manually inspect dependencies inside of site-packages, I haven't run across a case yet where that file doesn't exist.

Question

In short, where and when is this file created?

I've observed that it always seems to exist when I install a package (either in .egg-info or .dist-info), but is this a pattern I can expect to generally be the case?

NickS1
  • 496
  • 1
  • 6
  • 19
wheresmycookie
  • 683
  • 3
  • 16
  • 39

1 Answers1

3

this file is not always present but is added by setuptools during the egg-info phase

https://github.com/pypa/setuptools/blob/0d4d5565b1d9557f0b434adc87a0415abd2a5cc9/setuptools/command/egg_info.py#L707-L714

def write_toplevel_names(cmd, basename, filename):
    pkgs = dict.fromkeys(
        [
            k.split('.', 1)[0]
            for k in cmd.distribution.iter_distribution_names()
        ]
    )
    cmd.write_file("top-level names", filename, '\n'.join(sorted(pkgs)) + '\n')

here's an example of a wheel which does not contain one: https://pypi.org/project/distlib/0.3.4/

(the actual wheel file from pypi)

https://files.pythonhosted.org/packages/ac/a3/8ee4f54d5f12e16eeeda6b7df3dfdbda24e6cc572c86ff959a4ce110391b/distlib-0.3.4-py2.py3-none-any.whl

anthony sottile
  • 61,815
  • 15
  • 148
  • 207