11def get_setup_version_and_pattern (setup_content ):
22 depend_lst , version_lst = [], []
33 for l in setup_content :
4- if '==' in l :
5- lst = l .split ('[' )[- 1 ].split (']' )[0 ].replace (' ' , '' ).replace ('"' , '' ).replace ("'" , '' ).split (',' )
4+ if "==" in l :
5+ lst = (
6+ l .split ("[" )[- 1 ]
7+ .split ("]" )[0 ]
8+ .replace (" " , "" )
9+ .replace ('"' , "" )
10+ .replace ("'" , "" )
11+ .split ("," )
12+ )
613 for dep in lst :
7- if dep != ' \n ' :
8- version_lst .append (dep .split ('==' )[1 ])
9- depend_lst .append (dep .split ('==' )[0 ])
14+ if dep != " \n " :
15+ version_lst .append (dep .split ("==" )[1 ])
16+ depend_lst .append (dep .split ("==" )[0 ])
1017
1118 version_high_dict = {d : v for d , v in zip (depend_lst , version_lst )}
1219 return version_high_dict
@@ -16,14 +23,14 @@ def get_env_version(env_content):
1623 read_flag = False
1724 depend_lst , version_lst = [], []
1825 for l in env_content :
19- if ' dependencies:' in l :
26+ if " dependencies:" in l :
2027 read_flag = True
2128 elif read_flag :
22- lst = l .replace ('-' , '' ).replace (' ' , '' ).replace (' \n ' , '' ).split ("=" )
29+ lst = l .replace ("-" , "" ).replace (" " , "" ).replace (" \n " , "" ).split ("=" )
2330 if len (lst ) == 2 :
2431 depend_lst .append (lst [0 ])
2532 version_lst .append (lst [1 ])
26- return {d :v for d , v in zip (depend_lst , version_lst )}
33+ return {d : v for d , v in zip (depend_lst , version_lst )}
2734
2835
2936def update_dependencies (setup_content , version_low_dict , version_high_dict ):
@@ -35,27 +42,29 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict):
3542 version_combo_dict [dep ] = dep + "==" + ver
3643
3744 setup_content_new = ""
38- pattern_dict = {d :d + "==" + v for d , v in version_high_dict .items ()}
45+ pattern_dict = {d : d + "==" + v for d , v in version_high_dict .items ()}
3946 for l in setup_content :
4047 for k , v in pattern_dict .items ():
4148 if v in l :
4249 l = l .replace (v , version_combo_dict [k ])
43- setup_content_new += l
50+ setup_content_new += l
4451 return setup_content_new
4552
4653
4754if __name__ == "__main__" :
48- with open (' pyproject.toml' , "r" ) as f :
55+ with open (" pyproject.toml" , "r" ) as f :
4956 setup_content = f .readlines ()
5057
51- with open (' environment.yml' , "r" ) as f :
58+ with open (" environment.yml" , "r" ) as f :
5259 env_content = f .readlines ()
5360
5461 setup_content_new = update_dependencies (
5562 setup_content = setup_content [2 :],
5663 version_low_dict = get_env_version (env_content = env_content ),
57- version_high_dict = get_setup_version_and_pattern (setup_content = setup_content [2 :]),
64+ version_high_dict = get_setup_version_and_pattern (
65+ setup_content = setup_content [2 :]
66+ ),
5867 )
5968
60- with open (' pyproject.toml' , "w" ) as f :
69+ with open (" pyproject.toml" , "w" ) as f :
6170 f .writelines ("" .join (setup_content [:2 ]) + setup_content_new )
0 commit comments