当前位置: 首页>>代码示例>>Python>>正文


Python synthtool.replace方法代码示例

本文整理汇总了Python中synthtool.replace方法的典型用法代码示例。如果您正苦于以下问题:Python synthtool.replace方法的具体用法?Python synthtool.replace怎么用?Python synthtool.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synthtool的用法示例。


在下文中一共展示了synthtool.replace方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_code

# 需要导入模块: import synthtool [as 别名]
# 或者: from synthtool import replace [as 别名]
def format_code(
    path: str, version: str = DEFAULT_FORMAT_VERSION, times: int = 2
) -> None:
    """
    Runs the google-java-format jar against all .java files found within the
    provided path.
    """
    jar_name = f"google-java-format-{version}.jar"
    jar = cache.get_cache_dir() / jar_name
    if not jar.exists():
        _download_formatter(version, jar)

    # Find all .java files in path and run the formatter on them
    files = list(glob.iglob(os.path.join(path, "**/*.java"), recursive=True))

    # Run the formatter as a jar file
    logger.info("Running java formatter on {} files".format(len(files)))
    for _ in range(times):
        shell.run(["java", "-jar", str(jar), "--replace"] + files) 
开发者ID:googleapis,项目名称:synthtool,代码行数:21,代码来源:java.py

示例2: fix_pb2_headers

# 需要导入模块: import synthtool [as 别名]
# 或者: from synthtool import replace [as 别名]
def fix_pb2_headers(*, proto_root: str = "**/*_pb2.py") -> None:
    s.replace(
        proto_root,
        PB2_HEADER,
        fr"\g<1>{LICENSE}\n\n\g<2>",  # change order to avoid stacking replacements
        flags=re.DOTALL | re.MULTILINE,
    ) 
开发者ID:googleapis,项目名称:synthtool,代码行数:9,代码来源:python.py

示例3: fix_pb2_grpc_headers

# 需要导入模块: import synthtool [as 别名]
# 或者: from synthtool import replace [as 别名]
def fix_pb2_grpc_headers(*, proto_root: str = "**/*_pb2_grpc.py") -> None:
    s.replace(
        proto_root,
        PB2_GRPC_HEADER,
        fr"{LICENSE}\n\n\g<1>\n\n\g<2>",  # add line breaks to avoid stacking replacements
    ) 
开发者ID:googleapis,项目名称:synthtool,代码行数:8,代码来源:python.py

示例4: fix_proto_headers

# 需要导入模块: import synthtool [as 别名]
# 或者: from synthtool import replace [as 别名]
def fix_proto_headers(proto_root: Path) -> None:
    s.replace(
        [proto_root / "src/**/*.java"],
        PROTOBUF_HEADER,
        f"{GOOD_LICENSE}{PROTOBUF_HEADER}",
    )
    # https://github.com/googleapis/gapic-generator/issues/3074
    s.replace(
        [proto_root / "src/**/*Name.java", proto_root / "src/**/*Names.java"],
        BAD_LICENSE,
        GOOD_LICENSE,
    ) 
开发者ID:googleapis,项目名称:synthtool,代码行数:14,代码来源:java.py

示例5: fix_grpc_headers

# 需要导入模块: import synthtool [as 别名]
# 或者: from synthtool import replace [as 别名]
def fix_grpc_headers(grpc_root: Path, package_name: str) -> None:
    s.replace(
        [grpc_root / "src/**/*.java"], "^package (.*);", f"{GOOD_LICENSE}package \\1;",
    ) 
开发者ID:googleapis,项目名称:synthtool,代码行数:6,代码来源:java.py

示例6: delete_method

# 需要导入模块: import synthtool [as 别名]
# 或者: from synthtool import replace [as 别名]
def delete_method(sources: ListOfPathsOrStrs, method_name: str):
    """Deletes a Ruby method, including the leading comment if any.

    Args:
        sources: Source file or list of files
        method_name: Name of the method to delete
    """
    regex = f"\\n\\n(\\s+#[^\\n]*\\n)*\\n*(\\s+)def\\s+{method_name}[^\\n]+\\n+(\\2\\s\\s[^\\n]+\\n+)*\\2end\\n"
    synthtool.replace(sources, regex, "\n") 
开发者ID:googleapis,项目名称:synthtool,代码行数:11,代码来源:ruby.py


注:本文中的synthtool.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。