ocp-vscode 2.3.0__tar.gz → 2.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/PKG-INFO +3 -3
  2. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/README.md +12 -4
  3. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/__init__.py +12 -8
  4. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/comms.py +11 -5
  5. ocp_vscode-2.3.2/ocp_vscode/daemonize.py +199 -0
  6. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/show.py +0 -22
  7. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode.egg-info/PKG-INFO +3 -3
  8. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode.egg-info/SOURCES.txt +1 -0
  9. ocp_vscode-2.3.2/ocp_vscode.egg-info/requires.txt +5 -0
  10. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/setup.cfg +1 -1
  11. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/setup.py +3 -3
  12. ocp_vscode-2.3.0/ocp_vscode.egg-info/requires.txt +0 -5
  13. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/LICENSE +0 -0
  14. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/animation.py +0 -0
  15. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/backend.py +0 -0
  16. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/build123d.py +0 -0
  17. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/colors.py +0 -0
  18. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/config.py +0 -0
  19. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode/state.py +0 -0
  20. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode.egg-info/dependency_links.txt +0 -0
  21. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode.egg-info/not-zip-safe +0 -0
  22. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/ocp_vscode.egg-info/top_level.txt +0 -0
  23. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/test/test_for_backend.py +0 -0
  24. {ocp_vscode-2.3.0 → ocp_vscode-2.3.2}/test/testextension.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ocp_vscode
3
- Version: 2.3.0
3
+ Version: 2.3.2
4
4
  Summary: OCP CAD Viewer for VSCode
5
5
  Home-page: https://github.com/bernhard-42/vscode-ocp-cad-viewer
6
6
  Author: Bernhard Walter
@@ -17,10 +17,10 @@ Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
18
  Requires-Python: >=3.9
19
19
  License-File: LICENSE
20
- Requires-Dist: ocp-tessellate<2.4.0,>=2.3.0
20
+ Requires-Dist: ocp-tessellate<2.4.0,>=2.3.2
21
21
  Requires-Dist: requests
22
22
  Requires-Dist: ipykernel
23
23
  Requires-Dist: orjson
24
- Requires-Dist: websockets<11.1,>=11.0
24
+ Requires-Dist: websockets>=12.0
25
25
 
26
26
  An extension to show OCP cad CAD objects (CadQuery, build123d) in VS Code via threejs
