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官方产品,并且原样提供。