]> granicus.if.org Git - python/commitdiff
site: error on sitecustomize import error
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 22 Jan 2016 11:22:07 +0000 (12:22 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 22 Jan 2016 11:22:07 +0000 (12:22 +0100)
Issue #26099: The site module now writes an error into stderr if sitecustomize
module can be imported but executing the module raise an ImportError. Same
change for usercustomize.

Lib/site.py
Misc/NEWS

index 3a8d1c3728379435adcd942a7bf9eaa27498e597..13ec8fa43f85c38619bcb107e70c5bc95134f605 100644 (file)
@@ -504,9 +504,13 @@ def venv(known_paths):
 def execsitecustomize():
     """Run custom site specific code, if available."""
     try:
-        import sitecustomize
-    except ImportError:
-        pass
+        try:
+            import sitecustomize
+        except ImportError as exc:
+            if exc.name == 'sitecustomize':
+                pass
+            else:
+                raise
     except Exception as err:
         if os.environ.get("PYTHONVERBOSE"):
             sys.excepthook(*sys.exc_info())
@@ -520,9 +524,13 @@ def execsitecustomize():
 def execusercustomize():
     """Run custom user specific code, if available."""
     try:
-        import usercustomize
-    except ImportError:
-        pass
+        try:
+            import usercustomize
+        except ImportError as exc:
+            if exc.name == 'usercustomize':
+                pass
+            else:
+                raise
     except Exception as err:
         if os.environ.get("PYTHONVERBOSE"):
             sys.excepthook(*sys.exc_info())
index 01e933c460335e75dcf1db26a829701ea6f9a995..4e3cc96f548eaf267d90ce08573c259f6f418257 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -146,6 +146,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #26099: The site module now writes an error into stderr if
+  sitecustomize module can be imported but executing the module raise an
+  ImportError. Same change for usercustomize.
+
 - Issue #26147: xmlrpc now works with strings not encodable with used
   non-UTF-8 encoding.