Skip to content

Instantly share code, notes, and snippets.

@codefoxut
Last active July 26, 2023 11:48
Show Gist options
  • Save codefoxut/9bde8bc1cdf6928d42a9a28a1bb60270 to your computer and use it in GitHub Desktop.
Save codefoxut/9bde8bc1cdf6928d42a9a28a1bb60270 to your computer and use it in GitHub Desktop.
function to order module in dependency order.
import argparse
def order_modules(order_str, version_number_str):
# parse order list
order_list = [i.strip() for i in order_str.split(',')]
version_list = version_number_str.split()
version_dict = {}
for i in version_list:
i_lst = i.split('-')
version_dict["-".join(i_lst[:-1])] = i_lst[-1]
for i in order_list:
print(f"{i}=={version_dict[i]}")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Order python modules",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("order_str", help="Ordered string for installed modules")
parser.add_argument("version_str", help="String which contains version number for modules")
args = parser.parse_args()
config = vars(args)
# print(config, args)
order_modules(config['order_str'], config['version_str'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment