1
0
Fork 0
mirror of https://github.com/MillironX/nf-configs.git synced 2024-11-11 04:23:10 +00:00
nf-configs/bin/cchecker.py

69 lines
2.4 KiB
Python
Raw Normal View History

2019-11-26 12:57:32 +00:00
#!/usr/bin/env python
#######################################################################
#######################################################################
## Created on November 26 to check pipeline configs for nf-core/configs
#######################################################################
#######################################################################
import os
import sys
import argparse
import re
############################################
############################################
## PARSE ARGUMENTS
############################################
############################################
Description = 'Double check custom config file and github actions file to test all cases'
Epilog = """Example usage: python cchecker.py <nfcore_custom.config> <github_actions_file>"""
argParser = argparse.ArgumentParser(description=Description, epilog=Epilog)
## REQUIRED PARAMETERS
argParser.add_argument('CUSTOM_CONFIG', help="Input nfcore_custom.config.")
argParser.add_argument('GITHUB_CONFIG', help="Input Github Actions YAML")
args = argParser.parse_args()
############################################
############################################
## MAIN FUNCTION
############################################
############################################
def check_config(Config, Github):
regex = 'includeConfig*'
ERROR_STR = 'ERROR: Please check config file! Did you really update the profiles?'
## CHECK Config First
config_profiles = set()
with open(Config, 'r') as cfg:
for line in cfg:
if re.search(regex, line):
hit = line.split('/')[2].split('.')[0]
2019-11-26 13:04:58 +00:00
config_profiles.add(hit.strip())
2019-11-26 12:57:32 +00:00
###Check Github Config now
tests = set()
with open(Github, 'r') as ghfile:
for line in ghfile:
if re.search('profile: ', line):
2019-11-26 13:04:58 +00:00
line = line.replace('\'','').replace('[','').replace(']','').replace('\n','')
2019-11-26 12:57:32 +00:00
profiles = line.split(':')[1].split(',')
for p in profiles:
2019-11-26 13:04:58 +00:00
tests.add(p.strip())
2019-11-26 12:57:32 +00:00
###Check if sets are equal
if tests == config_profiles:
sys.exit(0)
else:
#Maybe report what is missing here too
2019-11-26 13:04:58 +00:00
print("Tests don't seem to test these profiles properly!\n")
print(config_profiles.symmetric_difference(tests))
2019-11-26 12:57:32 +00:00
sys.exit(1)
check_config(Config=args.CUSTOM_CONFIG,Github=args.GITHUB_CONFIG)