[英]How should I structure my Python module so that I can run older versions at any time in the future?
I have a Python module which generates forecasts for a specific area of our business.我有一个 Python 模块,它为我们业务的特定领域生成预测。 The module contains not only my forecasts, but also those of others which act as inputs into my forecasts, or use my forecast as an input.该模块不仅包含我的预测,还包含其他人的预测,这些人作为我的预测的输入,或使用我的预测作为输入。
We make many changes over time to the code in the repository.随着时间的推移,我们对存储库中的代码进行了许多更改。 I would like to be able to run the code as of some date in the past at all times.我希望能够始终运行过去某个日期的代码。 Ideally, I would be able to name versions or releases and specifically run that file.理想情况下,我将能够命名版本或发布并专门运行该文件。 As of right now, the only way I could imagine doing this is by having a bunch of if statements in my code.截至目前,我能想到的唯一方法是在我的代码中加入一堆 if 语句。 That can't be best practice though, hence me asking here.但这不是最佳实践,因此我在这里问。
I recognize that I will also need to store data inputs as of the date of the run - I'm able to handle that myself.我知道我还需要存储截至运行日期的数据输入——我自己可以处理。 What I am specifically asking about is how to store versions of the code base so that they can be easily run - ideally in parallel on an EC2 cluster.我特别想问的是如何存储代码库的版本,以便它们可以轻松运行——最好是在 EC2 集群上并行运行。
Repo structure:回购结构:
parent-folder
- Dockerfile
- forecasting-code
- requirements.txt
- forecast_runner.py
- config.py
- module
- forecasts
- volume_forecast.py
- conversion_forecast.py
- profitability_forecast.py
- models
- price_elasticity.py
- scripts
- load_data.py
- data_inputs
- sql
- csv
- pkl
- auth_files
- google_sheets
- db
One thing that may help you is tagging your commits for each release.可能对您有帮助的一件事是为每个版本标记您的提交。 That way you have an easy way to see which commits are real released vs small changes in between which may or may not work.这样你就有了一个简单的方法来查看哪些提交是真正发布的,哪些之间的小改动可能有效,也可能无效。
One workflow is to use pip. You can use pip to install from git.一种工作流程是使用 pip。您可以使用 pip 从 git 安装。
pip install git+https://myrep.com/mypath@1.0
Alternately, you could install from the path as editable.或者,您可以从可编辑的路径安装。
pip install -e .
That way, everytime you checkout a new tag you don't need to reinstall.这样,每次签出新标签时都无需重新安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.