jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/338958 )

Change subject: family.py: Do not use the `imp` module in Python 3
......................................................................


family.py: Do not use the `imp` module in Python 3

The `imp` module is deprecated since version 3.4 in favor of importlib.
Use `sys.path.append` and `importlib.import_module` instead of
`imp.load_source`.

Bug: T158640
Change-Id: Id12c9e991a2d359afdbd7f7e29558282ff39c5cb
---
M pywikibot/family.py
1 file changed, 15 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved



diff --git a/pywikibot/family.py b/pywikibot/family.py
index b5e06bc..85aa05d 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 """Objects representing MediaWiki families."""
 #
-# (C) Pywikibot team, 2004-2016
+# (C) Pywikibot team, 2004-2017
 #
 # Distributed under the terms of the MIT license.
 #
@@ -11,16 +11,19 @@
 #
 
 import collections
-import imp
 import logging
 import re
 import string
 import sys
 import warnings
 
-if sys.version_info[0] > 2:
+PY3 = sys.version_info[0] > 2
+if PY3:
+    from os.path import basename, dirname, splitext
+    from importlib import import_module
     import urllib.parse as urlparse
 else:
+    import imp
     import urlparse
 
 from warnings import warn
@@ -917,6 +920,8 @@
                 myfamily = AutoFamily(fam, family_file)
                 Family._families[fam] = myfamily
                 return Family._families[fam]
+        else:
+            raise UnknownFamily('Family %s does not exist' % fam)
 
         try:
             # Ignore warnings due to dots in family names.
@@ -924,8 +929,13 @@
             #     RuntimeWarning's while loading.
             with warnings.catch_warnings():
                 warnings.simplefilter("ignore", RuntimeWarning)
-                mod = imp.load_source(fam, config.family_files[fam])
-        except (ImportError, KeyError):
+                if PY3:
+                    sys.path.append(dirname(family_file))
+                    mod = import_module(splitext(basename(family_file))[0])
+                else:
+                    # Python 2.6 has no importlib.import_module
+                    mod = imp.load_source(fam, family_file)
+        except ImportError:
             raise UnknownFamily(u'Family %s does not exist' % fam)
         cls = mod.Family()
         if cls.name != fam:

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id12c9e991a2d359afdbd7f7e29558282ff39c5cb
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Lokal Profil <[email protected]>
Gerrit-Reviewer: Magul <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to