mirror of
https://github.com/MillironX/nf-configs.git
synced 2024-11-10 20:13:09 +00:00
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
|
#!/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]
|
||
|
config_profiles.add(hit)
|
||
|
|
||
|
###Check Github Config now
|
||
|
tests = set()
|
||
|
with open(Github, 'r') as ghfile:
|
||
|
for line in ghfile:
|
||
|
if re.search('profile: ', line):
|
||
|
line = line.replace('\'','').replace('[','').replace(']','')
|
||
|
profiles = line.split(':')[1].split(',')
|
||
|
for p in profiles:
|
||
|
tests.add(p)
|
||
|
|
||
|
print(len(tests))
|
||
|
print(len(config_profiles))
|
||
|
|
||
|
###Check if sets are equal
|
||
|
if tests == config_profiles:
|
||
|
sys.exit(0)
|
||
|
else:
|
||
|
#Maybe report what is missing here too
|
||
|
#print("Tests don't seem to test these profiles properly!\n")
|
||
|
# print(config_profiles.difference(tests))
|
||
|
sys.exit(1)
|
||
|
|
||
|
check_config(Config=args.CUSTOM_CONFIG,Github=args.GITHUB_CONFIG)
|