Rune Halvorsen avatar Rune Halvorsen committed f71867c

Added handing of __name__=="__main__". This should fix #1

Comments (0)

Files changed (1)

     raise ImportError("No module named: %s" % modname)
 
 
-for modspec in _modules:
-    try:
-        implementation = _JsonImplementation(modspec)
-        break
-    except ImportError:
-        pass
+
+def main():
+    installed = []
+    for modspec in _modules:
+        try:
+            __import__(modspec[0])
+            installed.append(modspec[0])
+        except ImportError:
+            pass
+
+    if installed:
+        print "Supported JSON modules found:", ", ".join(installed)
+        return 0
+    else:
+        print "No supported JSON modules found"
+        return 1
+
+if __name__ == "__main__":
+    # If run as a script, we simply print what is installed that we support.
+    # We do NOT try to load a compatible module because that may throw an
+    # exception, which renders the package uninstallable with easy_install
+    # (It trys to execfile the script when installing, to make sure it works)
+    sys.exit(main())
 else:
-    raise ImportError("No supported JSON module found")
+    for modspec in _modules:
+        try:
+            implementation = _JsonImplementation(modspec)
+            break
+        except ImportError:
+            pass
+        else:
+            raise ImportError("No supported JSON module found")
 
-serialize = lambda value: implementation.serialize(value)
-deserialize = lambda value: implementation.deserialize(value)
+        serialize = lambda value: implementation.serialize(value)
+        deserialize = lambda value: implementation.deserialize(value)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.