PiranhaAgent
PiranhaAgent uses a static inference algorithm and OpenAI's GPT-4 model to generate human-like piranha rules from code examples. It generates these rules in TOML format, which can be applied to refactor other parts of the codebase.
Install
To get started with PiranhaAgent, follow these instructions:
pip install polyglot-piranha-playground
Usage (Playground UI)
To run the playground:
piranha-playground
To define your transformation rules, you will need to provide pairs of code snippets: 'before' and 'after' transformation. Each piece of code that needs transformation should be marked by unique identifiers surrounded by comments (like // 1, // 2, etc.). These identifiers serve two purposes:
- They denote which part of the code should be transformed.
- They define the transformation sequence, or cascading, i.e., which transformations should follow which.
Example
Consider the following code snippet:
Code before refactoring:
class SomeClass {
// 1 -> 2
// 1
void someMethod(String arg) {
}
// end
void otherMethod() {
String x;
// 2
someMethod(x);
// end
}
}
Code after refactoring:
class SomeClass {
// 1 -> 2
// 1
public String someMethod() {
}
// end
void otherMethod() {
String x;
// 2
x = someMethod();
// end
}
}
In this example, there are two transformation points, marked by the identifiers // 1 and // 2.
// 1shows the transformation fromvoid someMethod(String arg)topublic String someMethod().// 2shows the transformation fromsomeMethod(x)tox = someMethod().
The arrow notation // 1 -> 2 indicates the transformation cascade, i.e., transformation // 2 should be applied after transformation // 1.
Each transformation snippet begins with the identifier (like // 1) and ends with a // end comment.
This way of representing transformations helps to create clear, concise, and human-friendly refactoring rules, making it easier to manage and understand your transformations.
Make sure to follow these conventions when inputting your code for refactoring. Happy coding!
Note: The code before and after must be syntactically correct, and it should parse. Moreover, after applying the rules to code before, the refactored code should match the code after. (spaces are ignored).
Metadata
Release files for polyglot-piranha-playground 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polyglot-piranha-playground-0.0.3.tar.gz | 34.8 kB | Without provenance | Details for polyglot-piranha-playground-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polyglot_piranha_playground-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for polyglot_piranha_playground-0.0.3-py3-none-any.whl |
Total release size: 85.3 kB
Release files / polyglot-piranha-playground-0.0.3.tar.gz
| Download URL | polyglot-piranha-playground-0.0.3.tar.gz |
|---|---|
| Size | 34.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f941b178bea38f70953bbb46f1a03dfd23977ce1c878a9c40e30e4a4865ab90
|
|
BLAKE2b-256 checksum How to use checksums |
842ce906a83aab24a52723a1be0f416f0e8aba8f141c9a4f9fe052706089a41e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / polyglot_piranha_playground-0.0.3-py3-none-any.whl
| Download URL | polyglot_piranha_playground-0.0.3-py3-none-any.whl |
|---|---|
| Size | 50.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ccab0df879016d9e0f25dfaaf737dba3d46770477fd8bb6f65134ee03887de5
|
|
BLAKE2b-256 checksum How to use checksums |
e9244cd2d3e721b0c8d384d65985db96277c2f03953c3c456b26296da6956fb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for polyglot-piranha-playground 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.