Rjak
Rjak

Reputation: 2187

How do you determine the current Python egg cache directory?

I'm aware that you can override the egg cache directory with the environment variable PYTHON_EGG_CACHE, and that you can look that override up in os.envrion. It looks like the default for Python 2.7 on Ubuntu 16 is /.cache/Python-Eggs.

How would you log the location of the egg cache when there is no PYTHON_EGG_CACHE provided in the environment?

Upvotes: 0

Views: 506

Answers (1)

engenious
engenious

Reputation: 26

The PYTHON_EGG_CACHE envvar is used by setuptools to determine the location to store installed egg packages. (You can read more about setuptools here)

Taking a look through the current code for setuptools on github (In the function currently named get_default_cache) shows that if the lookup of the envvar fails, a default is calculated using the following:

from pkg_resources.extern import appdirs

return (
    os.environ.get('PYTHON_EGG_CACHE')
    or appdirs.user_cache_dir(appname='Python-Eggs')
)

appdirs is a pretty simple python lib that gets standard file system locations. the user_cache_dir logic depends on your OS, and has quite a few conditionals (Far too much to explain here, but if you are interested, the logic is on github)

Since you mentioned U16 - the logic there is:

  • Look up another envvar (XDG_CACHE_HOME), and then append /Python-Eggs (For example, if XDG_CACHE_HOME is /tmp/xdg/ then the /tmp/xdg/Python-Eggs is used)
  • If the second envvar is not defined, then ~/.cache/Python-Eggs is used.

Upvotes: 1

Related Questions