[Checkins] SVN: Sandbox/janwijbrand/importchecker/trunk/ run import checker on individual python modules not just directories/packages

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Jan 9 11:13:04 UTC 2012


Log message for revision 123992:
  run import checker on individual python modules not just directories/packages

Changed:
  U   Sandbox/janwijbrand/importchecker/trunk/CHANGES.txt
  U   Sandbox/janwijbrand/importchecker/trunk/README.txt
  U   Sandbox/janwijbrand/importchecker/trunk/src/importchecker/importchecker.py

-=-
Modified: Sandbox/janwijbrand/importchecker/trunk/CHANGES.txt
===================================================================
--- Sandbox/janwijbrand/importchecker/trunk/CHANGES.txt	2012-01-08 16:36:53 UTC (rev 123991)
+++ Sandbox/janwijbrand/importchecker/trunk/CHANGES.txt	2012-01-09 11:13:03 UTC (rev 123992)
@@ -4,6 +4,9 @@
 1.1 (unreleased)
 ----------------
 
+* Applied provided by wosc enabling running the import checker on
+  individual python modules not just directories.
+
 * Report the absolute path for modules when needed, relative paths (relative
   to the current working directory, that is) when possible.
 

Modified: Sandbox/janwijbrand/importchecker/trunk/README.txt
===================================================================
--- Sandbox/janwijbrand/importchecker/trunk/README.txt	2012-01-08 16:36:53 UTC (rev 123991)
+++ Sandbox/janwijbrand/importchecker/trunk/README.txt	2012-01-09 11:13:03 UTC (rev 123992)
@@ -22,9 +22,10 @@
 
   $ sudo easy_install importchecker
 
-The command can then be invoked with::
+The command can then be invoked with either a directory or a Python file::
 
   $ importchecker /path/to/a/source/tree
+  $ importchecker /path/to/a/source/tree/module.py
 
 Buildout
 --------

Modified: Sandbox/janwijbrand/importchecker/trunk/src/importchecker/importchecker.py
===================================================================
--- Sandbox/janwijbrand/importchecker/trunk/src/importchecker/importchecker.py	2012-01-08 16:36:53 UTC (rev 123991)
+++ Sandbox/janwijbrand/importchecker/trunk/src/importchecker/importchecker.py	2012-01-09 11:13:03 UTC (rev 123992)
@@ -300,13 +300,16 @@
         print "No path supplied"
         sys.exit(1)
 
-    path = os.path.abspath(path)
-    if not os.path.isdir(path):
-        print "Unknown path:", path
-        sys.exit(1)
+    fullpath = os.path.abspath(path)
+    path = fullpath
+    if not os.path.isdir(fullpath):
+        path = os.path.dirname(fullpath)
 
     db = ImportDatabase(path)
-    db.findModules()
+    if os.path.isdir(fullpath):
+        db.findModules()
+    else:
+        db.addModule(Module(fullpath))
     unused_imports = db.getUnusedImports()
     module_paths = unused_imports.keys()
     module_paths.sort()



More information about the checkins mailing list