view mercurial/scmposix.py @ 27275:f2cd240f2f7c

ui: add a 'deprecwarn' helper to issue deprecation warnings As discussed on the list, we are adding an official way to keep old API around for a short time in order to help third party developer to catch up. The deprecated API will issue developer warning (issued by default during test runs) to warn extensions authors that they need to upgrade their code without instantaneously breaking tool chains and normal users. The version is passed as an explicit argument so that developer think about it and a potential future script can automatically check for it. This is not build as a decorator because accessing the 'ui' instance will likely be different each time. The message is also free form because deprecated API are replaced in a variety of ways. I'm not super happy about the final rendering of that message, but this is a developer oriented warning and I would like to move forward.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 05 Dec 2015 23:05:49 -0800
parents 23c995ed466b
children 39087ee88835
line wrap: on
line source

import sys, os
import osutil

def _rcfiles(path):
    rcs = [os.path.join(path, 'hgrc')]
    rcdir = os.path.join(path, 'hgrc.d')
    try:
        rcs.extend([os.path.join(rcdir, f)
                    for f, kind in osutil.listdir(rcdir)
                    if f.endswith(".rc")])
    except OSError:
        pass
    return rcs

def systemrcpath():
    path = []
    if sys.platform == 'plan9':
        root = 'lib/mercurial'
    else:
        root = 'etc/mercurial'
    # old mod_python does not set sys.argv
    if len(getattr(sys, 'argv', [])) > 0:
        p = os.path.dirname(os.path.dirname(sys.argv[0]))
        if p != '/':
            path.extend(_rcfiles(os.path.join(p, root)))
    path.extend(_rcfiles('/' + root))
    return path

def userrcpath():
    if sys.platform == 'plan9':
        return [os.environ['home'] + '/lib/hgrc']
    else:
        return [os.path.expanduser('~/.hgrc')]