comparison mercurial/ui.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 82910fdc216f
children 2916ebaef312
comparison
equal deleted inserted replaced
27274:82910fdc216f 27275:f2cd240f2f7c
1058 curframe = inspect.currentframe() 1058 curframe = inspect.currentframe()
1059 calframe = inspect.getouterframes(curframe, 2) 1059 calframe = inspect.getouterframes(curframe, 2)
1060 self.write_err('%s at: %s:%s (%s)\n' 1060 self.write_err('%s at: %s:%s (%s)\n'
1061 % ((msg,) + calframe[stacklevel][1:4])) 1061 % ((msg,) + calframe[stacklevel][1:4]))
1062 1062
1063 def deprecwarn(self, msg, version):
1064 """issue a deprecation warning
1065
1066 - msg: message explaining what is deprecated and how to upgrade,
1067 - version: last version where the API will be supported,
1068 """
1069 msg += ("\n(compatibility will be dropped after Mercurial-%s,"
1070 " update your code.)") % version
1071 self.develwarn(msg, stacklevel=2)
1072
1063 class paths(dict): 1073 class paths(dict):
1064 """Represents a collection of paths and their configs. 1074 """Represents a collection of paths and their configs.
1065 1075
1066 Data is initially derived from ui instances and the config files they have 1076 Data is initially derived from ui instances and the config files they have
1067 loaded. 1077 loaded.