Skip to content

[py] Adjust linting configuration to include /scripts #15702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions py/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
61 changes: 43 additions & 18 deletions scripts/pinned_browsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -268,7 +274,7 @@ def edge():
)
""" % (
linux,
linux_hash.lower()
linux_hash.lower(),
)

return content
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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):
Expand Down
41 changes: 24 additions & 17 deletions scripts/selenium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand All @@ -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()
Expand Down
Loading