<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hello!<br>
<br>
During "slave"->"worker" transition in bug 2340 names such as
<meta http-equiv="content-type" content="text/html; charset=utf-8">
buildbot.locks.SlaveLock <br>
will be renamed to "worker"-based names, e.g.
buildbot.locks.WorkerLock.<br>
For some classes fallback will be provided, e.g.
buildbot.locks.SlaveLock will still <br>
be available in 0.9.0, however it's use will emit deprecation
warning.<br>
<br>
My initial fallback implementation idea (that I expressed in PR
#1943 [1]) <br>
were based on an opinion, that Python module replacement in
sys.modules is a terrible hack<br>
and should be avoided at all costs.<br>
<br>
So to add fallback for buildbot.locks.SlaveLock I added dummy class
via wrapper<br>
that were named SlaveLock, inherited from WorkerLock and has
overriden __new__<br>
to emitted warning, when SlaveLock is *instantiated*.<br>
Effectively:<br>
<br>
class WorkerLock:<br>
...<br>
<br>
class SlaveLock(WorkerLock):<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
def __new__(cls, *args, **kwargs):<br>
# Raise warning here<br>
return cls.__new__(instance_cls)<br>
<br>
<br>
To add fallback for a function I added dummy function that emitted
warning<br>
*when called* and forwarded all arguments to the wrapped function.<br>
Effectively:<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<br>
def enforceChosenWorker(bldr, workerforbuilder, breq):<br>
...<br>
<br>
def enforceChosenSlave(*args, **kwargs):<br>
# Raise warning here<br>
return enforceChosenWorker(*args, **kwargs)<br>
<br>
Recently I noticed that Twisted already has helper for deprecating
module attributes [2]: <br>
deprecatedModuleAttributes().<br>
Twisted does it by replacing module in sys.modules with custom proxy
object that<br>
emits warnings when deprecated attribute is accessed.<br>
<br>
I want to refactor my fallback helpers to use Twisted's approach (I
will to use <br>
deprecatedModuleAttributes in my wrappers) and interested in other
developers<br>
opinions regarding Twisted's approach.<br>
<br>
Pros of using module proxy:<br>
<br>
1. Function or class *access* will raise warning. <br>
This is the only option to raise warnings in some cases, e.g. in
case if user catches <br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
BuildSlaveTooOldError in his code (that class is never instantiated
in user code).<br>
<br>
Cons of using module proxy:<br>
<br>
1. It's a hack that may lead to unexpected behaviour.<br>
If Twisted developers uses it I want to believe that this is not so
terrible hack, <br>
but at least cctrial has some issues on such modules [3]<br>
(module proxy can not be reloaded).<br>
<br>
2. It may make run code slower (insignificantly, IMO).<br>
<br>
3. It doesn't scale. If anyone else will decide to replace module
with it's own <br>
wrapper it may result in a conflict.<br>
<br>
4. It will emit warnings if star imports are used, even if no
"slave"-named objects<br>
are actually used (e.g. `from buildbot.interfaces import *` will
emit warning).<br>
<br>
Which implementation is more preferable?<br>
<br>
I like module replacement approach, but afraid of star imports in
the client code<br>
(star import from buildbot.plugins *will* work properly without
warnings with my <br>
current implementation of fallback in plugins, but not from other
modules).<br>
<br>
Switch implementation it's not a problem (API of my helpers will not
change, <br>
only their implementation).<br>
<br>
[1] <a class="moz-txt-link-freetext" href="https://github.com/buildbot/buildbot/pull/1943">https://github.com/buildbot/buildbot/pull/1943</a><br>
[2]
<a class="moz-txt-link-freetext" href="https://twistedmatrix.com/documents/9.0.0/api/twisted.python.deprecate.html">https://twistedmatrix.com/documents/9.0.0/api/twisted.python.deprecate.html</a><br>
[3] <a class="moz-txt-link-freetext" href="https://github.com/tardyp/cctrial/issues/4">https://github.com/tardyp/cctrial/issues/4</a><br>
<br>
<br>
Regards,<br>
<br>
Vladimir Rutsky<br>
<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</body>
</html>