FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnative/src/pythonnative/bootstrap.py at v0.43.1 · pythonnative/pythonnative · GitHub
pythonnative
pythonnative
Repository navigation
Code
Issues
11
(11)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
bootstrap.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
100 lines (79 loc) · 3.35 KB
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
bootstrap.py
Copy path
File metadata and controls
100 lines (79 loc) · 3.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Entry point the native app templates run right after Python starts.
Both templates execute one line of Python once the interpreter is up:
```python
import pythonnative.bootstrap; pythonnative.bootstrap.start()
```
[`start`][pythonnative.bootstrap.start] connects the two halves of the
bridge (installing the native -> Python callback on iOS), verifies the
protocol version, routes ``print()`` to the console on iOS, warms the
asyncio runtime, and, in debug builds, starts the dev client that syncs
sources from ``pn start``. From then on the native runtime drives
everything through ``callback("host", ...)``; see ``docs/concepts/bridge.md``.
"""
from
__future__
import
annotations
import
os
import
sys
import
traceback
from
typing
import
Any
,
Dict
__all__
=
[
"start"
,
"status"
]
_started
:
Dict
[
str
,
Any
]
=
{}
def
start
(
dev
:
bool
=
False
,
strict
:
bool
=
False
)
->
Dict
[
str
,
Any
]:
"""Connect the bridge and prepare the runtime.
Args:
dev: Enable dev mode (RedBox, validation warnings, the dev
client). Debug templates pass ``True``.
strict: Re-raise the failure after recording it. The templates
pass ``True`` so a broken bridge surfaces as a bootstrap
error screen with the full traceback.
Returns:
A status dict (``{"protocol": 2, "platform": "ios"}``) that the
template logs. Unless ``strict`` is set this never raises:
failures are printed and reported in the dict under
``"error"``.
"""
global
_started
if
_started
and
"error"
not
in
_started
:
return
dict
(
_started
)
status_
:
Dict
[
str
,
Any
]
=
{
"platform"
:
None
,
"protocol"
:
None
}
try
:
from
.
utils
import
IS_ANDROID
,
IS_IOS
status_
[
"platform"
]
=
"ios"
if
IS_IOS
else
"android"
if
IS_ANDROID
else
"off-device"
if
IS_IOS
:
try
:
from
.
import
_ios_log
_ios_log
.
install
()
except
Exception
:
pass
from
.
runtime
import
start
as
start_runtime
start_runtime
()
from
.
sdk
.
schema
import
load_bundled_contracts
load_bundled_contracts
()
from
.
import
bridge
status_
[
"protocol"
]
=
bridge
.
handshake
()
dev_mode
=
bool
(
dev
or
os
.
environ
.
get
(
"PN_DEV"
)
in
(
"1"
,
"true"
))
if
dev_mode
:
from
.
import
diagnostics
diagnostics
.
set_dev_mode
(
True
)
# Import the view backend eagerly: on a slow device the first
# commit shouldn't also pay for importing the reconciler.
from
.
native_views
import
get_registry
get_registry
()
if
dev_mode
:
# Debug builds are dev clients: connect to `pn start` when
# the build (or a remembered connection) names a server.
from
.
import
devclient
client
=
devclient
.
start_if_configured
()
status_
[
"dev_server"
]
=
client
.
url
if
client
is
not
None
else
None
except
Exception
as
exc
:
status_
[
"error"
]
=
f"
{
type
(
exc
).
__name__
}
:
{
exc
}
"
print
(
f"[pn.bootstrap] start failed:
{
exc
!r
}
"
,
file
=
sys
.
stderr
)
traceback
.
print_exc
()
_started
=
status_
if
strict
:
raise
return
dict
(
status_
)
_started
=
status_
return
dict
(
status_
)
def
status
()
->
Dict
[
str
,
Any
]:
"""Return the result of the last [`start`][pythonnative.bootstrap.start] (empty before it ran)."""
return
dict
(
_started
)
Back
|
FazBrowse Home
|
New Git URL