1. Pipeline
我们可以借助 Fire 来实现管道的功能,这个功能可以让我们在断点运行自己想要运行的代码。比如我们需要创建一系列的模型特征:
import fire
class BuildAppFeatures:
@staticmethod
def run():
print("Building APP features")
class BuildUsersFeatures:
@staticmethod
def run():
print("Building Users features")
class Pipeline:
def __init__(self):
self.app = BuildAppFeatures()
self.users = BuildUsersFeatures()
def run(self):
self.app.run()
self.users.run()
print("Pipeline complete")
if __name__ == '__main__':
fire.Fire(Pipeline)
终端中运行整个 Pipeline:
$ python pipeline.py run
Building APP features
Building Users features
Pipeline complete
2. 端点
如果我们创建 APP 特征后,结果程序终端了,我们又不想再创建一遍 APP 变量来浪费时间,可以采用下面的方式(这非常适合工程话项目):
$ python pipeline.py users run
Building Users features