Changeset 250869 in webkit


Ignore:
Timestamp:
Oct 8, 2019 3:30:21 PM (5 years ago)
Author:
Jonathan Bedard
Message:

Python 3: Add support to auto-importer
https://bugs.webkit.org/show_bug.cgi?id=201955

Reviewed by Aakash Jain.

  • Scripts/test-webkitpy-python3: Auto-install everything.
  • Scripts/webkitpy/common/system/autoinstall.py: Import urlopen and urlparse for Python3.
  • Scripts/webkitpy/thirdparty/init.py:

(AutoinstallImportHook.find_module): Update function definition for Python3.
(AutoinstallImportHook._install_mechanize): Use Python 2/3 compatible version of mechanize.
(AutoinstallImportHook._install_requests): Update urllib3 and requests version.
(AutoinstallImportHook._install_coverage): Use Python 2/3 compatible version of coverage.
(AutoinstallImportHook.greater_than_equal_to_version): Use range instead of xrange.
(AutoinstallImportHook._install_selenium): Update urllib3 version.
(AutoinstallImportHook.install_chromedriver):
(AutoinstallImportHook.install_geckodriver):
(AutoinstallImportHook.get_latest_pypi_url):
(AutoinstallImportHook.install_binary):

  • Scripts/webkitpy/thirdparty/init_unittest.py:

