John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/214294

Change subject: Support Debian python-ipaddr package
......................................................................

Support Debian python-ipaddr package

Change-Id: I531f739ab94a7ba424142041a5e74bf066e6e07d
---
M pywikibot/tools/ip.py
M setup.py
M tests/ipregex_tests.py
3 files changed, 24 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/94/214294/1

diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py
index 808c0cc..7f76ca4 100644
--- a/pywikibot/tools/ip.py
+++ b/pywikibot/tools/ip.py
@@ -46,18 +46,27 @@
         except ValueError:
             # This means ipaddress has correctly determined '1111' is invalid
             pass
+    ip_address.__T76286__ = True
 except ImportError as e:
     warn('Importing ipaddress.ip_address failed: %s' % e,
          ImportWarning)
 
-    def ip_address(IP):
-        """Fake ip_address method."""
-        warn('ipaddress backport not available.', DeprecationWarning)
-        if ip_regexp.match(IP) is None:
-            raise ValueError('Invalid IP address')
+    try:
+        from ipaddr import IPAddress as ip_address
+    except ImportError as e:
+        warn('Importing ipaddr.IPAddress failed: %s' % e,
+             ImportWarning)
 
-    # The following flag is used by the unit tests
-    ip_address.__fake__ = True
+        def ip_address(IP):
+            """Fake ip_address method."""
+            warn('ipaddress backport not available.', DeprecationWarning)
+            if ip_regexp.match(IP) is None:
+                raise ValueError('Invalid IP address')
+
+        # The following flag is used by the unit tests
+        ip_address.__fake__ = True
+
+    ip_address.__T76286__ = False
 
 # deprecated IP detector
 ip_regexp = LazyRegex()
diff --git a/setup.py b/setup.py
index db13b1e..c74ba98 100644
--- a/setup.py
+++ b/setup.py
@@ -78,12 +78,14 @@
         script_deps['replicate_wiki.py'] = ['argparse']
         dependencies.append('future')  # provides collections backports
 
-    # tools.ip does not depend on an ipaddress module, as it falls back to
-    # using regexes if not available, however the pywikibot package should use
-    # the functional backport of py3 ipaddress, which is:
+    # tools.ip does not have a hard dependency on an IP address module,
+    # as it falls back to using regexes if one is not available.
+    # The functional backport of py3 ipaddress is acceptable:
     # https://pypi.python.org/pypi/ipaddress
+    # However the Debian package python-ipaddr is also supported:
+    # https://pypi.python.org/pypi/ipaddr
     # Other backports are likely broken.
-    dependencies.append('ipaddress')
+    dependencies.append('ipaddr')
 
     # mwlib is not available for py3
     script_deps['patrol'] = ['mwlib']
diff --git a/tests/ipregex_tests.py b/tests/ipregex_tests.py
index 7553684..c8dc233 100644
--- a/tests/ipregex_tests.py
+++ b/tests/ipregex_tests.py
@@ -12,6 +12,7 @@
 from pywikibot.tools import ip
 
 from tests.aspects import unittest, TestCase
+from tests.utils import expected_failure_if
 
 
 class TestIPBase(TestCase):
@@ -656,7 +657,7 @@
         self._run_tests()
         self.assertEqual(self.fail, 0)
 
-    @unittest.expectedFailure
+    @expected_failure_if(ip.ip_address.__T76286__)
     def test_ipaddress_module_failures(self):
         """Test known bugs in the ipaddress module."""
         # The following fail with the ipaddress module. See T76286

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I531f739ab94a7ba424142041a5e74bf066e6e07d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

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

Reply via email to