Skip to content

Commit 9607ee5

Browse files
authored
Merge pull request #214 from plotly/andrew/fix_chrome_version
Andrew/fix chrome version
2 parents 354860e + 13a1be6 commit 9607ee5

File tree

8 files changed

+132
-17
lines changed

8 files changed

+132
-17
lines changed

.github/workflows/publish_testpypi.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
matrix:
1313
os: [ubuntu-latest, windows-latest, macos-latest]
1414
python_v: ['3.8', '3.9', '3.10', '']
15-
chrome_v: ['-1']
15+
# chrome_v: ['-1']
1616
name: Build and Test
1717
runs-on: ${{ matrix.os }}
1818
steps:
@@ -35,7 +35,7 @@ jobs:
3535
uv pip install dist/choreographer-$(uv
3636
run --no-sync --with setuptools-git-versioning
3737
setuptools-git-versioning)-py3-none-any.whl
38-
- run: uv run --no-sync choreo_get_chrome -v --i ${{ matrix.chrome_v }}
38+
- run: uv run --no-sync choreo_get_chrome -v #--i ${{ matrix.chrome_v }}
3939
- name: Diagnose
4040
run: uv run --no-sync choreo_diagnose --no-run
4141
- name: Test

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install choreographer
2727
run: uv sync --no-sources --all-extras
2828
- name: Install google-chrome-for-testing
29-
run: uv run --no-sources choreo_get_chrome
29+
run: uv run --no-sources choreo_get_chrome -v
3030
- name: Diagnose
3131
run: uv run --no-sources choreo_diagnose --no-run
3232
timeout-minutes: 1

CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
v1.0.3
2+
- Fix to fetch latest known chrome version, not latest version
13
v1.0.2
24
- Fix syntax to make compatible with python 3.8
35
- Remove lots of CLI commands

choreographer/browser_async.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ def run() -> subprocess.Popen[bytes]:
145145
await self.populate_targets()
146146
except (BrowserClosedError, BrowserFailedError, asyncio.CancelledError) as e:
147147
raise BrowserFailedError(
148-
"The browser seemed to close immediately after starting."
148+
"The browser seemed to close immediately after starting.",
149149
"You can set the `logging.Logger` level lower to see more output.",
150+
"You may try installed a known working copy of chrome from ",
151+
"`$ choreo_get_chome`. It may be your copy auto-updated.",
150152
) from e
151153

152154
async def __aenter__(self) -> Self:

choreographer/browsers/_chrome_constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"Chrome.app",
1212
"Google Chrome",
1313
"Google Chrome.app",
14+
"Google Chrome for Testing",
1415
]
1516
chrome_names.extend(chromium_names)
1617

choreographer/cli/_cli_utils.py

+48-13
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
from functools import partial
1313
from pathlib import Path
1414

15+
import logistro
16+
17+
_logger = logistro.getLogger(__name__)
18+
1519
# SOON TODO this isn't the right download path, look at uv, use sysconfig
1620
_default_download_path = Path(__file__).resolve().parent / "browser_exe"
1721

1822
_chrome_for_testing_url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
1923

24+
2025
_platforms = ["linux64", "win32", "win64", "mac-x64", "mac-arm64"]
2126

2227
_arch_size_detected = "64" if sys.maxsize > 2**32 else "32"
@@ -69,20 +74,30 @@ def _extract_member(self, member, targetpath, pwd): # type: ignore [no-untyped-
6974

