openrewrite-remote 0.13.4__py3-none-any.whl → 0.14.0__py3-none-any.whl

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.
rewrite_remote/server.py CHANGED
@@ -2,18 +2,15 @@
2
2
  import importlib
3
3
  import importlib.resources
4
4
  import os
5
- import select
6
5
  import socket
7
6
  import sys
8
7
  import time
9
8
  import traceback
10
9
  import zipfile
11
10
  from io import BytesIO, StringIO
12
- from pathlib import Path
13
- from typing import Any
14
- from typing import Optional
15
11
 
16
12
  import cbor2
13
+ import select
17
14
  from cbor2 import dumps
18
15
  from rewrite import (
19
16
  ParserInput,
@@ -22,7 +19,6 @@ from rewrite import (
22
19
  ParseError,
23
20
  Recipe,
24
21
  )
25
- from rewrite.java import J
26
22
  from rewrite.java.remote import *
27
23
  from rewrite.python import Py
28
24
  from rewrite.python.parser import PythonParserBuilder
@@ -30,12 +26,17 @@ from rewrite.python.remote.receiver import PythonReceiver
30
26
  from rewrite.python.remote.sender import PythonSender
31
27
 
32
28
  from rewrite_remote.handlers.hello_world_handler import hello_world_handler
33
- from rewrite_remote.handlers.recipe_install_handler import recipe_install_handler
29
+ from rewrite_remote.handlers.list_projects_handler import list_projects_handler
30
+ from rewrite_remote.handlers.parse_project_sources_handler import (
31
+ parse_project_sources_handler,
32
+ )
33
+ from rewrite_remote.handlers.project_helper import read_file_contents
34
+ from rewrite_remote.handlers.recipe_install_handler import (
35
+ recipe_install_handler,
36
+ )
34
37
  from rewrite_remote.handlers.run_recipe_load_and_visitor_handler import (
35
38
  run_recipe_load_and_visitor_handler,
36
39
  )
37
- from rewrite_remote.handlers.list_projects_handler import list_projects_handler
38
-
39
40
  from rewrite_remote.receiver import ReceiverContext
40
41
  from rewrite_remote.remoting import (
41
42
  RemotePrinterFactory,
@@ -86,9 +87,7 @@ class Server:
86
87
  self._path = path
87
88
  self.timeout = timeout
88
89
  self._remoting_context = RemotingContext()
89
- self._remoting_context._recipe_factories["test"] = (
90
- lambda recipe_options: Recipe()
91
- )
90
+ self._remoting_context._recipe_factories["test"] = lambda recipe_options: Recipe()
92
91
  self._messenger = RemotingMessenger(
93
92
  self._remoting_context,
94
93
  {
@@ -98,6 +97,7 @@ class Server:
98
97
  "recipe-install": recipe_install_handler,
99
98
  "run-recipe-load-and-visitor": run_recipe_load_and_visitor_handler,
100
99
  "list-projects": list_projects_handler,
100
+ "parse-project-sources": parse_project_sources_handler,
101
101
  },
102
102
  )
103
103
 
@@ -132,9 +132,7 @@ class Server:
132
132
  except socket.timeout:
133
133
  current_time = time.time()
134
134
  if current_time - last_activity_time >= self.timeout:
135
- print(
136
- "No new connections for 5 minutes, shutting down server."
137
- )
135
+ print("No new connections for 5 minutes, shutting down server.")
138
136
  break
139
137
 
140
138
  def handle_client(self, sock: socket.socket) -> None:
@@ -175,7 +173,10 @@ class Server:
175
173
  sock.close()
176
174
 
177
175
  def parse_python_source(
178
- self, stream: BytesIO, sock: socket.socket, remoting_ctx: RemotingContext
176
+ self,
177
+ stream: BytesIO,
178
+ sock: socket.socket,
179
+ remoting_ctx: RemotingContext,
179
180
  ) -> None:
180
181
  remoting_ctx.reset()
181
182
  source = cbor2.load(stream)
@@ -199,7 +200,10 @@ class Server:
199
200
  sock.sendall(response_stream.getvalue())
200
201
 
201
202
  def parse_python_file(
202
- self, stream: BytesIO, sock: socket.socket, remoting_ctx: RemotingContext
203
+ self,
204
+ stream: BytesIO,
205
+ sock: socket.socket,
206
+ remoting_ctx: RemotingContext,
203
207
  ) -> None:
204
208
  remoting_ctx.reset()
205
209
  path = cbor2.load(stream)
@@ -209,7 +213,14 @@ class Server:
209
213
  PythonParserBuilder()
210
214
  .build()
211
215
  .parse_inputs(
212
- [ParserInput(Path(path), None, True, lambda: read_file_contents(path))],
216
+ [
217
+ ParserInput(
218
+ Path(path),
219
+ None,
220
+ True,
221
+ lambda: read_file_contents(path),
222
+ )
223
+ ],
213
224
  None,
214
225
  ctx,
215
226
  )
@@ -223,11 +234,6 @@ class Server:
223
234
  sock.sendall(response_stream.getvalue())
224
235
 
225
236
 
226
- def read_file_contents(path: str) -> StringIO:
227
- with open(path, "r", newline="", encoding="utf-8") as file:
228
- return StringIO(file.read())
229
-
230
-
231
237
  def read_data_from_zip() -> None:
232
238
  # Access the resource within the 'your_package.resources' package
233
239
  # 'data.zip' is the name of the file included
@@ -1,8 +1,9 @@
1
+ import importlib
1
2
  import typing
2
- from typing import Optional
3
3
  from dataclasses import Field
4
4
  from functools import lru_cache
5
5
  from typing import Any, Type
6
+ from typing import Optional
6
7
 
7
8
 
8
9
  def to_java_type_name_from_value(v: Any) -> Optional[str]:
@@ -106,4 +107,7 @@ def __convert_snake_to_camel(field_name: str) -> str:
106
107
 
107
108
 
108
109
  def get_type(type_name: str) -> Type[Any]:
109
- raise NotImplementedError("get_type for: " + type_name)
110
+ # `type_name` will look like `org.openrewrite.java.tree.J$CompilationUnit`
111
+ parts = type_name.split('.')
112
+ module = importlib.import_module('rewrite.' + parts[2])
113
+ return getattr(module, parts[-1].split('$')[1])
@@ -1,23 +0,0 @@
1
- rewrite_remote/__init__.py,sha256=uuLrPH--ewvE-5owXbNItXDfjCypMXQgsm-72hO_dtc,286
2
- rewrite_remote/client.py,sha256=95ZCAtVOngF0ZqqKnOsrweUeGKruf3UKGPXNGTrNyy0,1853
3
- rewrite_remote/event.py,sha256=texLJD1mcFkpBpiXAa-Rmip0Tgqm2OlBpRPHFZyWcBs,359
4
- rewrite_remote/receiver.py,sha256=9oIdupOcV9z6eY-c2uFL1yfujbTQTgbXgTPG9Qx_ipc,20008
5
- rewrite_remote/remote_utils.py,sha256=wUo9WZoldgCLihFJGf6RaE1SufhDiEPCFlX74tcODVM,10552
6
- rewrite_remote/remoting.py,sha256=s0qVJlKTKhLZw8-9CJB1dJ4sPeKVkwIldI2WYEGULHY,13365
7
- rewrite_remote/sender.py,sha256=z42hmAIXai_dazQ-DhMwv_fDSi0AA2orUT2juWX2UJg,20056
8
- rewrite_remote/server.py,sha256=LDk4mUs33DX1s8HMCh3rC5lkpN8luyDu1CLeDQXczlY,9343
9
- rewrite_remote/type_utils.py,sha256=oVrB0olWFSCqhmg2nTU2wrwiAU7kBCUscjwdHK7gf3Y,4219
10
- rewrite_remote/handlers/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
11
- rewrite_remote/handlers/handler_helpers.py,sha256=CIAXtlzrsE-z5RmzlXBZihT1rfrRLHFttq8Ni_8AH9U,516
12
- rewrite_remote/handlers/hello_world_handler.py,sha256=NQScHfCJKofdImBgELL8tXtG_KnVyXj683C3Ae7xcKU,1298
13
- rewrite_remote/handlers/list_projects_handler.py,sha256=ukkCST7whpCxQ0omCWWw9W27Su3rFSnnEIhAS6T4iOU,2007
14
- rewrite_remote/handlers/project_helper.py,sha256=_zGzniyEgmBB4k14Oy4Sm7B3Lt1MoXKQLOJxofEELGI,7130
15
- rewrite_remote/handlers/pypi_manager.py,sha256=z4JJarLkNRztQaSLHCh5GViag7ce7E36ARBDqJLQREc,10269
16
- rewrite_remote/handlers/recipe_install_handler.py,sha256=D6n5d84pS-HBWNiND-qZt-SfB33uFHV0ntZf2ZQ1Imo,4942
17
- rewrite_remote/handlers/run_recipe_load_and_visitor_handler.py,sha256=Pppn90g2z0z3U9m4_3a3X9Wu0Qh_pvkhoxWgadjAHRs,4146
18
- rewrite_remote/handlers/types.py,sha256=5TK_oFp-7iy1iACWisuQJsa_WHTsqcPrV9nQTZ-_xgo,518
19
- openrewrite_remote-0.13.4.dist-info/METADATA,sha256=jL-ze_dwxBxu6JQADFZO2s_QJLF7IxPJwEQdU1pTLaI,386
20
- openrewrite_remote-0.13.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
- openrewrite_remote-0.13.4.dist-info/entry_points.txt,sha256=SMukuF7TPjQr3IZIcH8f98-_QBCqYSbYXYrVv-5UzRI,69
22
- openrewrite_remote-0.13.4.dist-info/top_level.txt,sha256=ansTioSZ-62aH3F2L3d1Bua0pJF4GOtgQ1PpG-CzcP0,15
23
- openrewrite_remote-0.13.4.dist-info/RECORD,,