webkitpy: Ignore failure to get updated selenium version
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Sep 2017 21:37:04 +0000 (21:37 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Sep 2017 21:37:04 +0000 (21:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177205
<rdar://problem/34531669>

Reviewed by Lucas Forschler.

Sometime asking PyPI for the latest version of Selenium fails. We should try and
fallback to, at a minimum, version 3.5.0 or a newer installed version.

* Scripts/webkitpy/thirdparty/__init__.py:
(AutoinstallImportHook.greater_than_equal_to_version): Return true if the second
version string is greater than or equal to the first version string.
(AutoinstallImportHook._install_selenium): If we can't get the latest PyPI url,
fallback to version 3.5.0 or a newer installed version.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222352 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/thirdparty/__init__.py

index f8678d7..54d2c36 100644 (file)
@@ -1,3 +1,20 @@
+2017-09-21  Jonathan Bedard  <jbedard@apple.com>
+
+        webkitpy: Ignore failure to get updated selenium version
+        https://bugs.webkit.org/show_bug.cgi?id=177205
+        <rdar://problem/34531669>
+
+        Reviewed by Lucas Forschler.
+
+        Sometime asking PyPI for the latest version of Selenium fails. We should try and
+        fallback to, at a minimum, version 3.5.0 or a newer installed version.
+
+        * Scripts/webkitpy/thirdparty/__init__.py:
+        (AutoinstallImportHook.greater_than_equal_to_version): Return true if the second
+        version string is greater than or equal to the first version string.
+        (AutoinstallImportHook._install_selenium): If we can't get the latest PyPI url,
+        fallback to version 3.5.0 or a newer installed version.
+
 2017-09-21  Filip Pizlo  <fpizlo@apple.com>
 
         WSL should have some post-instantiation type checking
index c084a17..fc47182 100644 (file)
@@ -166,9 +166,31 @@ class AutoinstallImportHook(object):
         installer.install(url="https://pypi.python.org/packages/source/T/Twisted/Twisted-15.5.0.tar.bz2#md5=0831d7c90d0020062de0f7287530a285", url_subpath="Twisted-15.5.0/twisted")
         installer.install(url="https://pypi.python.org/packages/source/z/zope.interface/zope.interface-4.1.3.tar.gz#md5=9ae3d24c0c7415deb249dd1a132f0f79", url_subpath="zope.interface-4.1.3/src/zope")
 
+    @staticmethod
+    def greater_than_equal_to_version(minimum, version):
+        for i in xrange(len(minimum.split('.'))):
+            if int(version.split('.')[i]) > int(minimum.split('.')[i]):
+                return True
+            if int(version.split('.')[i]) < int(minimum.split('.')[i]):
+                return False
+        return True
+
     def _install_selenium(self):
         self._ensure_autoinstalled_dir_is_in_sys_path()
-        url, url_subpath = self.get_latest_pypi_url('selenium')
+        try:
+            url, url_subpath = self.get_latest_pypi_url('selenium')
+        except urllib2.URLError:
+            minimum_version = '3.5.0'
+            if os.path.isfile(os.path.join(_AUTOINSTALLED_DIR, 'selenium', '__init__.py')):
+                import selenium.webdriver
+                if AutoinstallImportHook.greater_than_equal_to_version(minimum_version, selenium.webdriver.__version__):
+                    sys.stderr.write('\nFailed to find latest selenium, falling back to existing {} version\n'.format(selenium.webdriver.__version__))
+                    return
+
+            # URL for installing the minimum required version.
+            url = 'https://pypi.python.org/packages/ac/d7/1928416439d066c60f26c87a8d1b78a8edd64c7d05a0aa917fa97a8ee02d/selenium-3.5.0.tar.gz#986702fdd0e2aec6a4eda134678b8b3f'
+            url_subpath = 'selenium-{}/selenium'.format(minimum_version)
+            sys.stderr.write('\nFailed to find latest selenium, falling back to minimum {} version\n'.format(minimum_version))
         self._install(url=url, url_subpath=url_subpath)
 
     def install_chromedriver(self):