@@ -21,7 +21,7 @@ _OCP CAD Viewer_ for VS Code is an extension to show [CadQuery](https://github.c
21
21
 
22
22
  ### Installation
23
23
 
24
- 1. Open the VS Code Marketplace, and search and install _OCP CAD Viewer 2.2.1_.
24
+ 1. Open the VS Code Marketplace, and search and install _OCP CAD Viewer 2.3.2_.
25
25
 
26
26
  Afterwards the OCP viewer is available in the VS Code sidebar:
27
27
 
@@ -202,10 +202,18 @@ NATIVE_TESSELLATOR=1 OCP_VSCODE_PYTEST=1 pytest -v -s pytests/
202
202
 
203
203
  ## Changes
204
204
 
205
+ v2.3.2
206
+ - Fix regression that Python script hang in threading before exit ([#73](https://github.com/bernhard-42/vscode-ocp-cad-viewer/issues/60))
207
+
208
+ v2.3.1
209
+ - Add latest ocp-tessellate to fixed regression with handling instances
210
+ - Make native default if ocp-addons exists
211
+
205
212
  v2.3.0
206
- - Add newest ocp-tessellate to allow using native tessellator from ocp_addons
207
- - Fine tune communication to ensure the memory view of buffers will be passed through to javascript for performance
208
- - Use of the new protocol v3 of three-cad-viewer
213
+ Fine tune communication to ensure the memory view of buffers will be passed through to javascript for performance (*)
214
+ Use of the new protocol v3 of three-cad-viewer
215
+ Fix show_all regressions https://github.com/bernhard-42/vscode-ocp-cad-viewer/issues/71. It should also properly catch exceptions now to not interrupt viausl debugging
216
+ Add newest ocp-tessellate to allow using native tessellator from ocp_addons
209
217
 
210
218
  v2.2.2
211
219
  - Fix regression in measure tools
@@ -15,7 +15,9 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
- __version__ = "2.3.0"
18
+ __version__ = "2.3.2"
19
+
20
+ import os
19
21
 
20
22
  from .show import *
21
23
  from .config import *
@@ -32,13 +34,15 @@ try:
32
34
  is_native_tessellator_enabled,
33
35
  )
34
36
 
35
- if is_native_tessellator_enabled():
36
- print(
37
- "Enabled native tessellator, to disable, call `disable_native_tessellator()`\n"
38
- )
37
+ if os.environ.get("NATIVE_TESSELLATOR") == "0":
38
+ disable_native_tessellator()
39
39
  else:
40
- print(
41
- "Found native tessellator, to ansable, call `enable_native_tessellator()`\n"
42
- )
40
+ enable_native_tessellator()
41
+
42
+ print(
43
+ "Found and enabled native tessellator.\n"
44
+ "To disable, call `disable_native_tessellator()`\n"
45
+ "To enable, call `enable_native_tessellator()`\n"
46
+ )
43
47
  except:
44
48
  pass
@@ -8,7 +8,10 @@ import socket
8
8
 
9
9
  from pathlib import Path
10
10
 
11
- from websockets.sync.client import connect
11
+ # TODO:
12
+ # As soon as websockets 12.1 is released, replace with
13
+ # "from websockets.sync.client import connect"
14
+ from .daemonize import connect
12
15
 
13
16
  import orjson
14
17
  from ocp_tessellate.utils import Timer
@@ -34,7 +37,7 @@ CMD_URL = "ws://127.0.0.1"
34
37
  CMD_PORT = 3939
35
38
 
36
39
  INIT_DONE = False
37
-
40
+ WS = None
38
41
 
39
42
  #
40
43
  # Send data to the viewer
@@ -110,6 +113,8 @@ def set_port(port):
110
113
 
111
114
  def _send(data, message_type, port=None, timeit=False):
112
115
  """Send data to the viewer"""
116
+ global WS
117
+
113
118
  if port is None:
114
119
  if not INIT_DONE:
115
120
  find_and_set_port()
@@ -132,13 +137,14 @@ def _send(data, message_type, port=None, timeit=False):
132
137
  j = b"S:" + j
133
138
 
134
139
  with Timer(timeit, "", f"websocket send {len(j)/1024/1024:.3f} MB", 1):
135
- ws = connect(f"{CMD_URL}:{port}")
136
- ws.send(j)
140
+ if WS is None:
141
+ WS = connect(f"{CMD_URL}:{port}")
142
+ WS.send(j)
137
143
 
138
144
  result = None
139
145
  if message_type == MessageType.COMMAND:
140
146
  try:
141
- result = json.loads(ws.recv())
147
+ result = json.loads(WS.recv())
142
148
  except Exception as ex: # pylint: disable=broad-except
143
149
  print(ex)
144
150
 
@@ -0,0 +1,199 @@
1
+ # Copyright (c) Aymeric Augustin and contributors
2
+ # see https://github.com/python-websockets/websockets/blob/main/LICENSE
3
+
4
+ import logging
5
+ import socket
6
+ import threading
7
+ import uuid
8
+ from typing import Optional, Dict
9
+
10
+ from websockets.sync.client import ClientProtocol, connect as _connect
11
+ from websockets.sync.connection import Connection
12
+ from websockets.sync.messages import Assembler
13
+ from websockets.sync.utils import Deadline
14
+ from websockets.datastructures import HeadersLike
15
+ from websockets.protocol import Protocol
16
+ from websockets.http import USER_AGENT
17
+ from websockets.http11 import Request, Response
18
+ from websockets.protocol import CONNECTING, OPEN, Event
19
+ from websockets.typing import LoggerLike
20
+
21
+
22
+ class DaemonConnection(Connection):
23
+ """
24
+ Threaded implementation of a WebSocket connection.
25
+
26
+ :class:`Connection` provides APIs shared between WebSocket servers and
27
+ clients.
28
+
29
+ You shouldn't use it directly. Instead, use
30
+ :class:`~websockets.sync.client.ClientConnection` or
31
+ :class:`~websockets.sync.server.ServerConnection`.
32
+
33
+ """
34
+
35
+ recv_bufsize = 65536
36
+
37
+ def __init__(
38
+ self,
39
+ socket: socket.socket,
40
+ protocol: Protocol,
41
+ *,
42
+ close_timeout: Optional[float] = 10,
43
+ ) -> None:
44
+ self.socket = socket
45
+ self.protocol = protocol
46
+ self.close_timeout = close_timeout
47
+
48
+ # Inject reference to this instance in the protocol's logger.
49
+ self.protocol.logger = logging.LoggerAdapter(
50
+ self.protocol.logger,
51
+ {"websocket": self},
52
+ )
53
+
54
+ # Copy attributes from the protocol for convenience.
55
+ self.id: uuid.UUID = self.protocol.id
56
+ """Unique identifier of the connection. Useful in logs."""
57
+ self.logger: LoggerLike = self.protocol.logger
58
+ """Logger for this connection."""
59
+ self.debug = self.protocol.debug
60
+
61
+ # HTTP handshake request and response.
62
+ self.request: Optional[Request] = None
63
+ """Opening handshake request."""
64
+ self.response: Optional[Response] = None
65
+ """Opening handshake response."""
66
+
67
+ # Mutex serializing interactions with the protocol.
68
+ self.protocol_mutex = threading.Lock()
69
+
70
+ # Assembler turning frames into messages and serializing reads.
71
+ self.recv_messages = Assembler()
72
+
73
+ # Whether we are busy sending a fragmented message.
74
+ self.send_in_progress = False
75
+
76
+ # Deadline for the closing handshake.
77
+ self.close_deadline: Optional[Deadline] = None
78
+
79
+ # Mapping of ping IDs to pong waiters, in chronological order.
80
+ self.pings: Dict[bytes, threading.Event] = {}
81
+
82
+ # Receiving events from the socket.
83
+
84
+ # !!! Start patch based on 12.0 (this is the only patched line) !!!
85
+ # self.recv_events_thread = threading.Thread(target=self.recv_events)
86
+ self.recv_events_thread = threading.Thread(target=self.recv_events, daemon=True)
87
+ # !!! End patch !!!
88
+
89
+ self.recv_events_thread.start()
90
+
91
+ # Exception raised in recv_events, to be chained to ConnectionClosed
92
+ # in the user thread in order to show why the TCP connection dropped.
93
+ self.recv_events_exc: Optional[BaseException] = None
94
+
95
+
96
+ class DaemonClientConnection(DaemonConnection):
97
+ """
98
+ Threaded implementation of a WebSocket client connection.
99
+
100
+ :class:`ClientConnection` provides :meth:`recv` and :meth:`send` methods for
101
+ receiving and sending messages.
102
+
103
+ It supports iteration to receive messages::
104
+
105
+ for message in websocket:
106
+ process(message)
107
+
108
+ The iterator exits normally when the connection is closed with close code
109
+ 1000 (OK) or 1001 (going away) or without a close code. It raises a
110
+ :exc:`~websockets.exceptions.ConnectionClosedError` when the connection is
111
+ closed with any other code.
112
+
113
+ Args:
114
+ socket: Socket connected to a WebSocket server.
115
+ protocol: Sans-I/O connection.
116
+ close_timeout: Timeout for closing the connection in seconds.
117
+
118
+ """
119
+
120
+ def __init__(
121
+ self,
122
+ socket: socket.socket,
123
+ protocol: ClientProtocol,
124
+ *,
125
+ close_timeout: Optional[float] = 10,
126
+ ) -> None:
127
+ self.protocol: ClientProtocol
128
+ self.response_rcvd = threading.Event()
129
+ super().__init__(
130
+ socket,
131
+ protocol,
132
+ close_timeout=close_timeout,
133
+ )
134
+
135
+ def handshake(
136
+ self,
137
+ additional_headers: Optional[HeadersLike] = None,
138
+ user_agent_header: Optional[str] = USER_AGENT,
139
+ timeout: Optional[float] = None,
140
+ ) -> None:
141
+ """
142
+ Perform the opening handshake.
143
+
144
+ """
145
+ with self.send_context(expected_state=CONNECTING):
146
+ self.request = self.protocol.connect()
147
+ if additional_headers is not None:
148
+ self.request.headers.update(additional_headers)
149
+ if user_agent_header is not None:
150
+ self.request.headers["User-Agent"] = user_agent_header
151
+ self.protocol.send_request(self.request)
152
+
153
+ if not self.response_rcvd.wait(timeout):
154
+ self.close_socket()
155
+ self.recv_events_thread.join()
156
+ raise TimeoutError("timed out during handshake")
157
+
158
+ if self.response is None:
159
+ self.close_socket()
160
+ self.recv_events_thread.join()
161
+ raise ConnectionError("connection closed during handshake")
162
+
163
+ if self.protocol.state is not OPEN:
164
+ self.recv_events_thread.join(self.close_timeout)
165
+ self.close_socket()
166
+ self.recv_events_thread.join()
167
+
168
+ if self.protocol.handshake_exc is not None:
169
+ raise self.protocol.handshake_exc
170
+
171
+ def process_event(self, event: Event) -> None:
172
+ """
173
+ Process one incoming event.
174
+
175
+ """
176
+ # First event - handshake response.
177
+ if self.response is None:
178
+ assert isinstance(event, Response)
179
+ self.response = event
180
+ self.response_rcvd.set()
181
+ # Later events - frames.
182
+ else:
183
+ super().process_event(event)
184
+
185
+ def recv_events(self) -> None:
186
+ """
187
+ Read incoming data from the socket and process events.
188
+
189
+ """
190
+ try:
191
+ super().recv_events()
192
+ finally:
193
+ # If the connection is closed during the handshake, unblock it.
194
+ self.response_rcvd.set()
195
+
196
+
197
+ # Simple shim
198
+ def connect(url):
199
+ return _connect(url, create_connection=DaemonClientConnection)
@@ -26,7 +26,6 @@ from ocp_tessellate.convert import (
26
26
  get_normal_len,
27
27
  combined_bb,
28
28
  to_assembly,
29
- mp_get_results,
30
29
  conv,
31
30
  )
32
31
  from ocp_tessellate.utils import numpy_to_buffer_json, Timer, Color
@@ -42,7 +41,6 @@ from ocp_tessellate.ocp_utils import (
42
41
  is_wrapped,
43
42
  )
44
43
 
45
- from ocp_tessellate.mp_tessellator import init_pool, keymap, close_pool
46
44
  from ocp_tessellate.cad_objects import (
47
45
  OCP_PartGroup,
48
46
  OCP_Edges,
@@ -201,30 +199,14 @@ def _tessellate(
201
199
  continue
202
200
  params[k] = v
203
201
 
204
- parallel = preset("parallel", params.get("parallel"))
205
- if parallel and not any(
206
- [isinstance(obj, OCP_PartGroup) for obj in part_group.objects]
207
- ):
208
- print("parallel only works for assemblies, setting it to False")
209
- parallel = False
210
- params["parallel"] = False
211
-
212
202
  if kwargs.get("debug") is not None and kwargs["debug"]:
213
203
  print("\ntessellation parameters:\n", params)
214
204
 
215
205
  with Timer(timeit, "", "tessellate", 1):
216
- if parallel:
217
- init_pool()
218
- keymap.reset()
219
-
220
206
  instances, shapes, states, mapping = tessellate_group(
221
207
  part_group, instances, params, progress, params.get("timeit")
222
208
  )
223
209
 
224
- if parallel:
225
- instances, shapes = mp_get_results(instances, shapes, progress)
226
- close_pool()
227
-
228
210
  params["normal_len"] = get_normal_len(
229
211
  preset("render_normals", params.get("render_normals")),
230
212
  shapes,
@@ -383,7 +365,6 @@ def show(
383
365
  render_joints=None,
384
366
  show_parent=None,
385
367
  show_sketch_local=None,
386
- parallel=None,
387
368
  helper_scale=None,
388
369
  mate_scale=None, # DEPRECATED
389
370
  debug=None,
@@ -474,7 +455,6 @@ def show(
474
455
  render_normals: Render normals (default=False)
475
456
  render_mates: Render mates for MAssemblies (default=False)
476
457
  render_joints: Render build123d joints (default=False)
477
- parallel: Tessellate objects in parallel (default=False)
478
458
  show_parent: Render parent of faces, edges or vertices as wireframe (default=False)
479
459
  show_sketch_local: In build123d show local sketch in addition to relocate sketch (default=True)
480
460
  helper_scale: Scale of rendered helpers (locations, axis, mates for MAssemblies) (default=1)
@@ -642,7 +622,6 @@ def show_object(
642
622
  render_normals=None,
643
623
  render_mates=None,
644
624
  render_joints=None,
645
- parallel=None,
646
625
  show_parent=None,
647
626
  show_sketch_local=None,
648
627
  helper_scale=None,
@@ -739,7 +718,6 @@ def show_object(
739
718
  render_normals: Render normals (default=False)
740
719
  render_mates: Render mates for MAssemblies (default=False)
741
720
  render_joints: Render build123d joints (default=False)
742
- parallel: Tessellate objects in parallel (default=False)
743
721
  show_parent: Render parent of faces, edges or vertices as wireframe (default=False)
744
722
  show_sketch_local: In build123d show local sketch in addition to relocate sketch (default=True)
745
723
  helper_scale: Scale of rendered helpers (locations, axis, mates for MAssemblies) (default=1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ocp_vscode
3
- Version: 2.3.0
3
+ Version: 2.3.2
4
4
  Summary: OCP CAD Viewer for VSCode
5
5
  Home-page: https://github.com/bernhard-42/vscode-ocp-cad-viewer
6
6
  Author: Bernhard Walter
@@ -17,10 +17,10 @@ Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
18
  Requires-Python: >=3.9
19
19
  License-File: LICENSE
20
- Requires-Dist: ocp-tessellate<2.4.0,>=2.3.0
20
+ Requires-Dist: ocp-tessellate<2.4.0,>=2.3.2
21
21
  Requires-Dist: requests
22
22
  Requires-Dist: ipykernel
23
23
  Requires-Dist: orjson
24
- Requires-Dist: websockets<11.1,>=11.0
24
+ Requires-Dist: websockets>=12.0
25
25
 
26
26
  An extension to show OCP cad CAD objects (CadQuery, build123d) in VS Code via threejs
@@ -9,6 +9,7 @@ ocp_vscode/build123d.py
9
9
  ocp_vscode/colors.py
10
10
  ocp_vscode/comms.py
11
11
  ocp_vscode/config.py
12
+ ocp_vscode/daemonize.py
12
13
  ocp_vscode/show.py
13
14
  ocp_vscode/state.py
14
15
  ocp_vscode.egg-info/PKG-INFO
@@ -0,0 +1,5 @@
1
+ ocp-tessellate<2.4.0,>=2.3.2
2
+ requests
3
+ ipykernel
4
+ orjson
5
+ websockets>=12.0
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 2.3.0
2
+ current_version = 2.3.2
3
3
  commit = False
4
4
  tag = False
5
5
  parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?P<release>\D*)(?P<build>\d*)
@@ -2,17 +2,17 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup_args = {
4
4
  "name": "ocp_vscode",
5
- "version": "2.3.0",
5
+ "version": "2.3.2",
6
6
  "description": "OCP CAD Viewer for VSCode",
7
7
  "long_description": "An extension to show OCP cad CAD objects (CadQuery, build123d) in VS Code via threejs",
8
8
  "include_package_data": True,
9
9
  "python_requires": ">=3.9",
10
10
  "install_requires": [
11
- "ocp-tessellate>=2.3.0,<2.4.0",
11
+ "ocp-tessellate>=2.3.2,<2.4.0",
12
12
  "requests",
13
13
  "ipykernel",
14
14
  "orjson",
15
- "websockets>=11.0,<11.1",
15
+ "websockets>=12.0",
16
16
  ],
17
17
  "packages": find_packages(),
18
18
  "zip_safe": False,
@@ -1,5 +0,0 @@
1
- ocp-tessellate<2.4.0,>=2.3.0
2
- requests
3
- ipykernel
4
- orjson
5
- websockets<11.1,>=11.0
File without changes