mirror of
https://github.com/clearml/clearml
synced 2025-06-26 18:16:07 +00:00
Add Python Fire support (#550)
This commit is contained in:
committed by
GitHub
parent
9794135aed
commit
296cb7d899
21
examples/frameworks/fire/fire_class_cmd.py
Normal file
21
examples/frameworks/fire/fire_class_cmd.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# ClearML - Example of Python Fire integration, processing commands derived from a class
|
||||
#
|
||||
from clearml import Task
|
||||
|
||||
import fire
|
||||
|
||||
|
||||
class BrokenCalculator(object):
|
||||
def __init__(self, offset=1):
|
||||
self._offset = offset
|
||||
|
||||
def add(self, x, y):
|
||||
return x + y + self._offset
|
||||
|
||||
def multiply(self, x, y):
|
||||
return x * y + self._offset
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Task.init(project_name="examples", task_name="fire class command")
|
||||
fire.Fire(BrokenCalculator)
|
||||
23
examples/frameworks/fire/fire_dict_cmd.py
Normal file
23
examples/frameworks/fire/fire_dict_cmd.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# ClearML - Example of Python Fire integration, with commands derived from a dictionary
|
||||
#
|
||||
from clearml import Task
|
||||
|
||||
import fire
|
||||
|
||||
|
||||
def add(x, y):
|
||||
return x + y
|
||||
|
||||
|
||||
def multiply(x, y):
|
||||
return x * y
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Task.init(project_name="examples", task_name="fire dict command")
|
||||
fire.Fire(
|
||||
{
|
||||
"add": add,
|
||||
"multiply": multiply,
|
||||
}
|
||||
)
|
||||
44
examples/frameworks/fire/fire_grouping_cmd.py
Normal file
44
examples/frameworks/fire/fire_grouping_cmd.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# ClearML - Example of Python Fire integration, with commands grouped inside classes
|
||||
#
|
||||
from clearml import Task
|
||||
|
||||
import fire
|
||||
|
||||
|
||||
class Other(object):
|
||||
def status(self):
|
||||
return "Other"
|
||||
|
||||
|
||||
class IngestionStage(object):
|
||||
def __init__(self):
|
||||
self.other = Other()
|
||||
|
||||
def run(self):
|
||||
return "Ingesting! Nom nom nom..."
|
||||
|
||||
def hello(self, hello_str):
|
||||
return hello_str
|
||||
|
||||
|
||||
class DigestionStage(object):
|
||||
def run(self, volume=1):
|
||||
return " ".join(["Burp!"] * volume)
|
||||
|
||||
def status(self):
|
||||
return "Satiated."
|
||||
|
||||
|
||||
class Pipeline(object):
|
||||
def __init__(self):
|
||||
self.ingestion = IngestionStage()
|
||||
self.digestion = DigestionStage()
|
||||
|
||||
def run(self):
|
||||
self.ingestion.run()
|
||||
self.digestion.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Task.init(project_name="examples", task_name="fire grouping command")
|
||||
fire.Fire(Pipeline)
|
||||
22
examples/frameworks/fire/fire_multi_cmd.py
Normal file
22
examples/frameworks/fire/fire_multi_cmd.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# ClearML - Example of Python Fire integration, processing multiple commands, when fire is initialized with no component
|
||||
#
|
||||
from clearml import Task
|
||||
|
||||
import fire
|
||||
|
||||
|
||||
def hello(count, name="clearml", prefix="prefix_", suffix="_suffix", **kwargs):
|
||||
for _ in range(count):
|
||||
print("Hello %s%s%s!" % (prefix, name, suffix))
|
||||
|
||||
|
||||
def serve(addr, port, should_serve=False):
|
||||
if not should_serve:
|
||||
print("Not serving")
|
||||
else:
|
||||
print("Serving on %s:%s" % (addr, port))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Task.init(project_name="examples", task_name="fire multi command")
|
||||
fire.Fire()
|
||||
19
examples/frameworks/fire/fire_object_cmd.py
Normal file
19
examples/frameworks/fire/fire_object_cmd.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# ClearML - Example of Python Fire integration, with commands derived from an object
|
||||
#
|
||||
from clearml import Task
|
||||
|
||||
import fire
|
||||
|
||||
|
||||
class Calculator(object):
|
||||
def add(self, x, y):
|
||||
return x + y
|
||||
|
||||
def multiply(self, x, y):
|
||||
return x * y
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Task.init(project_name="examples", task_name="fire object command")
|
||||
calculator = Calculator()
|
||||
fire.Fire(calculator)
|
||||
15
examples/frameworks/fire/fire_single_cmd.py
Normal file
15
examples/frameworks/fire/fire_single_cmd.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# ClearML - Example of Python Fire integration, with a single command passed to Fire
|
||||
#
|
||||
from clearml import Task
|
||||
|
||||
import fire
|
||||
|
||||
|
||||
def hello(count, name="clearml", prefix="prefix_", suffix="_suffix", **kwargs):
|
||||
for _ in range(count):
|
||||
print("Hello %s%s%s!" % (prefix, name, suffix))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Task.init(project_name="examples", task_name="fire single command")
|
||||
fire.Fire(hello)
|
||||
2
examples/frameworks/fire/requirements.txt
Normal file
2
examples/frameworks/fire/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
clearml
|
||||
fire
|
||||
Reference in New Issue
Block a user