本文整理匯總了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)
示例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,
)
示例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
)
示例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,
)
示例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;",
)
示例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")