[Distutils] 2.6 replacement for sysconfig.get_paths(scheme)[path]?

Sridhar Ratnakumar sridharr at activestate.com
Thu May 20 18:34:10 CEST 2010


Python 2.7 introduced the `sysconfig` module which has a function `get_paths` that returns the fully variable substituted path for the given scheme. This doesn't seem like possible on 2.6 using `distutils.sysconfig` - as variable substitution is done deep in a class method, and not exposed as a public API. At the moment I am writing code like this:

            scheme = 'nt' sys.platform == 'win32' else 'unix'
            scheme += ('_user' if usersite else (
                '_prefix' if scheme == 'unix' else ''))

            template = INSTALL_SCHEMES[scheme][path]

            # hardcoded template substitution (distutils API does not provide
            # this)
            template = template.replace('$base', base_dir)
            template = template.replace('$py_version_short', pyver)
            if '$user' in template:
                template = template.replace('$usersite', site.USER_SITE)
                template = template.replace('$userbase', site.USER_BASE)
            assert '$' not in template, \
                    'Unsubstituded variables left in "%s"' % template
            return template

Can this be simplified?

-srid



More information about the Distutils-SIG mailing list