(ThirdpartyTest):
(ThirdpartyTest.test_import_hook): Deleted.

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r250868 r250869  
     12019-10-08  Jonathan Bedard  <jbedard@apple.com>
     2
     3        Python 3: Add support to auto-importer
     4        https://bugs.webkit.org/show_bug.cgi?id=201955
     5
     6        Reviewed by Aakash Jain.
     7
     8        * Scripts/test-webkitpy-python3: Auto-install everything.
     9        * Scripts/webkitpy/common/system/autoinstall.py: Import urlopen and urlparse for Python3.
     10        * Scripts/webkitpy/thirdparty/__init__.py:
     11        (AutoinstallImportHook.find_module): Update function definition for Python3.
     12        (AutoinstallImportHook._install_mechanize): Use Python 2/3 compatible version of mechanize.
     13        (AutoinstallImportHook._install_requests): Update urllib3 and requests version.
     14        (AutoinstallImportHook._install_coverage): Use Python 2/3 compatible version of coverage.
     15        (AutoinstallImportHook.greater_than_equal_to_version): Use range instead of xrange.
     16        (AutoinstallImportHook._install_selenium): Update urllib3 version.
     17        (AutoinstallImportHook.install_chromedriver):
     18        (AutoinstallImportHook.install_geckodriver):
     19        (AutoinstallImportHook.get_latest_pypi_url):
     20        (AutoinstallImportHook.install_binary):
     21        * Scripts/webkitpy/thirdparty/__init___unittest.py:
     22        (ThirdpartyTest):
     23        (ThirdpartyTest.test_import_hook): Deleted.
     24
    1252019-10-08  Yury Semikhatsky  <yurys@chromium.org>
    226
  • trunk/Tools/Scripts/test-webkitpy-python3

    r250631 r250869  
    7676        raise RuntimeError('No matching tests found.')
    7777
     78    from webkitpy.thirdparty import autoinstall_everything
     79    autoinstall_everything()
     80
    7881    result = unittest.TextTestRunner(verbosity=int(options.verbose) + 1, failfast=options.stop_on_fail, buffer=not options.verbose).run(suite)
    7982    return len(result.errors)
  • trunk/Tools/Scripts/webkitpy/common/system/autoinstall.py

    r244513 r250869  
    4040import tarfile
    4141import tempfile
    42 import urllib2
    43 import urlparse
    4442import zipfile
    4543import re
    4644from distutils import dir_util
    4745from glob import glob
    48 import urlparse
    4946import subprocess
     47
     48if sys.version_info > (3, 0):
     49    from urllib.request import urlopen
     50    import urllib.parse as urlparse
     51else:
     52    from urllib2 import urlopen
     53    import urlparse
    5054
    5155
  • trunk/Tools/Scripts/webkitpy/thirdparty/__init__.py

    r247538 r250869  
    3232import re
    3333import sys
    34 import urllib2
     34
     35if sys.version_info > (3, 0):
     36    from urllib.error import URLError
     37    from urllib.request import urlopen
     38else:
     39    from urllib2 import URLError, urlopen
    3540
    3641from collections import namedtuple
     
    8186            sys.path.insert(0, _AUTOINSTALLED_DIR)
    8287
    83     def find_module(self, fullname, _):
     88    def find_module(self, fullname, path=None):
    8489        # This method will run before each import. See http://www.python.org/dev/peps/pep-0302/
    8590        if '.autoinstalled' not in fullname:
     
    122127
    123128    def _install_mechanize(self):
    124         self._install("https://files.pythonhosted.org/packages/source/m/mechanize/mechanize-0.2.5.tar.gz",
    125                              "mechanize-0.2.5/mechanize")
     129        self._ensure_autoinstalled_dir_is_in_sys_path()
     130        self._install("https://files.pythonhosted.org/packages/0b/02/ae6ceac1baeda530866a85075641cec12989bd8d31af6d5ab4a3e8c92f47/webencodings-0.5.1.tar.gz",
     131                             "webencodings-0.5.1/webencodings")
     132        self._install("https://files.pythonhosted.org/packages/85/3e/cf449cf1b5004e87510b9368e7a5f1acd8831c2d6691edd3c62a0823f98f/html5lib-1.0.1.tar.gz",
     133                             "html5lib-1.0.1/html5lib")
     134        self._install("https://files.pythonhosted.org/packages/64/f1/1aa4c96dea14e17a955019b0fc4ac1b8dfbc50e3c90970c1fb8882e74a7b/mechanize-0.4.3.tar.gz",
     135                             "mechanize-0.4.3/mechanize")
    126136
    127137    def _install_keyring(self):
     
    176186        self._install("https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz",
    177187                      "chardet-3.0.4/chardet")
    178         self._install("https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz",
    179                       "chardet-3.0.4/chardet")
    180188        self._install("https://files.pythonhosted.org/packages/ad/13/eb56951b6f7950cadb579ca166e448ba77f9d24efc03edd7e55fa57d04b7/idna-2.8.tar.gz",
    181189                      "idna-2.8/idna")
    182         self._install("https://files.pythonhosted.org/packages/b1/53/37d82ab391393565f2f831b8eedbffd57db5a718216f82f1a8b4d381a1c1/urllib3-1.24.1.tar.gz",
    183                       "urllib3-1.24.1/src/urllib3")
    184         self._install("https://files.pythonhosted.org/packages/52/2c/514e4ac25da2b08ca5a464c50463682126385c4272c18193876e91f4bc38/requests-2.21.0.tar.gz",
    185                       "requests-2.21.0/requests")
     190        self._install("https://files.pythonhosted.org/packages/ff/44/29655168da441dff66de03952880c6e2d17b252836ff1aa4421fba556424/urllib3-1.25.6.tar.gz",
     191                      "urllib3-1.25.6/src/urllib3")
     192        self._install("https://files.pythonhosted.org/packages/01/62/ddcf76d1d19885e8579acb1b1df26a852b03472c0e46d2b959a714c90608/requests-2.22.0.tar.gz",
     193                      "requests-2.22.0/requests")
    186194
    187195    def _install_pylint(self):
     
    224232    def _install_coverage(self):
    225233        self._ensure_autoinstalled_dir_is_in_sys_path()
    226         self._install(url="https://files.pythonhosted.org/packages/source/c/coverage/coverage-3.5.1.tar.gz", url_subpath="coverage-3.5.1/coverage")
     234        self._install(url="https://files.pythonhosted.org/packages/85/d5/818d0e603685c4a613d56f065a721013e942088047ff1027a632948bdae6/coverage-4.5.4.tar.gz", url_subpath="coverage-4.5.4/coverage")
    227235
    228236    def _install_twisted_15_5_0(self):
     
    234242    @staticmethod
    235243    def greater_than_equal_to_version(minimum, version):
    236         for i in xrange(len(minimum.split('.'))):
     244        for i in range(len(minimum.split('.'))):
    237245            if int(version.split('.')[i]) > int(minimum.split('.')[i]):
    238246                return True
     
    245253
    246254        installer = AutoInstaller(prepend_to_search_path=True, target_dir=self._fs.join(_AUTOINSTALLED_DIR, "urllib3"))
    247         installer.install(url="https://files.pythonhosted.org/packages/b1/53/37d82ab391393565f2f831b8eedbffd57db5a718216f82f1a8b4d381a1c1/urllib3-1.24.1.tar.gz", url_subpath="urllib3-1.24.1")
     255        installer.install(url="https://files.pythonhosted.org/packages/ff/44/29655168da441dff66de03952880c6e2d17b252836ff1aa4421fba556424/urllib3-1.25.6.tar.gz", url_subpath="urllib3-1.25.6")
    248256
    249257        minimum_version = '3.5.0'
     
    255263        try:
    256264            url, url_subpath = self.get_latest_pypi_url('selenium')
    257         except urllib2.URLError:
     265        except URLError:
    258266            # URL for installing the minimum required version.
    259267            url = 'https://files.pythonhosted.org/packages/ac/d7/1928416439d066c60f26c87a8d1b78a8edd64c7d05a0aa917fa97a8ee02d/selenium-3.5.0.tar.gz'
     
    265273        filename_postfix = get_driver_filename().chrome
    266274        if filename_postfix != "unsupported":
    267             version = urllib2.urlopen(CHROME_DRIVER_URL + 'LATEST_RELEASE').read().strip()
     275            version = urlopen(CHROME_DRIVER_URL + 'LATEST_RELEASE').read().strip()
    268276            full_chrome_url = "{base_url}{version}/chromedriver_{os}.zip".format(base_url=CHROME_DRIVER_URL, version=version, os=filename_postfix)
    269277            self.install_binary(full_chrome_url, 'chromedriver')
     
    272280        filename_postfix = get_driver_filename().firefox
    273281        if filename_postfix != "unsupported":
    274             firefox_releases_blob = urllib2.urlopen(FIREFOX_RELEASES_URL)
     282            firefox_releases_blob = urlopen(FIREFOX_RELEASES_URL)
    275283            firefox_releases_line_separated = json.dumps(json.load(firefox_releases_blob), indent=0).strip()
    276284            all_firefox_release_urls = "\n".join(re.findall(r'.*browser_download_url.*', firefox_releases_line_separated))
     
    284292    def get_latest_pypi_url(self, package_name, url_subpath_format='{name}-{version}/{lname}'):
    285293        json_url = "https://pypi.org/pypi/%s/json" % package_name
    286         response = urllib2.urlopen(json_url, timeout=30)
     294        response = urlopen(json_url, timeout=30)
    287295        data = json.load(response)
    288296        url = data['urls'][1]['url']
     
    293301        self._install(url=url, target_name=name)
    294302        directory = os.path.join(_AUTOINSTALLED_DIR, name)
    295         os.chmod(os.path.join(directory, name), 0755)
     303        os.chmod(os.path.join(directory, name), 0o755)
    296304        open(os.path.join(directory, '__init__.py'), 'w+').close()
    297305
    298306
    299307_hook = AutoinstallImportHook()
    300 sys.meta_path.append(_hook)
     308sys.meta_path.insert(0, _hook)
    301309
    302310
  • trunk/Tools/Scripts/webkitpy/thirdparty/__init___unittest.py

    r221825 r250869  
    3434
    3535class ThirdpartyTest(unittest.TestCase):
    36     def test_import_hook(self):
    37         # Add another import hook and make sure we get called.
    38         class MockImportHook(AutoinstallImportHook):
    39             def __init__(self):
    40                 AutoinstallImportHook.__init__(self)
    41                 self.buildbot_installed = False
    42 
    43             def _install_buildbot(self):
    44                 self.buildbot_installed = True
    45 
    46         mock_import_hook = MockImportHook()
    47         try:
    48             # The actual AutoinstallImportHook should be installed before us,
    49             # so these modules will get installed before MockImportHook runs.
    50             sys.meta_path.append(mock_import_hook)
    51             # unused-variable, import failures - pylint: disable-msg=W0612,E0611,F0401
    52             from webkitpy.thirdparty.autoinstalled import buildbot
    53             self.assertTrue(mock_import_hook.buildbot_installed)
    54 
    55         finally:
    56             sys.meta_path.remove(mock_import_hook)
    57 
    5836    def test_imports(self):
    5937        # This method tests that we can actually import everything.
Note: See TracChangeset for help on using the changeset viewer.