简体   繁体   中英

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. 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. 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.

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM