generated from konveyor-ecosystem/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PyInstaller build spec + JSON RPC interface for client (#321)
* checkpoint Signed-off-by: Pranav Gaikwad <[email protected]> * checkpoint Signed-off-by: Pranav Gaikwad <[email protected]> * add JSON-RPC interface and PyInstaller build spec Signed-off-by: Pranav Gaikwad <[email protected]> checkpoint Signed-off-by: Pranav Gaikwad <[email protected]> * update README Signed-off-by: Pranav Gaikwad <[email protected]> * checkpoint: Signed-off-by: Pranav Gaikwad <[email protected]> * cleanup Signed-off-by: Pranav Gaikwad <[email protected]> --------- Signed-off-by: Pranav Gaikwad <[email protected]>
- Loading branch information
1 parent
1e0252c
commit 8863dd9
Showing
10 changed files
with
597 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/** | ||
node_modules/** | ||
package.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,86 @@ | ||
# Playpen | ||
|
||
Playpen is intended to be a location for exploring and sharing concepts. The material created under this directory may be broken and contain approaches that end up not being useful, or the material here may help to rapidly try out a concept that ends up being incorporated into Kai. | ||
|
||
## PyInstaller and JSON-RPC Client | ||
|
||
The goals of this effort are: | ||
|
||
- Figure out how we can enable communication between the Kai Client and different IDE extensions (possibly running in restricted environments) in a uniform way. | ||
- Figure out a way to package the client into an independent binary that can be run on different platforms. | ||
|
||
As of writing this, here's the progress we made on the goals above: | ||
|
||
- We have a JSON-RPC interface in front of the Client CLI. The JSON-RPC interface can be found in [./client/rpc.py](./client/rpc.py). It exposes `get_incident_solutions_for_file` function that generates a fix for one file. There are two example clients (Python and Javascript) we have written that talk with the interface over I/O streams. | ||
- We have a `build.spec` file that builds the JSON-RPC client into a binary using PyInstaller. | ||
|
||
### Building JSON-RPC interface into a binary | ||
|
||
Before you can build the binary, you need to activate Kai virtual environment. Once venv is activated, you need to install Kai module in the env. To install Kai module, navigate to the Kai project root and run: | ||
|
||
```sh | ||
pip install -e . | ||
``` | ||
|
||
Now we install pyinstaller in current venv: | ||
|
||
```sh | ||
pip install pyinstaller | ||
``` | ||
|
||
Next, we run pyinstaller to generate a binary: | ||
|
||
```sh | ||
pyinstaller build.spec | ||
``` | ||
|
||
Once successful, a binary will be generated at `./dist/cli`. | ||
|
||
### Testing JSON-RPC binary | ||
|
||
Now that we have built our JSON-RPC interface into a binary, we will test it using a Python and a JS client that communicates. Both of these clients use a hardcoded path `./dist/cli` to run the JSON-RPC server. Make sure you have built the binary before moving forward. | ||
|
||
#### Testing with Python client | ||
|
||
To run the Python JSON-RPC client, install a dependency: | ||
|
||
```sh | ||
pip install pylspclient | ||
``` | ||
|
||
To run the client: | ||
|
||
```sh | ||
python rpc-client.py <KAI_TOML_CONFIG> <APP_NAME> <ANALYSIS_OUTPUT_PATH> <INPUT_FILE_PATH> | ||
``` | ||
|
||
See [arguments](#client-arguments) for help on arguments above. | ||
|
||
#### Testing with JS client | ||
|
||
To run the Javascript client, install a dependency: | ||
|
||
```sh | ||
npm install vscode-jsonrpc | ||
``` | ||
|
||
To run the client: | ||
|
||
```sh | ||
node rpc-client.js <KAI_TOML_CONFIG> <APP_NAME> <ANALYSIS_OUTPUT_PATH> <INPUT_FILE_PATH> | ||
``` | ||
|
||
##### Client arguments | ||
|
||
Both the Python and JS clients take exactly the same arguments in order: | ||
|
||
- <KAI_TOML_CONFIG>: Absolute path to the Kai config you want to use to generate fix | ||
- <APP_NAME>: The name of the application you're analyzing | ||
- <ANALYSIS_OUTPUT_PATH>: Absolute path to an analysis report containing incidents | ||
- <INPUT_FILE_PATH>: Absolute path to the input file for which you want to generate incidents | ||
|
||
When successful, both clients will print the updated file followed by the following message: | ||
|
||
```sh | ||
Received response successfully! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- mode: python ; coding: utf-8 -*- | ||
|
||
# This is a PyInstaller build spec to build Kai Client into a binary | ||
# To run this spec, activate Kai venv and run `pyinstaller ./build.spec` | ||
|
||
import sys | ||
import os | ||
from PyInstaller.building.datastruct import Tree | ||
from PyInstaller.building.build_main import Analysis | ||
from PyInstaller.building.api import PYZ, EXE, COLLECT | ||
from PyInstaller.utils.hooks import collect_data_files | ||
|
||
data_dirs = [ | ||
('../kai/data/templates', 'data/templates'), | ||
] | ||
|
||
script_path = 'client/rpc.py' | ||
|
||
a = Analysis( | ||
[script_path], | ||
pathex=[os.path.dirname(script_path)], | ||
binaries=[], | ||
datas=data_dirs, | ||
hiddenimports=["_ssl"], | ||
hookspath=[], | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
# cipher=None, | ||
noarchive=False, | ||
) | ||
|
||
pyz = PYZ(a.pure, a.zipped_data) | ||
|
||
exe = EXE( | ||
pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.datas, | ||
[], | ||
name="cli", | ||
debug=False, | ||
bootloader_ignore_signals=False, | ||
strip=False, | ||
upx=True, | ||
upx_exclude=[], | ||
runtime_tmpdir=None, | ||
console=True, | ||
disable_windowed_traceback=False, | ||
argv_emulation=False, | ||
target_arch=None, | ||
codesign_identity=None, | ||
entitlements_file=None, | ||
) | ||
|
Oops, something went wrong.