jenkins-bot has submitted this change and it was merged.

Change subject: Do not remove imported packages
......................................................................


Do not remove imported packages

Imported modules were hidden in 2009, as part of a large cleanup of the
symbols exported by config.py
https://mediawiki.org/wiki/Special:Code/pywikipedia/4285

While there is benefit in hiding symbols not intended to be public,
hiding the imported modules is not beneficial as it is unlikely that
any config value will be of type module, so they can be differentiated,
and indeed they were already skipped in 'list of config options' code.
https://mediawiki.org/wiki/Special:Code/pywikipedia/4887

The removal of symbols __sys and os currently cause pyflakes error F821.
While this isnt a functional problem, it does prevent reflection and
inspection of the loaded python code, and is unecessary.

Also moved platform import into the only code block that uses it,
meaning it wont be loaded on many systems.

Also removed 're' import, as it was unused.

Change-Id: I783fba623a2825af3273ecad286d47e897c2a674
---
M pywikibot/config2.py
1 file changed, 15 insertions(+), 20 deletions(-)

Approvals:
  Merlijn van Deen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 6cca983..37579ad 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -9,9 +9,7 @@
 #
 
 import os
-import sys as __sys
-import re
-import platform
+import sys
 
 # IMPORTANT:
 # Do not change any of the variables in this file. Instead, make
@@ -121,18 +119,19 @@
 
     """
     NAME = "pywikibot"
-    for arg in __sys.argv[1:]:
+    for arg in sys.argv[1:]:
         if arg.startswith("-dir:"):
             base_dir = arg[5:]
-            __sys.argv.remove(arg)
+            sys.argv.remove(arg)
             break
     else:
         if "PYWIKIBOT2_DIR" in os.environ:
             base_dir = os.environ["PYWIKIBOT2_DIR"]
         else:
-            is_windows = __sys.platform == 'win32'
+            is_windows = sys.platform == 'win32'
             home = os.path.expanduser("~")
             if is_windows:
+                import platform
                 _win_version = int(platform.version()[0])
                 if _win_version == 5:
                     base_dir = os.path.join(home, "Application Data", NAME)
@@ -194,7 +193,7 @@
 # This default code should work fine, so you don't have to think about it.
 # TODO: consider getting rid of this config variable.
 try:
-    console_encoding = __sys.stdout.encoding
+    console_encoding = sys.stdout.encoding
 except:
     # When using pywikibot inside a daemonized twisted application,
     # we get "StdioOnnaStick instance has no attribute 'encoding'"
@@ -250,7 +249,7 @@
 # ANSI colors.
 try:
     # Don't print colorized when the output is, for example, piped to a file.
-    colorized_output = __sys.stdout.isatty()
+    colorized_output = sys.stdout.isatty()
 except:
     colorized_output = False
 
@@ -258,7 +257,7 @@
 # The command for the editor you want to use. If set to None, a simple Tkinter
 # editor will be used.
 # On Windows systems, this script tries to determine the default text editor.
-if __sys.platform == 'win32':
+if sys.platform == 'win32':
     try:
         import _winreg
         _key1 = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
@@ -643,7 +642,6 @@
     from [email protected] 2002/03/18
 
     """
-    import os
     dpath = os.path.normpath(os.path.dirname(path))
     if not os.path.exists(dpath):
         os.makedirs(dpath)
@@ -658,13 +656,11 @@
     directories in the path that do not already exist are created.
 
     """
-    import os.path
     return makepath(os.path.join(base_dir, *filename))
 
 
 def shortpath(path):
     """Return a file path relative to config.base_dir."""
-    import os.path
     if path.startswith(base_dir):
         return path[len(base_dir) + len(os.path.sep):]
     return path
@@ -687,8 +683,8 @@
         _filestatus = os.stat(_filename)
         _filemode = _filestatus[0]
         _fileuid = _filestatus[4]
-        if __sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
-            if __sys.platform == 'win32' or _filemode & 0o02 == 0 or True:
+        if sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
+            if sys.platform == 'win32' or _filemode & 0o02 == 0 or True:
                 exec(compile(open(_filename).read(), _filename, 'exec'))
             else:
                 print("WARNING: Skipped '%(fn)s': writeable by others."
@@ -724,14 +720,14 @@
 
 # Fix up default console_encoding
 if console_encoding is None:
-    if __sys.platform == 'win32':
+    if sys.platform == 'win32':
         console_encoding = 'cp850'
     else:
         console_encoding = 'iso-8859-1'
 
 # Fix up transliteration_target
 if transliteration_target == 'not set':
-    if __sys.platform == 'win32':
+    if sys.platform == 'win32':
         transliteration_target = console_encoding
         print("WARNING: Running on Windows and transliteration_target is not "
               "set.")
@@ -752,7 +748,7 @@
 if __name__ == "__main__":
     import types
     _all = 1
-    for _arg in __sys.argv[1:]:
+    for _arg in sys.argv[1:]:
         if _arg == "modified":
             _all = 0
         else:
@@ -769,7 +765,6 @@
 # cleanup all locally-defined variables
 for __var in list(globals().keys()):
     if __var.startswith("_") and not __var.startswith("__"):
-        del __sys.modules[__name__].__dict__[__var]
+        del sys.modules[__name__].__dict__[__var]
 
-del __var, __sys
-del os, re
+del __var

-- 
To view, visit https://gerrit.wikimedia.org/r/141289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I783fba623a2825af3273ecad286d47e897c2a674
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Russell Blau <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to