Can/should you use the system timezone files?

Asked by Danek Duvall

Most systems ship a set of zoneinfo files already. Is there a reason that pytz bundles its own copy? It'd be nice to have a single, canonical copy of the database on any given system, so that all programs have the same notion time. Splitting the database out would imply a different versioning scheme, of course -- one for the database, one for the code -- but that almost seems like a win.

Question information

Language:
English Edit question
Status:
Answered
For:
pytz Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Stuart Bishop (stub) said :
#1

pytz bundles its own copy of the zoneinfo files for systems that don't have them (primarily Windows).

pytz does support using the system zoneinfo database. The mechanism is a bit of a kludge, but has been good enough for at least the Debian and Ubuntu packages to be done this way. Generally, systems with a maintained zoneinfo database also have a mechanism for installing pytz as a package so there is no need to install pytz from the tarball.

Do use the system zoneinfo database, you either need to replace the 'zoneinfo' directory with a symlink to the system zoneinfo directory, or alter the open_resource() function in pytz/__init__.py

def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    # Patched in Debian, use the system zoneinfo from the tzdata package
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join('/usr/share/zoneinfo', *name_parts)
    return open(filename, 'rb')

Can you help with this problem?

Provide an answer of your own, or ask Danek Duvall for more information if necessary.

To post a message you must log in.