7075
def get_chrome_sync(
7176
arch: str = _chrome_platform_detected,
72-
i: int = -1,
77+
i: int | None = None,
7378
path: str | Path = _default_download_path,
7479
*,
7580
verbose: bool = False,
7681
) -> Path | str:
7782
"""Download chrome synchronously: see `get_chrome()`."""
7883
if isinstance(path, str):
7984
path = Path(path)
80-
browser_list = json.loads(
81-
urllib.request.urlopen( # noqa: S310 audit url for schemes
82-
_chrome_for_testing_url,
83-
).read(),
84-
)
85-
version_obj = browser_list["versions"][i]
85+
if i:
86+
_logger.info("Loading chrome from list")
87+
browser_list = json.loads(
88+
urllib.request.urlopen( # noqa: S310 audit url for schemes
89+
_chrome_for_testing_url,
90+
).read(),
91+
)
92+
version_obj = browser_list["versions"][i]
93+
else:
94+
_logger.info("Using last known good version of chrome")
95+
with (
96+
Path(__file__).resolve().parent.parent
97+
/ "resources"
98+
/ "last_known_good_chrome.json"
99+
).open() as f:
100+
version_obj = json.load(f)
86101
if verbose:
87102
print(version_obj["version"]) # noqa: T201 allow print in cli
88103
print(version_obj["revision"]) # noqa: T201 allow print in cli
@@ -119,7 +134,7 @@ def get_chrome_sync(
119134

120135
async def get_chrome(
121136
arch: str = _chrome_platform_detected,
122-
i: int = -1,
137+
i: int | None = None,
123138
path: str | Path = _default_download_path,
124139
*,
125140
verbose: bool = False,
@@ -153,17 +168,37 @@ def get_chrome_cli() -> None:
153168
" package manager.",
154169
UserWarning,
155170
)
156-
parser = argparse.ArgumentParser(description="tool to help debug problems")
157-
parser.add_argument("--i", "-i", type=int, dest="i")
158-
parser.add_argument("--arch", dest="arch")
159-
parser.add_argument("--path", dest="path")
171+
parser = argparse.ArgumentParser(
172+
description="Will download Chrome for testing. All arguments optional.",
173+
parents=[logistro.parser],
174+
)
175+
parser.add_argument(
176+
"--i",
177+
"-i",
178+
type=int,
179+
dest="i",
180+
help=(
181+
"Google offers thousands of chrome versions for download. "
182+
"'-i 0' is the oldest, '-i -1' is the newest: array syntax"
183+
),
184+
)
185+
parser.add_argument(
186+
"--arch",
187+
dest="arch",
188+
help="linux64|win32|win64|mac-x64|mac-arm64",
189+
)
190+
parser.add_argument(
191+
"--path",
192+
dest="path",
193+
help="Where to store the download.",
194+
)
160195
parser.add_argument(
161196
"-v",
162197
"--verbose",
163198
dest="verbose",
164199
action="store_true",
200+
help="Display found version number if using -i (to stdout)",
165201
)
166-
parser.set_defaults(i=-1)
167202
parser.set_defaults(path=_default_download_path)
168203
parser.set_defaults(arch=_chrome_platform_detected)
169204
parser.set_defaults(verbose=False)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"version": "135.0.7011.0",
3+
"revision": "1418433",
4+
"downloads": {
5+
"chrome": [
6+
{
7+
"platform": "linux64",
8+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/linux64/chrome-linux64.zip"
9+
},
10+
{
11+
"platform": "mac-arm64",
12+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/mac-arm64/chrome-mac-arm64.zip"
13+
},
14+
{
15+
"platform": "mac-x64",
16+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/mac-x64/chrome-mac-x64.zip"
17+
},
18+
{
19+
"platform": "win32",
20+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/win32/chrome-win32.zip"
21+
},
22+
{
23+
"platform": "win64",
24+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/win64/chrome-win64.zip"
25+
}
26+
],
27+
"chromedriver": [
28+
{
29+
"platform": "linux64",
30+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/linux64/chromedriver-linux64.zip"
31+
},
32+
{
33+
"platform": "mac-arm64",
34+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/mac-arm64/chromedriver-mac-arm64.zip"
35+
},
36+
{
37+
"platform": "mac-x64",
38+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/mac-x64/chromedriver-mac-x64.zip"
39+
},
40+
{
41+
"platform": "win32",
42+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/win32/chromedriver-win32.zip"
43+
},
44+
{
45+
"platform": "win64",
46+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/win64/chromedriver-win64.zip"
47+
}
48+
],
49+
"chrome-headless-shell": [
50+
{
51+
"platform": "linux64",
52+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/linux64/chrome-headless-shell-linux64.zip"
53+
},
54+
{
55+
"platform": "mac-arm64",
56+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/mac-arm64/chrome-headless-shell-mac-arm64.zip"
57+
},
58+
{
59+
"platform": "mac-x64",
60+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/mac-x64/chrome-headless-shell-mac-x64.zip"
61+
},
62+
{
63+
"platform": "win32",
64+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/win32/chrome-headless-shell-win32.zip"
65+
},
66+
{
67+
"platform": "win64",
68+
"url": "https://storage.googleapis.com/chrome-for-testing-public/135.0.7011.0/win64/chrome-headless-shell-win64.zip"
69+
}
70+
]
71+
}
72+
}

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ find = {namespaces = false}
88
[tool.setuptools-git-versioning]
99
enabled = true
1010

11+
[tool.setuptools.package-data]
12+
kaleido = ['resources/latest_known_good_chrome.json']
13+
1114
[project]
1215
name = "choreographer"
1316
description = "Devtools Protocol implementation for chrome."

0 commit comments

Comments
 (0)