support freezing one Python at a time

pull/208/head
Min RK 2018-02-01 14:28:41 +01:00
rodzic c31ff40937
commit 0d1c132de2
1 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -3,6 +3,10 @@
Freeze the conda environment.yml Freeze the conda environment.yml
Run in a continuumio/miniconda3 image to ensure portability Run in a continuumio/miniconda3 image to ensure portability
Usage:
python freeze.py [3.5]
""" """
from datetime import datetime from datetime import datetime
@ -10,6 +14,7 @@ import os
import pathlib import pathlib
import shutil import shutil
from subprocess import check_call from subprocess import check_call
import sys
from ruamel.yaml import YAML from ruamel.yaml import YAML
@ -39,6 +44,7 @@ def freeze(env_file, frozen_file):
Result will be stored in frozen_file Result will be stored in frozen_file
""" """
print(f"Freezing {env_file} -> {frozen_file}")
with open(HERE / frozen_file, 'w') as f: with open(HERE / frozen_file, 'w') as f:
f.write(f"# AUTO GENERATED FROM {env_file}, DO NOT MANUALLY MODIFY\n") f.write(f"# AUTO GENERATED FROM {env_file}, DO NOT MANUALLY MODIFY\n")
@ -73,6 +79,8 @@ def set_python(py_env_file, py):
text = f.read() text = f.read()
if text and 'GENERATED' not in text: if text and 'GENERATED' not in text:
return return
print(f"Regenerating {py_env_file} from {ENV_FILE}")
with open(ENV_FILE) as f: with open(ENV_FILE) as f:
env = yaml.load(f) env = yaml.load(f)
for idx, dep in enumerate(env['dependencies']): for idx, dep in enumerate(env['dependencies']):
@ -89,7 +97,9 @@ def set_python(py_env_file, py):
if __name__ == '__main__': if __name__ == '__main__':
for py in ('2.7', '3.5', '3.6'): # allow specifying which Pythons to update on argv
pys = sys.argv[1:] or ('2.7', '3.5', '3.6')
for py in pys:
env_file = ENV_FILE_T.format(py=py) env_file = ENV_FILE_T.format(py=py)
set_python(env_file, py) set_python(env_file, py)
frozen_file = os.path.splitext(env_file)[0] + '.frozen.yml' frozen_file = os.path.splitext(env_file)[0] + '.frozen.yml'