in tools/add_module.py [0:0]
def from_user_input():
name = ask_input("Please enter the module name: ")
version = ask_input("Please enter the module version: ")
compatibility = ask_input(
"Please enter the compatibility level [default is 1]: ") or "1"
module = Module(name, version, compatibility)
url = ask_input("Please enter the URL of the source archive: ")
strip_prefix = ask_input(
"Please enter the strip_prefix value of the archive [default None]: ") or None
module.set_source(url, strip_prefix)
if yes_or_no("Do you want to add patch files?", False):
patches = ask_input("Please enter patch file paths, separated by `,`: ")
for patch in patches.strip().split(","):
module.add_patch(patch.strip())
patch_strip = ask_input("Please enter the patch strip number [Default is 1, compatible with git generated "
"patches]: ") or "1"
module.set_patch_strip(int(patch_strip.strip()))
if yes_or_no("Do you want to add a BUILD file?", False):
build_file = ask_input(
"Please enter the path of the BUILD file to be added: ")
module.set_build_file(build_file.strip())
if yes_or_no("Do you want to specify a MODULE.bazel file?", False):
path = ask_input("Please enter the MODULE.bazel file path: ").strip()
module.set_module_dot_bazel(path)
else:
if yes_or_no("Do you want to specify dependencies for this module?", False):
deps = ask_input(
"Please enter dependencies in the form of <name>@<version>, separated by `,`: ")
for dep in deps.strip().split(","):
name, version = dep.split("@")
module.add_dep(name, version)
presubmit_url = "https://github.com/bazelbuild/bazel-central-registry/tree/main#presubmityml"
if yes_or_no(f"Do you want to specify an existing presubmit.yml file? (See {presubmit_url})", False):
path = ask_input("Please enter the presubmit.yml file path: ").strip()
module.set_presubmit_yml(path)
else:
first = True
while not module.build_targets:
if not first:
print("Build targets cannot be empty, please re-enter!")
first = False
build_targets = ask_input(
"Please enter a list of build targets you want to expose to downstream users, separated by `,`: ")
for target in build_targets.strip().split(","):
if target:
module.add_build_target(target)
if yes_or_no("Do you have a test module in your source archive?", True):
module.test_module_path = ask_input("Please enter the test module path in your source archive: ")
first = True
while not (module.test_module_build_targets or module.test_module_test_targets):
if not first:
print("Build targets and test targets cannot both be empty, please re-enter!")
first = False
build_targets = ask_input(
"Please enter a list of build targets for the test module, separated by `,`: ")
for target in build_targets.strip().split(","):
if target:
module.add_test_module_build_target(target)
test_targets = ask_input(
"Please enter a list of test targets for the test module, separated by `,`: ")
for target in test_targets.strip().split(","):
if target:
module.add_test_module_test_target(target)
return module