1. Pipeline

我们可以借助 Fire 来实现管道的功能,这个功能可以让我们在断点运行自己想要运行的代码。比如我们需要创建一系列的模型特征:

  1. import fire
  2. class BuildAppFeatures:
  3. @staticmethod
  4. def run():
  5. print("Building APP features")
  6. class BuildUsersFeatures:
  7. @staticmethod
  8. def run():
  9. print("Building Users features")
  10. class Pipeline:
  11. def __init__(self):
  12. self.app = BuildAppFeatures()
  13. self.users = BuildUsersFeatures()
  14. def run(self):
  15. self.app.run()
  16. self.users.run()
  17. print("Pipeline complete")
  18. if __name__ == '__main__':
  19. fire.Fire(Pipeline)

终端中运行整个 Pipeline:

  1. $ python pipeline.py run
  2. Building APP features
  3. Building Users features
  4. Pipeline complete

2. 端点

如果我们创建 APP 特征后,结果程序终端了,我们又不想再创建一遍 APP 变量来浪费时间,可以采用下面的方式(这非常适合工程话项目):

  1. $ python pipeline.py users run
  2. Building Users features