Python packages and egg-info directories
Asked Answered
S

1

88

Can someone explain how egg-info directories are tied to their respective modules? For example, I have the following:

/usr/local/lib/python2.5/site-packages/quodlibet/
/usr/local/lib/python2.5/site-packages/quodlibet-2.0.egg-info/

I'm assuming the egg-info directory is to make the corresponding module visible to setuptools (easy_install), right? If so, how does setuptools tie the egg-info directory to the module directory?

Assuming that I'm on the right track, and for the sake of example... If I wanted to make an existing package of mine visible to setuptools, could I just symlink the module directory and the egg-info directory to the site-packages directory? I would have just tried this myself, but I'm not sure how to test if the package is visible to setuptools. Bonus points if you can also tell me how to test this :)

The main reason I'm trying to understand all this is because I would like to symlink some of my modules into site-packages so that I can make changes to them and have the changes visible to the scripts that use them without having to reinstall the egg from PyPI after each change.

Sunglass answered 2/11, 2008 at 2:26 Comment(2)
Do you still have a quodlibet plugin for python hanging around somewhere? That sounds really cool.Pleasantry
@PeterTurner That's probably quodlibet itself -- it's written in PythonYukikoyukio
C
76

The .egg-info directories get only created if --single-version-externally-managed was used to install the egg. "Normally", installing an egg would create a single directory (or zip file), containing both the code and the metadata.

pkg_resources (which is the library that reads the metadata) has a function require which can be used to request a specific version of the package. For "old-style", regular imports, easy_install hacks a .pth file to get the egg directory onto sys.path. For --single-version-externally-managed, this hacking is not necessary, because there will only be a single version installed (by the system's pacakging infrastructure, e.g. rpm or dpkg). The egg-info is still included, for applications that use require (or any of the other pkg_resources binding mechanisms).

If you want to install a package by hard-linking, I recommend to use "setup.py develop". This is a command from setuptools which doesn't actually install the egg, but makes it available site-wide. To do so, it creates an egg-link file so that pkg_resources can find it, and it manipulates a .pth file, so that regular import can find it.

Coridon answered 2/11, 2008 at 6:40 Comment(2)
To reverse the effects of setup.py develop, use setup.py develop -uGriseous
Note, that it's a lower-case -u. Upper-case -U does something else.Fragment

© 2022 - 2024 — McMap. All rights reserved.