[kupfer: 3/12] Leave no visible names after kupfer.plugin setup code



commit 4e4d1cb6fb70ec236626d733c54ace3c9130ea9f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Feb 8 22:46:57 2010 +0100

    Leave no visible names after kupfer.plugin setup code

 kupfer/plugin/__init__.py |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/kupfer/plugin/__init__.py b/kupfer/plugin/__init__.py
index da24234..efa5fdd 100644
--- a/kupfer/plugin/__init__.py
+++ b/kupfer/plugin/__init__.py
@@ -1,19 +1,24 @@
-import os
 
-from kupfer import config
-from kupfer import pretty
+def _extend_path():
+	# Inside a function to not leak variables to module namespace
+	import os
+	from kupfer import config
+	from kupfer import pretty
 
-# Add plugins in data directories
-__path__.extend(config.get_data_dirs("plugins"))
+	# Add plugins in data directories
+	__path__.extend(config.get_data_dirs("plugins"))
+
+	# Add .zip files in plugins directories
+	for directory in list(__path__):
+		try:
+			filenames = os.listdir(directory)
+		except OSError, error:
+			pretty.print_error(__name__, error)
+			continue
+		zipnames = [f for f in filenames if f.endswith(".zip")]
+		if zipnames:
+			pretty.print_debug(__name__, "Adding", directory, zipnames)
+		__path__.extend(os.path.join(directory, z) for z in zipnames)
+
+_extend_path()
 
-# Add .zip files in plugins directories
-for directory in list(__path__):
-	try:
-		filenames = os.listdir(directory)
-	except OSError, err:
-		pretty.print_error(__name__, err)
-		continue
-	zipnames = [f for f in filenames if f.endswith(".zip")]
-	if zipnames:
-		pretty.print_debug(__name__, "Adding", directory, zipnames)
-	__path__.extend(os.path.join(directory, z) for z in zipnames)



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