piranha
0.1.0
Polylotpiranha是一種輕巧的代碼轉換工具集,用於自動化大規模更改。在Uber,它主要用於清理過時的功能標誌。
我們僅支持Uber使用的語言。我們可能無法在此存儲庫中添加新語言。有許多叉子(請參閱https://github.com/uber/piranha/forks以獲取完整列表),可能會提供其他功能。
要安裝Polyglot Piranha,您可以將其用作Python庫或命令行工具。
要安裝Python API,請運行以下命令:
pip install polyglot-piranha
要安裝命令行接口,請按照以下步驟:
git clone https://github.com/uber/piranha.git
cd piranha
cargo build --release
(或cargo build --release --no-default-features
)target/release
下生成 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 )
有關工具集的更多示例和說明,請檢查我們的演示和擴展polyglot_readme.md文件。
特徵標誌通常用於逐步推出或實驗新功能。在少數情況下,即使完成標誌的目的,與功能標誌有關的代碼也不會刪除。我們將這樣的標誌稱為陳舊的旗幟。與陳舊標誌有關的代碼的存在可能具有以下缺點:
polylotpiranha是一種可以自動重構與陳舊標誌相關的重構代碼的工具。在更高級別上,該工具的輸入是標誌的名稱和預期行為,在指定了屬性文件中與標誌相關的API列表之後。 Piranha將使用這些輸入來根據預期行為自動重構代碼。
Polylotpiranha(截至2022年5月)是支持多種語言和功能標誌API的常見重構工具。對於特定於語言的實現,請檢查以下標籤。
關於Piranha的其他一些鏈接:
如果您對如何使用Piranha或找到任何錯誤有任何疑問,請打開GitHub問題。
Piranha已獲得Apache 2.0許可證的許可。有關更多信息,請參見許可證文件。
這不是Uber官方產品,並且原樣提供。