File size: 506 Bytes
265d55c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import ruamel.yaml

yaml = ruamel.yaml.YAML()
data = yaml.load(open('environment.yaml'))

requirements = []
for dep in data['dependencies']:
    if isinstance(dep, str):
        package, package_version = dep.split('=')
        requirements.append(package + '==' + package_version)
    elif isinstance(dep, dict):
        for preq in dep.get('pip', []):
            requirements.append(preq)

with open('requirements.txt', 'w') as fp:
    for requirement in requirements:
       print(requirement, file=fp)