Skip to main content

Polyglot Piranha is a library for performing structural find and replace with deep cleanup.

Project description

PolyglotPiranha

PolyglotPiranha is a lightweight code transformation toolset for automating large scale changes. At Uber, it is mostly used to clean up stale feature flags.

Installation

To install Polyglot Piranha, you can use it as a Python library or as a command-line tool.

Python API

To install the Python API, run the following command:

pip install polyglot-piranha

Command-line Interface

To install the command-line interface, follow these steps:

  1. Install Rust
  2. Clone the repository: git clone https://github.com/uber/piranha.git
  3. Navigate to the cloned directory: cd piranha
  4. Build the project: cargo build --release (or cargo build --release --no-default-features for macOS)
  5. The binary will be generated under target/release

Example Usage

from polyglot_piranha import execute_piranha, PiranhaArguments, Rule, RuleGraph, OutgoingEdges

# Original code snippet
code = """
if (obj.isLocEnabled() || x > 0) {
    // do something
} else {
    // do something else!
}
"""

# Define the rule to replace the method call
r1 = Rule(
    name="replace_method",
    query="cs :[x].isLocEnabled()", # cs indicates we are using concrete syntax
    replace_node="*",
    replace="true",
    is_seed_rule=True
)

# Define the edges for the rule graph. 
# In this case, boolean_literal_cleanup is already defined for java [see src/cleanup_rules]
edge = OutgoingEdges("replace_method", to=["boolean_literal_cleanup"], scope="parent")

# Create Piranha arguments
piranha_arguments = PiranhaArguments(
    code_snippet=code,
    language="java",
    rule_graph=RuleGraph(rules=[r1], edges=[edge])
)

# Execute Piranha and print the transformed code
piranha_summary = execute_piranha(piranha_arguments)
print(piranha_summary[0].content)

Documentation

For more examples and explanations of the toolset, please check our demos and extended POLYGLOT_README.md file.

Feature Flags

Feature flags are commonly used to enable gradual rollout or experiment with new features. In a few cases, even after the purpose of the flag is accomplished, the code pertaining to the feature flag is not removed. We refer to such flags as stale flags. The presence of code pertaining to stale flags can have the following drawbacks:

  • Unnecessary code clutter increases the overall complexity w.r.t maintenance resulting in reduced developer productivity
  • The flags can interfere with other experimental flags (e.g., due to nesting under a flag that is always false)
  • Presence of unused code in the source as well as the binary
  • Stale flags can also cause bugs

PolyglotPiranha is a tool that can automatically refactor code related to stale flags. At a higher level, the input to the tool is the name of the flag and the expected behavior, after specifying a list of APIs related to flags in a properties file. Piranha will use these inputs to automatically refactor the code according to the expected behavior.

PolyglotPiranha (as of May 2022) is a common refactoring tool to support multiple languages and feature flag APIs. For legacy language-specific implementations please check following tag.

A few additional links on Piranha:

  • Research paper published at PLDI 2024 on PolyglotPiranha.
  • A technical report detailing our experiences with using Piranha at Uber.
  • A blogpost presenting more information on Piranha.
  • 6 minute video overview of Piranha.

Support

If you have any questions on how to use Piranha or find any bugs, please open a GitHub issue.

Contributors

We'd love for you to contribute to Piranha! Please note that once you create a pull request, you will be asked to sign our Uber Contributor License Agreement.

