Repository: meejah/txtorcon
Issue: using deprecated `launch_tor` causes failure via Incremental

My local magic-wormhole tests are currently failing, because magic-wormhole still uses `launch_tor`, and the `@deprecated()` decorator around `launch_tor` causes Incremental to look for `.git/refs/heads/master`, and that file doesn't exist in my checkout (I did a `git gc`, which seems to have compressed everything into `.git/packed-refs`).

Using a deprecated function from a git-gc'ed source tree is probably rare enough that nobody else has run into this problem so far. I've filed https://github.com/hawkowl/incremental/issues/31 to fix it upstream, and for now I'm going to prioritize moving from `launch_tor` to the modern `launch`, but I'll file this just in case someone else sees this exception and is wondering why.

The full message (using Twisted-17.1.0, Incremental-16.10.1, and txtorcon-0.19.1) is:
```
[ERROR]
Traceback (most recent call last):
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/trial/runner.py", line 602, in loadByNames
    things.append(self.findByName(name))
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/trial/runner.py", line 406, in findByName
    return reflect.namedAny(name)
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/python/reflect.py", line 301, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/python/reflect.py", line 240, in _importAndCheckStack
    return __import__(importName)
  File "/home/warner/stuff/tahoe/magic-wormhole/src/wormhole/test/test_tor_manager.py", line 8, in <module>
    from ..tor_manager import TorManager, DEFAULT_VALUE
  File "/home/warner/stuff/tahoe/magic-wormhole/src/wormhole/tor_manager.py", line 9, in <module>
    from txtorcon import (TorConfig, launch_tor, build_tor_connection,
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/txtorcon/__init__.py", line 16, in <module>
    from txtorcon.controller import connect
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/txtorcon/controller.py", line 34, in <module>
    from txtorcon.torconfig import TorConfig
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/txtorcon/torconfig.py", line 34, in <module>
    stdout=None, stderr=None):
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/python/deprecate.py", line 293, in deprecationDecorator
    function, version, None, replacement)
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/python/deprecate.py", line 238, in getDeprecationWarningString
    _fullyQualifiedName(callableThing), version, format, replacement)
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/twisted/python/deprecate.py", line 198, in _getDeprecationWarningString
    'version': getVersionString(version)}
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/incremental/__init__.py", line 518, in getVersionString
    result = '%s %s' % (version.package, version.short())
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/incremental/__init__.py", line 221, in short
    gitver = self._getGitVersion()
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/incremental/__init__.py", line 422, in _getGitVersion
    return self._parseGitDir(os.path.join(upOneMore, '.git'))
  File "/home/warner/stuff/tahoe/magic-wormhole/ve/local/lib/python2.7/site-packages/incremental/__init__.py", line 395, in _parseGitDir
    headContent.split(" ")[1]))) as f:
exceptions.IOError: [Errno 2] No such file or directory: '/home/warner/stuff/tahoe/magic-wormhole/.git/refs/heads/master'

wormhole.test.test_tor_manager
```


Changed files:
txtorcon/torconfig.py

diff --git a/txtorcon/torconfig.py b/txtorcon/torconfig.py
index 2fc3f76..28228c4 100644
--- a/txtorcon/torconfig.py
+++ b/txtorcon/torconfig.py
@@ -12,7 +12,6 @@ import warnings
 from io import StringIO
 from collections import OrderedDict
 
-from incremental import Version
 from twisted.python import log
 from twisted.python.deprecate import deprecated
 from twisted.internet import defer
@@ -24,8 +23,28 @@ from txtorcon.interface import ITorControlProtocol
 from txtorcon.util import find_keywords
 
 
+class _Version(object):
+    """
+    Replacement for incremental.Version until
+    https://github.com/meejah/txtorcon/issues/233 and/or
+    https://github.com/hawkowl/incremental/issues/31 is fixed.
+    """
+    # as of latest incremental, it should only access .package and
+    # .short() via the getVersionString() method that Twisted's
+    # deprecated() uses...
+
+    def __init__(self, package, major, minor, patch):
+        self.package = package
+        self.major = major
+        self.minor = minor
+        self.patch = patch
+
+    def short(self):
+        return '{}.{}.{}'.format(self.major, self.minor, self.patch)
+
+
 @defer.inlineCallbacks
-@deprecated(Version("txtorcon", 0, 18, 0))
+@deprecated(_Version("txtorcon", 0, 18, 0))
 def launch_tor(config, reactor,
                tor_binary=None,
                progress_updates=None,