sketchingpy

Entrypoint for the sketchingpy library.

Entrypoint for the sketchingpy library which includes the logic for the auto-renderer selection for Sketch2D.

License:

BSD

 1"""Entrypoint for the sketchingpy library.
 2
 3Entrypoint for the sketchingpy library which includes the logic for the auto-renderer selection for
 4Sketch2D.
 5
 6License:
 7    BSD
 8"""
 9
10import os
11import typing
12
13import sketchingpy.abstracted
14
15NOT_FOUND_MSG = 'Could not load a sketch backend. See https://sketchingpy.org/guides/start.html.'
16
17has_app = False
18has_static = False
19has_web = False
20in_notebook = False
21
22app_exception = None
23static_exception = None
24web_exception = None
25
26
27try:
28    from sketchingpy.sketch2dapp import Sketch2DApp
29    has_app = True
30except ModuleNotFoundError as e:
31    app_exception = e
32
33
34try:
35    from sketchingpy.sketch2dstatic import Sketch2DStatic
36    has_static = True
37except ModuleNotFoundError as e:
38    static_exception = e
39
40
41try:
42    from sketchingpy.sketch2dweb import Sketch2DWeb
43    has_web = True
44except ModuleNotFoundError as e:
45    web_exception = e
46
47
48try:
49    in_notebook = "JPY_PARENT_PID" in os.environ
50except:
51    pass
52
53
54Sketch2D: typing.TypeAlias = sketchingpy.abstracted.Sketch
55
56if in_notebook:
57    Sketch2D = Sketch2DStatic  # type: ignore
58elif has_app:
59    Sketch2D = Sketch2DApp  # type: ignore
60elif has_static:
61    Sketch2D = Sketch2DStatic  # type: ignore
62elif has_web:
63    Sketch2D = Sketch2DWeb  # type: ignore
64else:
65    print('Failed to load runtime. Debugging:')
66    print('App: ' + str(app_exception))
67    print('Static: ' + str(static_exception))
68    print('Web: ' + str(web_exception))
69    raise RuntimeError(NOT_FOUND_MSG)
NOT_FOUND_MSG = 'Could not load a sketch backend. See https://sketchingpy.org/guides/start.html.'
has_app = True
has_static = True
has_web = True
in_notebook = False
app_exception = None
static_exception = None
web_exception = None
Sketch2D: TypeAlias = sketchingpy.sketch2dapp.Sketch2DApp