简体   繁体   English

我应该如何构建我的 Python 模块,以便将来可以随时运行旧版本?

[英]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.

相关问题 如何从旧的Python版本中隐藏不兼容的代码? - How can I hide incompatible code from older Python versions? 我如何用大量文件构建我的 Python 子模块,以便我只需要导入一个模块 - How do i structure my Python submodule with a lot of files, so that i have to import only one module 我应该如何构造和访问数据表,以便在Python 3.5中轻松比较子集? - How should I structure and access a table of data so that I can compare subsets easily in Python 3.5? 我应该把我自己的 python 模块放在哪里,以便它可以被导入 - Where should I put my own python module so that it can be imported 如何在python(vs代码)中安装任何模块的先前版本? - How can I install previous versions of any module in python (vs code)? 如何保存输入值以便下次运行代码 (Python) 时可以检索它? - How can I save an input value so I can retrieve it next time I run the code (Python)? 我如何告诉python我的数据结构(二进制)是什么样子,以便我可以绘制它? - How do I tell python what my data structure (that is in binary) looks like so I can plot it? 在Python中,如何运行不在自己路径中的模块? - In Python, how can I run a module that's not in my path? 如何让 mypy 告诉我我正在使用旧 Python 版本不支持的功能? - How can I make mypy tell me I am using features that are unsupported in older Python versions? 我应该固定我的Python依赖版本吗? - Should I pin my Python dependencies versions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM