diff --git a/py/tox.ini b/py/tox.ini index 7bf3bc7dbcdf9..eedcffdb56b1a 100644 --- a/py/tox.ini +++ b/py/tox.ini @@ -44,11 +44,18 @@ deps = flake8-typing-imports==1.16.0 docformatter==1.7.5 commands = - isort --check-only --diff selenium/ test/ conftest.py + isort --check-only --diff selenium/ test/ ../scripts conftest.py black --check --diff selenium/ test/ conftest.py + # run black separately for directories above the current directory + # because it ignores pyproject.toml configuration otrherwise + black --check --diff ../scripts + # not including ../scripts because autofoflake can't handle + # directories above the current directory autoflake --check-diff selenium/ test/ conftest.py + # not including ../scripts because flake8 can't handle + # directories above the current directory flake8 selenium/ test/ conftest.py - docformatter --check --diff selenium/ test/ conftest.py + docformatter --check --diff selenium/ test/ ../scripts conftest.py [testenv:linting] ; A consolidated linting based recipe, responsible for executing linting tools across the code base. @@ -70,8 +77,15 @@ deps = flake8-typing-imports==1.16.0 docformatter==1.7.5 commands = - isort selenium/ test/ conftest.py + isort selenium/ test/ ../scripts conftest.py black selenium/ test/ conftest.py + # run black separately for directories above the current directory + # because it ignores pyproject.toml configuration otrherwise + black ../scripts + # not including ../scripts because autofoflake can't handle + # directories above the current directory autoflake selenium/ test/ conftest.py + # not including ../scripts because flake8 can't handle + # directories above the current directory flake8 selenium/ test/ conftest.py - docformatter selenium/ test/ conftest.py + docformatter selenium/ test/ ../scripts conftest.py diff --git a/scripts/pinned_browsers.py b/scripts/pinned_browsers.py index 77bc0a021acf3..76d774c2f2ee1 100755 --- a/scripts/pinned_browsers.py +++ b/scripts/pinned_browsers.py @@ -28,23 +28,30 @@ def calculate_hash(url): def get_chrome_milestone(): parser = argparse.ArgumentParser() - parser.add_argument('--chrome_channel', default='Stable', help='Set the Chrome channel') + parser.add_argument( + "--chrome_channel", default="Stable", help="Set the Chrome channel" + ) args = parser.parse_args() channel = args.chrome_channel r = http.request( - "GET", f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux" + "GET", + f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux", ) all_versions = json.loads(r.data) # use the same milestone for all chrome releases, so pick the lowest - milestone = min([version["milestone"] for version in all_versions if version["milestone"]]) + milestone = min( + [version["milestone"] for version in all_versions if version["milestone"]] + ) r = http.request( - "GET", "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json" + "GET", + "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json", ) versions = json.loads(r.data)["versions"] return sorted( - filter(lambda v: v["version"].split(".")[0] == str(milestone), versions), key=lambda v: parse(v["version"]) + filter(lambda v: v["version"].split(".")[0] == str(milestone), versions), + key=lambda v: parse(v["version"]), )[-1] @@ -198,7 +205,6 @@ def edge(): linux_hash = None mac = None mac_hash = None - version = None for data in all_data: if not "Stable" == data.get("product"): @@ -268,7 +274,7 @@ def edge(): ) """ % ( linux, - linux_hash.lower() + linux_hash.lower(), ) return content @@ -277,13 +283,18 @@ def edge(): def edgedriver(): r_stable = http.request("GET", "https://msedgedriver.azureedge.net/LATEST_STABLE") stable_version = r_stable.data.decode("utf-16").strip() - major_version = stable_version.split('.')[0] - r = http.request("GET", f"https://msedgedriver.azureedge.net/LATEST_RELEASE_{major_version}_LINUX") + major_version = stable_version.split(".")[0] + r = http.request( + "GET", + f"https://msedgedriver.azureedge.net/LATEST_RELEASE_{major_version}_LINUX", + ) linux_version = r.data.decode("utf-16").strip() content = "" - linux = "https://msedgedriver.azureedge.net/%s/edgedriver_linux64.zip" % linux_version + linux = ( + "https://msedgedriver.azureedge.net/%s/edgedriver_linux64.zip" % linux_version + ) sha = calculate_hash(linux) content = ( content @@ -308,7 +319,10 @@ def edgedriver(): % (linux, sha) ) - r = http.request("GET", f"https://msedgedriver.azureedge.net/LATEST_RELEASE_{major_version}_MACOS") + r = http.request( + "GET", + f"https://msedgedriver.azureedge.net/LATEST_RELEASE_{major_version}_MACOS", + ) macos_version = r.data.decode("utf-16").strip() mac = "https://msedgedriver.azureedge.net/%s/edgedriver_mac64.zip" % macos_version sha = calculate_hash(mac) @@ -340,7 +354,9 @@ def edgedriver(): def geckodriver(): content = "" - r = http.request("GET", "https://api.github.com/repos/mozilla/geckodriver/releases/latest") + r = http.request( + "GET", "https://api.github.com/repos/mozilla/geckodriver/releases/latest" + ) for a in json.loads(r.data)["assets"]: if a["name"].endswith("-linux64.tar.gz"): url = a["browser_download_url"] @@ -411,21 +427,30 @@ def firefox(): def firefox_version_data(): - versions = http.request("GET", "https://product-details.mozilla.org/1.0/firefox_versions.json") + versions = http.request( + "GET", "https://product-details.mozilla.org/1.0/firefox_versions.json" + ) return versions.data def firefox_linux(version): if int(version.split(".")[0]) < 135: - return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" % ( - version, version) + return ( + "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" + % (version, version) + ) else: - return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.xz" % ( - version, version) + return ( + "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.xz" + % (version, version) + ) def firefox_mac(version): - return "https://ftp.mozilla.org/pub/firefox/releases/%s/mac/en-US/Firefox%%20%s.dmg" % (version, version) + return ( + "https://ftp.mozilla.org/pub/firefox/releases/%s/mac/en-US/Firefox%%20%s.dmg" + % (version, version) + ) def print_firefox(version, workspace_name, sha_linux, sha_mac): diff --git a/scripts/selenium_manager.py b/scripts/selenium_manager.py index c4d96a8732ee6..b9ca7c6d57811 100755 --- a/scripts/selenium_manager.py +++ b/scripts/selenium_manager.py @@ -14,52 +14,59 @@ def get_url(): r = http.request( - "GET", f"https://github.com/SeleniumHQ/selenium_manager_artifacts/releases/latest" + "GET", + "https://github.com/SeleniumHQ/selenium_manager_artifacts/releases/latest", ) return r.url.replace("tag", "download") def get_sha_json(): - r = http.request("GET", f"https://raw.githubusercontent.com/SeleniumHQ/selenium_manager_artifacts/trunk/latest.json") + r = http.request( + "GET", + "https://raw.githubusercontent.com/SeleniumHQ/selenium_manager_artifacts/trunk/latest.json", + ) return json.loads(r.data) def print_linux(base_url, sha): - return (""" http_file( + return """ http_file( name = "download_sm_linux", executable = True, sha256 = "%s", url = "%s", ) -""" - % (sha, base_url + "/selenium-manager-linux") - ) +""" % ( + sha, + base_url + "/selenium-manager-linux", + ) def print_macos(base_url, sha): - return (""" http_file( + return """ http_file( name = "download_sm_macos", executable = True, sha256 = "%s", url = "%s", ) -""" - % (sha, base_url + "/selenium-manager-macos") - ) +""" % ( + sha, + base_url + "/selenium-manager-macos", + ) def print_windows(base_url, sha): - return (""" http_file( + return """ http_file( name = "download_sm_windows", executable = True, sha256 = "%s", url = "%s", ) -""" - % (sha, base_url + "/selenium-manager-windows.exe") - ) +""" % ( + sha, + base_url + "/selenium-manager-windows.exe", + ) if __name__ == "__main__": @@ -71,9 +78,9 @@ def selenium_manager(): """ base_url = get_url() sha_dict = get_sha_json() - content = content + print_linux(base_url, sha_dict['linux']) - content = content + print_macos(base_url, sha_dict['macos']) - content = content + print_windows(base_url, sha_dict['windows']) + content = content + print_linux(base_url, sha_dict["linux"]) + content = content + print_macos(base_url, sha_dict["macos"]) + content = content + print_windows(base_url, sha_dict["windows"]) content += """ def _selenium_manager_artifacts_impl(_ctx): selenium_manager() diff --git a/scripts/update_cdp.py b/scripts/update_cdp.py index 9c978449fc828..364d971513d60 100755 --- a/scripts/update_cdp.py +++ b/scripts/update_cdp.py @@ -1,13 +1,11 @@ #!/usr/bin/env python import argparse -import hashlib import json import os import re import shutil import subprocess -import sys from pathlib import Path import urllib3 @@ -21,23 +19,30 @@ def get_chrome_milestone(): """This is the same method from pinned_browser. Use --chrome_channel=Beta if using early stable release.""" parser = argparse.ArgumentParser() - parser.add_argument("--chrome_channel", default="Stable", help="Set the Chrome channel") + parser.add_argument( + "--chrome_channel", default="Stable", help="Set the Chrome channel" + ) args = parser.parse_args() channel = args.chrome_channel r = http.request( - "GET", f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux" + "GET", + f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux", ) all_versions = json.loads(r.data) # use the same milestone for all Chrome releases, so pick the lowest - milestone = min([version["milestone"] for version in all_versions if version["milestone"]]) + milestone = min( + [version["milestone"] for version in all_versions if version["milestone"]] + ) r = http.request( - "GET", "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json" + "GET", + "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json", ) versions = json.loads(r.data)["versions"] return sorted( - filter(lambda v: v["version"].split(".")[0] == str(milestone), versions), key=lambda v: parse(v["version"]) + filter(lambda v: v["version"].split(".")[0] == str(milestone), versions), + key=lambda v: parse(v["version"]), )[-1] @@ -60,7 +65,9 @@ def old_chrome(chrome_milestone): def add_pdls(chrome_milestone): - source_dir = root_dir / f"common/devtools/chromium/v{previous_chrome(chrome_milestone)}" + source_dir = ( + root_dir / f"common/devtools/chromium/v{previous_chrome(chrome_milestone)}" + ) target_dir = root_dir / f"common/devtools/chromium/v{new_chrome(chrome_milestone)}" old_dir = root_dir / f"common/devtools/chromium/v{old_chrome(chrome_milestone)}" @@ -78,9 +85,14 @@ def add_pdls(chrome_milestone): ) deps_content = http.request( - "GET", f"https://raw.githubusercontent.com/chromium/chromium/{chrome_milestone['version']}/DEPS" + "GET", + f"https://raw.githubusercontent.com/chromium/chromium/{chrome_milestone['version']}/DEPS", ).data.decode("utf-8") - v8_revision = [line for line in deps_content.split("\n") if "v8_revision" in line][0].split(": ")[1].strip("',") + v8_revision = ( + [line for line in deps_content.split("\n") if "v8_revision" in line][0] + .split(": ")[1] + .strip("',") + ) fetch_and_save( f"https://raw.githubusercontent.com/v8/v8/{v8_revision}/include/js_protocol.pdl", f"{target_dir}/js_protocol.pdl", @@ -112,8 +124,12 @@ def create_new_chrome_files(src_base, chrome_milestone): shutil.copy(item, target_dir) for file in target_dir.iterdir(): - replace_in_file(file, previous_chrome(chrome_milestone), new_chrome(chrome_milestone)) - new_filename = file.name.replace(previous_chrome(chrome_milestone), new_chrome(chrome_milestone)) + replace_in_file( + file, previous_chrome(chrome_milestone), new_chrome(chrome_milestone) + ) + new_filename = file.name.replace( + previous_chrome(chrome_milestone), new_chrome(chrome_milestone) + ) file.rename(target_dir / new_filename) subprocess.run(["git", "add", str(target_dir / "*")], cwd=root_dir) @@ -137,7 +153,9 @@ def update_java(chrome_milestone): root_dir / "Rakefile", ] for file in files: - replace_in_file(file, old_chrome(chrome_milestone), new_chrome(chrome_milestone)) + replace_in_file( + file, old_chrome(chrome_milestone), new_chrome(chrome_milestone) + ) def update_dotnet(chrome_milestone): @@ -149,13 +167,19 @@ def update_dotnet(chrome_milestone): root_dir / "dotnet/src/webdriver/DevTools/DevToolsDomains.cs", ] for file in files: - replace_in_file(file, old_chrome(chrome_milestone), new_chrome(chrome_milestone)) + replace_in_file( + file, old_chrome(chrome_milestone), new_chrome(chrome_milestone) + ) - files = [root_dir / "dotnet/test/common/CustomDriverConfigs/StableChannelChromeDriver.cs"] + files = [ + root_dir / "dotnet/test/common/CustomDriverConfigs/StableChannelChromeDriver.cs" + ] dir_path = root_dir / "dotnet/test/common/DevTools" files.extend(str(file) for file in dir_path.glob("*") if file.is_file()) for file in files: - replace_in_file(file, previous_chrome(chrome_milestone), new_chrome(chrome_milestone)) + replace_in_file( + file, previous_chrome(chrome_milestone), new_chrome(chrome_milestone) + ) def update_ruby(chrome_milestone): @@ -163,10 +187,16 @@ def update_ruby(chrome_milestone): replace_in_file(file, old_chrome(chrome_milestone), new_chrome(chrome_milestone)) file = root_dir / "rb/lib/selenium/devtools/version.rb" - replace_in_file(file, rf"{previous_chrome(chrome_milestone)}\.[0-9]*", f"{new_chrome(chrome_milestone)}.0", True) + replace_in_file( + file, + rf"{previous_chrome(chrome_milestone)}\.[0-9]*", + f"{new_chrome(chrome_milestone)}.0", + True, + ) subprocess.run(["bundle", "install"], cwd=root_dir / "rb", check=True) + def update_python(chrome_milestone): file = root_dir / "py/BUILD.bazel" replace_in_file(file, old_chrome(chrome_milestone), new_chrome(chrome_milestone)) @@ -186,4 +216,6 @@ def update_js(chrome_milestone): update_python(chrome_milestone) update_js(chrome_milestone) - print(f"adding CDP {new_chrome(chrome_milestone)} and removing {old_chrome(chrome_milestone)}") + print( + f"adding CDP {new_chrome(chrome_milestone)} and removing {old_chrome(chrome_milestone)}" + ) diff --git a/scripts/update_copyright.py b/scripts/update_copyright.py index 57e37abb7a406..d61d03127d296 100755 --- a/scripts/update_copyright.py +++ b/scripts/update_copyright.py @@ -4,6 +4,7 @@ import os from pathlib import Path + class Copyright: NOTICE = """Licensed to the Software Freedom Conservancy (SFC) under one or more contributor license agreements. See the NOTICE file @@ -22,19 +23,20 @@ class Copyright: specific language governing permissions and limitations under the License.""" - def __init__(self, comment_characters='//', prefix=None): + def __init__(self, comment_characters="//", prefix=None): self._comment_characters = comment_characters self._prefix = prefix or [] def update(self, files): for file in files: - with open(file, 'r', encoding='utf-8-sig') as f: + with open(file, "r", encoding="utf-8-sig") as f: lines = f.readlines() index = -1 for i, line in enumerate(lines): - if line.startswith(self._comment_characters) or \ - self.valid_copyright_notice_line(line, index, file): + if line.startswith( + self._comment_characters + ) or self.valid_copyright_notice_line(line, index, file): index += 1 else: break @@ -42,39 +44,48 @@ def update(self, files): if index == -1: self.write_update_notice(file, lines) else: - current = ''.join(lines[:index + 1]) + current = "".join(lines[: index + 1]) if current != self.copyright_notice(file): - self.write_update_notice(file, lines[index + 1:]) + self.write_update_notice(file, lines[index + 1 :]) def valid_copyright_notice_line(self, line, index, file): - return index + 1 < len(self.copyright_notice_lines(file)) and \ - line.startswith(self.copyright_notice_lines(file)[index + 1]) + return index + 1 < len(self.copyright_notice_lines(file)) and line.startswith( + self.copyright_notice_lines(file)[index + 1] + ) def copyright_notice(self, file): - return ''.join(self.copyright_notice_lines(file)) + return "".join(self.copyright_notice_lines(file)) def copyright_notice_lines(self, file): - return self.dotnet(file) if file.endswith("cs") else self._prefix + self.commented_notice_lines + return ( + self.dotnet(file) + if file.endswith("cs") + else self._prefix + self.commented_notice_lines + ) def dotnet(self, file): file_name = os.path.basename(file) - first = f"{self._comment_characters} \n" + first = f'{self._comment_characters} \n' last = f"{self._comment_characters} " return [first] + self.commented_notice_lines + [last] @property def commented_notice_lines(self): - return [f"{self._comment_characters} {line}".rstrip() + "\n" for line in self.NOTICE.split('\n')] + return [ + f"{self._comment_characters} {line}".rstrip() + "\n" + for line in self.NOTICE.split("\n") + ] def write_update_notice(self, file, lines): print(f"Adding notice to {file}") - with open(file, 'w') as f: + with open(file, "w") as f: f.write(self.copyright_notice(file) + "\n") if lines and lines[0] != "\n": f.write("\n") trimmed_lines = [line.rstrip() + "\n" for line in lines] f.writelines(trimmed_lines) + ROOT = Path(os.path.realpath(__file__)).parent.parent JS_EXCLUSIONS = [ @@ -87,18 +98,18 @@ def write_update_notice(self, file, lines): f"{ROOT}/javascript/selenium-core/scripts/user-extensions.js", f"{ROOT}/javascript/selenium-core/scripts/xmlextras.js", f"{ROOT}/javascript/selenium-core/xpath/**/*.js", - f"{ROOT}/javascript/grid-ui/node_modules/**/*.js" + f"{ROOT}/javascript/grid-ui/node_modules/**/*.js", ] PY_EXCLUSIONS = [ f"{ROOT}/py/selenium/webdriver/common/bidi/cdp.py", f"{ROOT}/py/generate.py", f"{ROOT}/py/selenium/webdriver/common/devtools/**/*", - f"{ROOT}/py/venv/**/*" + f"{ROOT}/py/venv/**/*", ] -def update_files(file_pattern, exclusions, comment_characters='//', prefix=None): +def update_files(file_pattern, exclusions, comment_characters="//", prefix=None): included = set(glob.glob(file_pattern, recursive=True)) excluded = set() for pattern in exclusions: @@ -113,7 +124,12 @@ def update_files(file_pattern, exclusions, comment_characters='//', prefix=None) update_files(f"{ROOT}/javascript/**/*.js", JS_EXCLUSIONS) update_files(f"{ROOT}/javascript/**/*.tsx", []) update_files(f"{ROOT}/py/**/*.py", PY_EXCLUSIONS, comment_characters="#") - update_files(f"{ROOT}/rb/**/*.rb", [], comment_characters="#", prefix=["# frozen_string_literal: true\n", "\n"]) + update_files( + f"{ROOT}/rb/**/*.rb", + [], + comment_characters="#", + prefix=["# frozen_string_literal: true\n", "\n"], + ) update_files(f"{ROOT}/java/**/*.java", []) update_files(f"{ROOT}/rust/**/*.rs", []) update_files(f"{ROOT}/dotnet/**/*.cs", [])