We are also looking for contributions to extend Piranha to other languages (C++, C#, Kotlin).

License

Piranha is licensed under the Apache 2.0 license. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyglot_piranha-0.3.27.tar.gz (94.2 kB view details)

Uploaded Source

Built Distributions

polyglot_piranha-0.3.27-cp312-cp312-manylinux_2_34_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.34+ ARM64

polyglot_piranha-0.3.27-cp312-cp312-manylinux_2_28_x86_64.whl (16.9 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.28+ x86-64

polyglot_piranha-0.3.27-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.3 MB view details)

Uploaded CPython 3.12 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

polyglot_piranha-0.3.27-cp311-cp311-manylinux_2_34_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.34+ ARM64

polyglot_piranha-0.3.27-cp311-cp311-manylinux_2_28_x86_64.whl (16.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

polyglot_piranha-0.3.27-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.3 MB view details)

Uploaded CPython 3.11 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

polyglot_piranha-0.3.27-cp310-cp310-manylinux_2_34_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.34+ ARM64

polyglot_piranha-0.3.27-cp310-cp310-manylinux_2_28_x86_64.whl (16.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

polyglot_piranha-0.3.27-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.3 MB view details)

Uploaded CPython 3.10 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

polyglot_piranha-0.3.27-cp39-cp39-manylinux_2_34_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.34+ ARM64

polyglot_piranha-0.3.27-cp39-cp39-manylinux_2_28_x86_64.whl (16.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

polyglot_piranha-0.3.27-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.3 MB view details)

Uploaded CPython 3.9 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

polyglot_piranha-0.3.27-cp38-cp38-manylinux_2_34_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.34+ ARM64

polyglot_piranha-0.3.27-cp38-cp38-manylinux_2_28_x86_64.whl (16.9 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

polyglot_piranha-0.3.27-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.3 MB view details)

Uploaded CPython 3.8 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

File details

Details for the file polyglot_piranha-0.3.27.tar.gz.

File metadata

  • Download URL: polyglot_piranha-0.3.27.tar.gz
  • Upload date:
  • Size: 94.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for polyglot_piranha-0.3.27.tar.gz
Algorithm Hash digest
SHA256 293424d5257842c8edaa991a35d7af86b5b21afe9f261fc1d232da6e4dc690c8
MD5 883da2e93ba837fefd0160915316ea4b
BLAKE2b-256 ecdf7321c20693aabef34b10bbc197ccd6e723cf82ec99afbd16780b4b2b29c6

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 af795535f22d5a13b4968726d642a2118a5f18d73b08cefae4669fa8b5377b35
MD5 ee0aec2cce4d8d36714edb8929120291
BLAKE2b-256 716cb8968c6b186e5ea549e344711e30849d498ce3eb648584f097f0e7ed0b77

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a9601caedc41445a331e2179d088621e98e3c6e54a838eed60b1aacdeb2c673
MD5 92a0f4f901485fd899519306df60691b
BLAKE2b-256 10135b591c97c0c1ca3f6b6054721263af27bada6d3a471dfbae5d6df36f4850

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 3edfb7d9ee22246b9fa8075fdcf706f3f18648f71b97f7a1b4b6c007fdd58ce8
MD5 5f71f10d94911074ef114e2416a26458
BLAKE2b-256 78e96fdc403161f75e22b11e79b3d305b24010b8717da63d1c232b29ecfac123

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5a7121c415410a8e957c6c4a0eafe9d7b1f7ecb305ef54ed26fc92146027b69f
MD5 2d4f7180c9b3764c31768ac27555150e
BLAKE2b-256 bcdc88ef43f0bd9bcdced5fb3a63d1f6a4bebd2eb01aa49fedb6accaa177aec2

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 870d6e47c48aeb53fa1d9b961146d02fbf86021fa52fedb4625d7b2df78bae8e
MD5 368084edb27e9a6f4afa7287e7068e78
BLAKE2b-256 ad7bc4d9b99b40e2faa73ac9d73a51e8553d8fdee1a0b4febc11d2693988abfb

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 70e216673083ce899b1c761acef134b4ee275a5c30b4cc2d21fea512bd9a6704
MD5 77a2aa56ce6113f31c58c47789aea6fa
BLAKE2b-256 fda30e4a4e95cf45c7b3d7815ac84c09ef793062e91d8a856b75ba45be8120c7

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5584fc920ff0d0f2672b89b5e6b974ae096ab81b9db69237dc0d0fde87413251
MD5 906526a037ff1b5eb5f84c2cb7c982bb
BLAKE2b-256 5f750a2da262feb925ed334ca211f47777b40ccee308b20ca6445393c6d4a321

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cfdee99494c03b8612a8d9d314180b846f36ff73fcfd8ef7c12b9a87f1d2a461
MD5 52689e2bf3c77fa19fd19fd23fcf29e7
BLAKE2b-256 bc78aa8b5b32615c29ffd15fd04d660354b67275371f0c90df6476ffc44a77a2

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 841765738177f59aaa72fe911bf1cad3465e14c852e33b61f82bf0c69d55745c
MD5 6c4d9bef29add3d9b30160dc9ee553d5
BLAKE2b-256 9dcb04698b81e9b8ca1ad74dd1273eaa4c9751ce12bf671d5cba3bc722bf1fa6

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp39-cp39-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp39-cp39-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ad66eac24382bdbf7ee64a54509e8c5e4a233a12c07203043daa511a6f2a3ec2
MD5 67c0dc3b09daf43dbb7b1a21707b7652
BLAKE2b-256 774c91b9b6f70680d7ac7cf58b296a9e0dc426503e7fdd5e3cd28840a8aa5d1e

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c2f0efc28e4d00507ad514117ef94b2b1b69e90fc22c41e234b3849a2dc07acb
MD5 cac27529a21b5c6bfac5ce8db6d54bf3
BLAKE2b-256 c17342241036b815c1d3d5b44b95bb989e30954c628750b4c069983fd546054a

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 00fb34ae9d57890997da24870846f9a58269e429701b8fc3e8f17931969ee934
MD5 4bf520c217ad97128ec4b5036f31d0f2
BLAKE2b-256 839f4d157b786324b22be2b6b579ca116d9015294be8fcfa1e42353d0991128a

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp38-cp38-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp38-cp38-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1f30b3285aaec0c14b598031a2c60e7f13c932990128d8c6c98659731823aa1a
MD5 015e4985e4795a3dc25200de1a028aed
BLAKE2b-256 3b148297e2591a1ba773d1b6b1e278a780ec1ec5295d714d08ffe967f520716d

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 40d8028abfb52a6c64f58420384d2a90265838951f0dca2b01d5ae13be26cbf0
MD5 9bf56db7e03cc0dbbd25f9651df29be4
BLAKE2b-256 68fac2bc2cb2a018b7104005be784c822aa50c63561c84454b063b4ffdbd1e21

See more details on using hashes here.

File details

Details for the file polyglot_piranha-0.3.27-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for polyglot_piranha-0.3.27-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 5fe1afa48594f46a6776c186cd03c87c67da0abdd22ea3e144c8ddc8a5058594
MD5 165a0937266d4002b07dfc1711fefa44
BLAKE2b-256 06778b8467e076a2ea0dac36fbae0ee15e465c476d827ac4fbac238c4db151e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page