meejah / txtorcon

Twisted-based asynchronous Tor control protocol implementation. Includes unit-tests, examples, state-tracking code and configuration abstraction.
http://fjblvrw2jrxnhtg67qpbzi45r7ofojaoo3orzykesly2j3c2m3htapid.onion/
MIT License
250 stars 72 forks source link

using deprecated `launch_tor` causes failure via Incremental #233

Closed warner closed 7 years ago

warner commented 7 years ago

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
meejah commented 7 years ago

Hmm, interesting. It is odd that trying to make a new, specific Version instance (which is what the Twisted API demands) does anything at all to disc :/

meejah commented 7 years ago

So getVersionString calls Version.short() which looks for SCM stuff so it can tack on +rdeadbeef or similar.

Twisted could fix/change this by calling version.public() instead of getVersionString. Arguably, that might make more sense since it's for error-messages and docstrings ...

warner commented 7 years ago

BTW I originally thought I could work around this by not using the deprecated launch_tor API, but now I think the problem happens when txtorcon is imported. So switching to the new API won't help. My current workaround is to modify master (e.g. changing it and then reverting right away), which causes a separate refs/heads/master to be written out, and then refraining from running git-gc.

meejah commented 7 years ago

I think I have a fix for txtorcon until incremental and/or twisted changes...

meejah commented 7 years ago

@warner this is in 0.19.2, just released