[Python-Dev] Fixing #7175: a standard location for Python config files

Éric Araujo merwok at netwok.org
Thu Aug 12 04:56:02 CEST 2010


> I'd like to see a more complete proposal, including:
Fair enough.

tl;dr: Locating config files is hard.

I have looked at http://github.com/ActiveState/appdirs (MIT) for
OS-specific bits of knowledge. (Note that the directories it uses for
free OSes are not compliant with the freedesktop.org Base Directory
specification, which already did the reflexion and code to separate
config, user data and cache.)

> - what to do with Windows,
appdirs uses pywin32 or ctypes or _winreg to find the correct value for
the user settings directory. There is a new complication in recent
Windows called roaming profiles, which are copied from a server to
multiple clients and need synchronization calls.

> Mac OS X
There is debate between Ned Deily, Ronald Oussoren and Glyph Lefkowitz
as to whether Mac OS is just a Unix or a special beast. appdirs chooses
the Mac-specific directory. There are also probably variations between
system installations, framework things and unix-style installations.

> - backward compatibility considered
>   (seems straightforward, but seemings are often wrong)
Are you talking about finding config from older locations, or automatic
renaming of ~/.idlerc to ~/.python/idlerc? The former seems easy; not
sure how to do the latter. Gajim, a PyGTK Jabber client, moved from a
custom layout to BaseDir-compliant directories a few months ago; I think
it looks for the old directories on every startup to see if they need to
be moved. I’m not sure if this affects startup time noticeably, since
it’s after all a graphical network Python app, but it may be a concern
with programs that are run a lot like the unittest2 script (or not,
considering startup time of the interpreter).

> - cross-platform API to locate these files
I was thinking about adding a function to site with this tentative
signature:

def getuserconfig(appname=''):
    """Return the configuration file name for `appname`.

    If `appname` is the empty string, return the directory used for
    Python configuration files, else returns the file name used for the
    configuration file of `appname` (a PyPI project name).

    Strings starting with a number ('3.2') are reserved by Python.
    """

I’m not sure the x.y subdirectory is necessary. distutils config files
are compatible since forever and will still be compatible with
distutils2; config files in unittest2 are very recent, they could have a
policy of compatiblity too; I can investigate IDLE config format.

A boolean could control whether to return filenames using the old
conventions. On Windows, this would need application name and
author/vendor name (settings are grouped by author). On Mac, the
application would have to say whether it uses a unix-style dotfile or a
Mac-style directory. Also, capitalization differs across OSes. Can of
worms here.

> Seems like a good idea to have a "registry" of files known to be placed there
The project name registration on PyPI may be enough to avoid duplicates.


Next steps:

1) Find out if winreg is reliable enough, since we don’t want to depend
on ctypes or pywin32 IIRC.

2) Have the Mac people come to an agreement for each type of install.

3) Prototype the new function. It’s probably a good idea to contact the
author of appdirs and work with him on a Python-specific subset of his
module instead of rewriting the same code.

4) Think about the best way to handle b/w compat. Timings could help
deciding for or against automatic renaming.


Thanks for the feedback.



More information about the Python-Dev mailing list