Python源码示例:fire.Fire()
示例1
def same_run_eval(black_num=0, white_num=0, completions=4):
"""Shorthand to spawn a job matching up two models from the same run,
identified by their model number """
if black_num <= 0 or white_num <= 0:
print("Need real model numbers")
return
b = fsdb.get_model(black_num)
w = fsdb.get_model(white_num)
b_model_path = os.path.join(fsdb.models_dir(), b)
w_model_path = os.path.join(fsdb.models_dir(), w)
flags_path = fsdb.eval_flags_path()
obj = launch_eval_job(b_model_path + ".pb",
w_model_path + ".pb",
"{:d}-{:d}".format(black_num, white_num),
bucket_name=flags.FLAGS.bucket_name,
flags_path=flags_path,
completions=completions)
# Fire spams the retval to stdout, so...
return "{} job launched ok".format(obj[1].metadata.name)
示例2
def main():
version = get_version()
if version:
print("APSConnect-cli v{}".format(get_version()))
try:
log_entry = ("=============================\n{}\n".format(" ".join(sys.argv)))
Logger(LOG_FILE).log(log_entry)
fire.Fire(APSConnectUtil, name='apsconnect')
except Exception as e:
print("Error: {}".format(e))
sys.exit(1)
示例3
def main():
from .mock_group import MockGroupType
gc = GroupCommands(
group_types={MockGroupType.MOCK_TYPE: MockGroupType},
region='us-west-2'
)
fire.Fire(gc)
示例4
def main(commands_dict):
"""Similar to fire.Fire, but with support for multiple commands without having a class."""
class _Commands:
def __init__(self):
for name, cmd in commands_dict.items():
setattr(self, name, cmd)
fire.Fire(_Commands)
示例5
def main():
fire.Fire(TerminalCli)
示例6
def main(unused_argv):
fire.Fire(download)
示例7
def main(_=None):
fire.Fire(reinitialize.train)
示例8
def main(_=None):
fire.Fire(lottery_experiment.train)
示例9
def main(_=None):
fire.Fire(train.train)
示例10
def main(unused_argv):
fire.Fire(run)
示例11
def entry():
fire.Fire(LKI)
示例12
def main():
fire.Fire(ramile_cli(), name='ramile')
示例13
def stylecloud_cli(**kwargs):
"""Entrypoint for the stylecloud CLI."""
fire.Fire(gen_stylecloud)
示例14
def main():
fire.Fire(TelegramPublisher)
示例15
def main():
fire.Fire(MessageProcessor)
示例16
def main():
fire.Fire(TelegramPublisher)
示例17
def main():
fire.Fire(StreamConsumer)
示例18
def aitextgen_cli(**kwargs):
"""Entrypoint for the CLI"""
fire.Fire({"encode": encode_cli, "train": train_cli, "generate": generate_cli})
示例19
def run(*args):
fire.Fire(main, args)
示例20
def run(*args):
fire.Fire(main, args)
示例21
def main(): # type: ignore
fire.Fire(Main)
示例22
def test_fire1():
assert fire.Fire(Chepy, command=["A", "-", "to_hex", "o"]) == b"41"
示例23
def test_fire2():
assert (
fire.Fire(Chepy, command=["abc", "-", "hmac_hash", "--digest", "md5"]).o
== "dd2701993d29fdd0b032c233cec63403"
)
示例24
def test_fire3():
fire_obj = fire.Fire(Chepy, command=["abc", "-", "hmac_hash", "--digest", "md5"])
assert type(fire_obj) == Chepy
示例25
def run(cls_inst):
if issubclass(cls_inst, MainProgram):
fire.Fire(cls_inst)
else:
raise Exception('')
示例26
def main():
"""Launches either KFP sample test or component test as a command entrypoint.
Usage:
python sample_test_launcher.py sample_test run_test arg1 arg2 to launch sample test, and
python sample_test_launcher.py component_test run_test arg1 arg2 to launch component
test.
"""
fire.Fire({
'sample_test': SampleTest,
'component_test': ComponentTest
})
示例27
def launch(file_or_module, args):
"""Launches a python file or module as a command entrypoint.
Args:
file_or_module: it is either a file path to python file
a module path.
args: the args passed to the entrypoint function.
Returns:
The return value from the launched function.
"""
try:
module = importlib.import_module(file_or_module)
except Exception:
try:
if sys.version_info.major > 2:
spec = importlib.util.spec_from_file_location('module', file_or_module)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
else:
import imp
module = imp.load_source('module', file_or_module)
except Exception:
logging.error('Failed to find the module or file: {}'.format(file_or_module))
sys.exit(1)
return fire.Fire(module, command=args, name=module.__name__)
示例28
def main():
init(autoreset=True)
fire.Fire()
示例29
def main():
fire.Fire(GroupCommands)
# Run main()
示例30
def main():
fire.Fire(dict(
gen_csv_from_images=dataset.gen_csv_from_images,
gen_csv_from_annotations=dataset.gen_csv_from_annotations,
))