Skip to content

Commit 24cf392

Browse files
committed
Merge branch 'main' into andrew/mac-subprocess-fix
2 parents a1e7af0 + dfce2ed commit 24cf392

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Install Dependencies
1010
run: sudo apt-get update && sudo apt-get install chromium-browser
1111
- name: Install devtools
12-
run: ls && pip install .[dev] numpy
12+
run: ls && pip install .[dev]
1313
- name: diagnostic
1414
run: dtdoctor
1515
timeout-minutes: 1
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install Dependencies
2525
run: choco install googlechrome -y --ignore-checksums
2626
- name: Install devtools
27-
run: pip install .[dev] numpy
27+
run: pip install .[dev]
2828
- name: diagnostic
2929
run: dtdoctor
3030
timeout-minutes: 1
@@ -39,7 +39,7 @@ jobs:
3939
- name: Install Dependencies
4040
run: brew install google-chrome
4141
- name: Install devtools
42-
run: pip install .[dev] numpy
42+
run: pip install .[dev]
4343
- name: diagnostic
4444
run: dtdoctor
4545
timeout-minutes: 1

README.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
### ⚠️⚠️⚠️**Testers Needed!**⚠️⚠️⚠️
88

9-
**This package is cross-platform and testing on _many various platforms_ will help us! See [here](#%EF%B8%8F-help-needed-%EF%B8%8F).**
10-
9+
Please install this repo with `pip` (`pip install .`) and run `dtdoctor`, pasting the output in an issue or to slack!
1110

1211
## Quickstart (asyncio)
1312

1413
Easy:
1514
```python
16-
import asyncio
15+
import asyncio # required for this example only
1716
import devtools
1817

1918

@@ -22,6 +21,15 @@ async with Browser(headless=False) as browser:
2221
await asyncio.sleep(3)
2322
await new_tab.send_command("Page.navigate", params=dict(url="https://github.com"))
2423
await asyncio.sleep(3)
24+
25+
26+
## NOTE:
27+
# if you wish to use interactively, ie in a console,
28+
# it is better to use, instead of `async with`:
29+
30+
browser = await Browser(headless=False)
31+
32+
# as exiting the context will close the browser
2533
```
2634

2735
See [the devtools reference](https://chromedevtools.github.io/devtools-protocol/) for a list of all possible commands.
@@ -45,38 +53,22 @@ See [the devtools reference](https://chromedevtools.github.io/devtools-protocol/
4553
reponse = await new_tab.subscribe_once("Page.lifecycleEvent")
4654
# do something with response
4755
browser.unsubscribe("Target.*")
48-
# events are always sent to a browser or tab, but the documentation isn't always clear which
49-
# so dumping all: `browser.subscribe("*", dump_event)` can be useful (but verbose) for debugging
56+
# events are always sent to a browser or tab,
57+
# but the documentation isn't always clear which.
58+
# Dumping all: `browser.subscribe("*", dump_event)` (on tab too)
59+
# can be useful (but verbose) for debugging.
5060
```
51-
Install this repository (`pip install .`) and `numpy`.
5261

5362
## Other Options
5463

5564
### Non-asyncio
5665

5766
You can use this library without `asyncio`,
5867
```
59-
my_browser = devtools.Browser()
68+
my_browser = devtools.Browser() # blocking until open
6069
```
6170
But you are responsible for calling all `browser.pipe.read_jsons(blocking=True|False)` and organizing the results. `browser.run_output_thread()` will start a second thread that constantly prints all responses from the browser, it can't be used with `asyncio`- it won't play nice with any other read.
6271

6372
### Low-level use
6473

6574
We provide a `Browser` and `Tab` interface, but there is also a lower-level `Target` and `Session` interface that one can use if needed.
66-
67-
--------------------------
68-
--------------------------
69-
--------------------------
70-
--------------------------
71-
# ⚠️ Help Needed! ⚠️
72-
73-
### First Test
74-
75-
Please run: `python app/test1.py` and send me the output along with information about your browser, operating system, and python. Internal plotly slack is fine #kaleido, or a github issue is also fine.
76-
77-
#### Optional Tests
78-
79-
Run: `app/app.py` and send me the output.
80-
81-
If everything works, feel free to give `kaleido/app.py` a shot.
82-

devtools/pipe.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@
44
import platform
55
import warnings
66

7-
import numpy as np
8-
97
with_block = bool(sys.version_info[:3] >= (3, 12) or platform.system() != "Windows")
108
class BlockWarning(UserWarning):
119
pass
1210

1311
# TODO: don't know about this
1412
# TODO: use has_attr instead of np.integer, you'll be fine
1513
class NumpyEncoder(json.JSONEncoder):
16-
""" Special json encoder for numpy types """
14+
"""Special json encoder for numpy types"""
15+
1716
def default(self, obj):
18-
if isinstance(obj, np.integer):
17+
if (
18+
hasattr(obj, "dtype")
19+
and obj.dtype.kind == "i"
20+
and obj.shape == ()
21+
):
1922
return int(obj)
20-
elif isinstance(obj, np.floating):
23+
elif (
24+
hasattr(obj, "dtype")
25+
and obj.dtype.kind == "f"
26+
and obj.shape == ()
27+
):
2128
return float(obj)
22-
elif isinstance(obj, np.ndarray):
29+
elif hasattr(obj, "dtype") and obj.shape != ():
2330
return obj.tolist()
2431
return json.JSONEncoder.default(self, obj)
2532

devtools/target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _get_first_session(self):
7676
)
7777
return list(self.sessions.values())[0]
7878

79-
def subscribe(self, string, callback, repeating):
79+
def subscribe(self, string, callback, repeating=True):
8080
session = self._get_first_session()
8181
session.subscribe(string, callback, repeating)
8282

0 commit comments

Comments
 (0)