[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Resolving circular dependency with server_descriptor



commit c91532362bd04d90c35adab22d497ba09ee7cc64
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Mar 23 20:23:57 2012 -0700

    Resolving circular dependency with server_descriptor
    
    ... damn this was a pita to debug. A long explanation of the issue is:
    http://stackoverflow.com/questions/8991520/python-conditional-module-object-has-no-attribute-error- with-personal-package
    
    Short story is that the stem.descriptor module imported server_descriptor prior
    to being fully initialized which caused a server_descriptor use of
    stem.descriptor.Descriptor to fail.
    
    The confusing was that it was actually reporting failure in using
    "stem.descriptor" (the module itself) which made no sense because it was listed
    within sys.modules. It turns out that the python importer uses module
    attributes rather than sys.modules mappings to resolve statements (ie, it was
    doing getattr(stem, "descriptor")). However, a module's added as an attribute
    of its parent when its *finished* importing.
    
    This fixes the unit tests, but integ tests are still getting stuck when they
    use the new server_descriptor parsing.
---
 stem/descriptor/__init__.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 7b05963..4d44bc0 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -6,8 +6,6 @@ __all__ = ["descriptor", "reader", "server_descriptor", "parse_descriptors", "De
 
 import os
 
-import stem.descriptor.server_descriptor
-
 def parse_descriptors(path, descriptor_file):
   """
   Provides an iterator for the descriptors within a given file.
@@ -24,6 +22,8 @@ def parse_descriptors(path, descriptor_file):
     IOError if unable to read from the descriptor_file
   """
   
+  import stem.descriptor.server_descriptor
+  
   # The tor descriptor specifications do not provide a reliable method for
   # identifying a descriptor file's type and version so we need to guess
   # based on its filename for resources from the data directory and contents



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits