openrewrite-remote 0.12.0__tar.gz → 0.13.0__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. openrewrite_remote-0.13.0/PKG-INFO +12 -0
  2. openrewrite_remote-0.13.0/README.md +142 -0
  3. openrewrite_remote-0.13.0/openrewrite_remote.egg-info/PKG-INFO +12 -0
  4. openrewrite_remote-0.13.0/openrewrite_remote.egg-info/SOURCES.txt +17 -0
  5. openrewrite_remote-0.13.0/openrewrite_remote.egg-info/dependency_links.txt +1 -0
  6. openrewrite_remote-0.13.0/openrewrite_remote.egg-info/entry_points.txt +2 -0
  7. openrewrite_remote-0.13.0/openrewrite_remote.egg-info/requires.txt +5 -0
  8. openrewrite_remote-0.13.0/openrewrite_remote.egg-info/top_level.txt +1 -0
  9. openrewrite_remote-0.13.0/pyproject.toml +41 -0
  10. openrewrite_remote-0.13.0/rewrite_remote/__init__.py +12 -0
  11. openrewrite_remote-0.13.0/rewrite_remote/client.py +70 -0
  12. {openrewrite_remote-0.12.0/rewrite/remote → openrewrite_remote-0.13.0/rewrite_remote}/event.py +2 -2
  13. {openrewrite_remote-0.12.0/rewrite/remote → openrewrite_remote-0.13.0/rewrite_remote}/receiver.py +245 -88
  14. {openrewrite_remote-0.12.0/rewrite/remote → openrewrite_remote-0.13.0/rewrite_remote}/remote_utils.py +78 -40
  15. {openrewrite_remote-0.12.0/rewrite/remote → openrewrite_remote-0.13.0/rewrite_remote}/remoting.py +116 -44
  16. {openrewrite_remote-0.12.0/rewrite/remote → openrewrite_remote-0.13.0/rewrite_remote}/sender.py +222 -90
  17. {openrewrite_remote-0.12.0/rewrite/remote → openrewrite_remote-0.13.0/rewrite_remote}/server.py +100 -36
  18. openrewrite_remote-0.13.0/rewrite_remote/type_utils.py +109 -0
  19. openrewrite_remote-0.13.0/setup.cfg +4 -0
  20. openrewrite_remote-0.12.0/PKG-INFO +0 -17
  21. openrewrite_remote-0.12.0/pyproject.toml +0 -37
  22. openrewrite_remote-0.12.0/rewrite/remote/__init__.py +0 -7
  23. openrewrite_remote-0.12.0/rewrite/remote/client.py +0 -40
  24. openrewrite_remote-0.12.0/rewrite/remote/type_utils.py +0 -101
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: openrewrite-remote
3
+ Version: 0.13.0
4
+ Summary: Remoting functionality for the OpenRewrite library.
5
+ Author-email: "Moderne Inc." <support@moderne.io>
6
+ License: Moderne, Inc. Commercial License
7
+ Requires-Python: <4,>=3.9
8
+ Requires-Dist: cbor2==5.6.5
9
+ Requires-Dist: openrewrite
10
+ Requires-Dist: pip>=24.3.1
11
+ Requires-Dist: pypi-simple>=1.6.1
12
+ Requires-Dist: toml>=0.10.2
@@ -0,0 +1,142 @@
1
+ # Python remoting server
2
+
3
+ ## Overview
4
+
5
+ This project provide remote services for working with OpenRewrite and is published as `openrewrite-remote` in [PyPi](https://pypi.org/project/openrewrite-remote/). This package serves as an openrewrite remoting server for the python language.
6
+ Example:
7
+
8
+ ```mermaid
9
+ sequenceDiagram
10
+ participant Client as Java client
11
+ participant Server as Language Specific Remote Server
12
+
13
+ Client->>Server: Connect to server
14
+ Server-->>Client: Acknowledge connection
15
+
16
+ Client->>Server: Send command (e.g., hello)
17
+ Server->>Server: Process command
18
+ Server-->>Client: Send response (e.g., OK)
19
+
20
+ Client->>Server: Send command (e.g., load-recipe)
21
+ Server->>Server: Process command
22
+ Server-->>Client: Send response (e.g., recipe loaded)
23
+
24
+ Client->>Server: Send command (e.g., run-recipe-visitor)
25
+ Server->>Server: Process command
26
+ Server-->>Client: Send response (e.g., visitor result)
27
+
28
+ Client->>Server: Disconnect
29
+ Server-->>Client: Acknowledge disconnection
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ ### Install the published package on PyPi
35
+
36
+ Install and use the remoting server from another project:
37
+
38
+ ```bash
39
+ pip install openrewrite-remote
40
+ ```
41
+
42
+ ### Install the package from source
43
+
44
+ ### Fast way using `uv`
45
+
46
+ Install [uv](https://github.com/astral-sh/uv)
47
+
48
+ and then run:
49
+
50
+ ```bash
51
+ uv sync --all-extras
52
+ source .venv/bin/activate
53
+ ```
54
+
55
+ ### Long way using `pyenv` and `pip`
56
+
57
+ #### Use the correct python version
58
+
59
+ Install `pyenv`:
60
+
61
+ ```bash
62
+ brew install pyenv
63
+ ```
64
+
65
+ Use `pyenv` to install the required python version:
66
+
67
+ ```bash
68
+ pyenv install
69
+ ```
70
+
71
+ If this is your first time using pyenv then do:
72
+
73
+ ```bash
74
+ pyenv init
75
+ ```
76
+
77
+ and follow instructions to add the necessary lines to your shell profile.
78
+
79
+ #### Create a virtual environment
80
+
81
+ Virtual environments are used to isolate the dependencies of a project from the
82
+ system's python installation.
83
+
84
+ Remove any old virtual environment
85
+
86
+ ```bash
87
+ rm -rf .venv
88
+ ```
89
+
90
+ Create a new virtual environment
91
+
92
+ ```bash
93
+ python3 -m venv .venv
94
+ source .venv/bin/activate
95
+ ```
96
+
97
+ #### Install dependencies using PIP
98
+
99
+ Install project dependencies:
100
+
101
+ ```bash
102
+ pip install .
103
+ ```
104
+
105
+ Install the development dependencies:
106
+
107
+ ```bash
108
+ pip install ".[dev]"
109
+ ```
110
+
111
+ #### (Optional) Link local openrewrite package
112
+
113
+ If you plan to modify the openrewrite package locally and want those changes to
114
+ reflect immediately without reinstalling, you can install the dependency in
115
+ editable mode:
116
+
117
+ ```bash
118
+ pip install -e ../path/to/local/openrewrite
119
+ ```
120
+
121
+ when using uv prefix the command with `uv`:
122
+
123
+ ```bash
124
+ uv pip install -e ../path/to/local/openrewrite
125
+ ```
126
+
127
+ #### Build the project
128
+
129
+ Build the project (wheel and tarball):
130
+
131
+ ```bash
132
+ python build
133
+ ```
134
+
135
+ ### Starting the server:
136
+
137
+ Installing the module should also make the executable `start_python_remoting`
138
+ available to start the server.
139
+
140
+ ```bash
141
+ start_python_remoting
142
+ ```
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: openrewrite-remote
3
+ Version: 0.13.0
4
+ Summary: Remoting functionality for the OpenRewrite library.
5
+ Author-email: "Moderne Inc." <support@moderne.io>
6
+ License: Moderne, Inc. Commercial License
7
+ Requires-Python: <4,>=3.9
8
+ Requires-Dist: cbor2==5.6.5
9
+ Requires-Dist: openrewrite
10
+ Requires-Dist: pip>=24.3.1
11
+ Requires-Dist: pypi-simple>=1.6.1
12
+ Requires-Dist: toml>=0.10.2
@@ -0,0 +1,17 @@
1
+ README.md
2
+ pyproject.toml
3
+ openrewrite_remote.egg-info/PKG-INFO
4
+ openrewrite_remote.egg-info/SOURCES.txt
5
+ openrewrite_remote.egg-info/dependency_links.txt
6
+ openrewrite_remote.egg-info/entry_points.txt
7
+ openrewrite_remote.egg-info/requires.txt
8
+ openrewrite_remote.egg-info/top_level.txt
9
+ rewrite_remote/__init__.py
10
+ rewrite_remote/client.py
11
+ rewrite_remote/event.py
12
+ rewrite_remote/receiver.py
13
+ rewrite_remote/remote_utils.py
14
+ rewrite_remote/remoting.py
15
+ rewrite_remote/sender.py
16
+ rewrite_remote/server.py
17
+ rewrite_remote/type_utils.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ start_python_remoting = rewrite_remote.server:main
@@ -0,0 +1,5 @@
1
+ cbor2==5.6.5
2
+ openrewrite
3
+ pip>=24.3.1
4
+ pypi-simple>=1.6.1
5
+ toml>=0.10.2
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "openrewrite-remote"
7
+ description = "Remoting functionality for the OpenRewrite library."
8
+ version = "0.13.0" # Updated dynamically during release
9
+ authors = [{ name = "Moderne Inc.", email = "support@moderne.io" }]
10
+ license = { text = "Moderne, Inc. Commercial License" }
11
+ dependencies = [
12
+ "cbor2==5.6.5",
13
+ "openrewrite",
14
+ "pip>=24.3.1",
15
+ "pypi-simple>=1.6.1",
16
+ "toml>=0.10.2",
17
+ ]
18
+ requires-python = ">=3.9, <4"
19
+
20
+ [tool.setuptools.packages.find]
21
+ include = ["rewrite_remote"]
22
+ exclude = []
23
+
24
+ [dependency-groups]
25
+ dev = [
26
+ "pytest==8.3.4",
27
+ "pytest-asyncio==0.24.0",
28
+ "mypy==1.13.0",
29
+ "poethepoet==0.31.1",
30
+ "black==24.10.0",
31
+ "pylint==3.3.2",
32
+ ]
33
+
34
+ [project.scripts]
35
+ start_python_remoting = "rewrite_remote.server:main"
36
+
37
+ [tool.poe.tasks]
38
+ check-types = "mypy ./rewrite_remote"
39
+ format = "black ./rewrite_remote ./tests"
40
+ test = "pytest"
41
+ lint = "pylint ./rewrite_remote/**/*.py ./tests/**/*.py"
@@ -0,0 +1,12 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
2
+ from typing import TypeVar
3
+
4
+ from .receiver import *
5
+ from .sender import *
6
+ from .remoting import *
7
+
8
+ __all__ = [
9
+ name
10
+ for name in dir()
11
+ if not name.startswith("_") and not isinstance(globals()[name], TypeVar)
12
+ ]
@@ -0,0 +1,70 @@
1
+ import socket
2
+ import tempfile
3
+ from pathlib import Path
4
+
5
+ import rewrite.java.tree as j
6
+ import rewrite.python.tree as py
7
+ from rewrite import Markers
8
+ from rewrite import random_id, Cursor, PrintOutputCapture
9
+ from rewrite.java import Space, JavaType
10
+ from rewrite.python import Py
11
+ from rewrite.python.remote.receiver import PythonReceiver
12
+ from rewrite.python.remote.sender import PythonSender
13
+
14
+ from .receiver import ReceiverContext
15
+ from .remoting import (
16
+ RemotingContext,
17
+ RemotePrinterFactory,
18
+ )
19
+ from .sender import SenderContext
20
+
21
+ SenderContext.register(Py, lambda: PythonSender())
22
+ ReceiverContext.register(Py, lambda: PythonReceiver())
23
+
24
+ # Path to the Unix domain socket
25
+ SOCKET_PATH = tempfile.gettempdir() + "/rewrite-java.sock"
26
+
27
+ # Create a Unix domain socket
28
+ client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
29
+
30
+ # Connect the socket to the path where the server is listening
31
+ client.connect(("localhost", 65432))
32
+ print(f"Connected to {SOCKET_PATH}")
33
+
34
+ try:
35
+ remoting = RemotingContext()
36
+ remoting.connect(client)
37
+ RemotePrinterFactory(remoting.client).set_current()
38
+
39
+ literal = j.Literal(
40
+ random_id(),
41
+ Space.SINGLE_SPACE,
42
+ Markers.EMPTY,
43
+ True,
44
+ "True",
45
+ None,
46
+ JavaType.Primitive(),
47
+ )
48
+ assert_ = py.AssertStatement(
49
+ random_id(),
50
+ Space.EMPTY,
51
+ Markers.EMPTY,
52
+ [j.JRightPadded(literal, Space.EMPTY, Markers.EMPTY)],
53
+ )
54
+ cu = py.CompilationUnit(
55
+ random_id(),
56
+ Space.EMPTY,
57
+ Markers.EMPTY,
58
+ Path("/foo.py"),
59
+ None,
60
+ None,
61
+ False,
62
+ None,
63
+ [],
64
+ [j.JRightPadded(assert_, Space.EMPTY, Markers.EMPTY)],
65
+ Space.EMPTY,
66
+ )
67
+ printed = cu.print(Cursor(None, Cursor.ROOT_VALUE), PrintOutputCapture(0))
68
+ assert printed == "assert True"
69
+ finally:
70
+ client.close()
@@ -1,6 +1,6 @@
1
1
  from dataclasses import dataclass
2
2
  from enum import Enum
3
- from typing import Optional
3
+ from typing import Optional, Any
4
4
 
5
5
 
6
6
  class EventType(Enum):
@@ -17,4 +17,4 @@ class EventType(Enum):
17
17
  class DiffEvent:
18
18
  event_type: EventType
19
19
  concrete_type: Optional[str] = None
20
- msg: Optional[any] = None
20
+ msg: Optional[Any] = None