ADD: dependency-checker.py
This commit is contained in:
commit
42299175e2
84
dependency-checker.py
Normal file
84
dependency-checker.py
Normal file
@ -0,0 +1,84 @@
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
assert sys.version_info >= (3, 7), 'Python version is too low, please load a python >= 3.7'
|
||||
|
||||
def subprocess_cmd(cmd):
|
||||
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True, shell=True)
|
||||
|
||||
class PmodulePackage():
|
||||
def __init__(self, name, status, deps=[]):
|
||||
self.name = name
|
||||
self.given_status = status
|
||||
self.true_status = [status]
|
||||
|
||||
if len(deps) != 0 and self.given_status != 'deprecated':
|
||||
compiler = deps[0]
|
||||
if len(deps) > 1 and 'mpi' in deps[1]:
|
||||
mpi_provider = deps[1]
|
||||
else:
|
||||
mpi_provider = ''
|
||||
self.deps = [PmodulePackage.Pmoduliser(d, compiler, mpi_provider) for d in deps]
|
||||
self.true_status += self.check_deps_status()
|
||||
|
||||
def check_deps_status(self):
|
||||
deps_status = []
|
||||
for d in self.deps:
|
||||
if d.given_status == 'unstable' and self.given_status == 'stable':
|
||||
print('Dependency ' + d.name + ' is unstable!')
|
||||
elif d.given_status == 'deprecated':
|
||||
print('Dependency ' + d.name + ' is deprecated!')
|
||||
deps_status += d.true_status
|
||||
return deps_status
|
||||
|
||||
def check_correct_status(self):
|
||||
if (self.given_status != 'deprecated') and len(self.true_status) > 1:
|
||||
print_cmd = 'Package ' + self.name + ' is deployed as ' + self.given_status
|
||||
if 'deprecated' in self.true_status:
|
||||
print(print_cmd + ' although it should be deployed as deprecated')
|
||||
self.given_status = 'deprecated'
|
||||
elif self.given_status == 'stable' and 'unstable' in self.true_status:
|
||||
print(print_cmd + ' although it should be deployed as unstable')
|
||||
self.given_status = 'unstable'
|
||||
self.true_status = [self.given_status]
|
||||
|
||||
@staticmethod
|
||||
def Pmoduliser(pckg_name='', compiler='', mpi_provider=''):
|
||||
default_module_cmd = 'module search ' + pckg_name + ' -a --all-deps --no-header'
|
||||
|
||||
# try to precise the module search if compiler and/or mpi_provider are given
|
||||
module_cmd = default_module_cmd
|
||||
if compiler != '' and pckg_name != compiler:
|
||||
module_cmd = module_cmd + ' --with=' + compiler
|
||||
if mpi_provider != '' and pckg_name != mpi_provider:
|
||||
module_cmd = module_cmd + ' --with=' + mpi_provider
|
||||
module_cmd_process = subprocess_cmd(module_cmd)
|
||||
|
||||
# take the default command if the dependency wasn't compiled with the same compiler and/or mpi_provider
|
||||
if len(module_cmd_process.stderr.splitlines()) == 0:
|
||||
module_cmd = default_module_cmd
|
||||
module_cmd_process = subprocess_cmd(module_cmd)
|
||||
|
||||
package = module_cmd_process.stderr.splitlines()
|
||||
if len(package) != 0:
|
||||
package = package[0].split()
|
||||
Pmodule_pckg = PmodulePackage(package[0], package[1], package[3:])
|
||||
Pmodule_pckg.check_correct_status()
|
||||
return Pmodule_pckg
|
||||
else:
|
||||
print(pckg_name + ' could not be found using "' + module_cmd + '"')
|
||||
return PmodulePackage('', '')
|
||||
|
||||
def main():
|
||||
module_cmd = 'module search -a --all-deps --no-header'
|
||||
module_cmd_process = subprocess_cmd(module_cmd)
|
||||
for package in module_cmd_process.stderr.splitlines():
|
||||
if len(package) != 0:
|
||||
print('Resolving status of ' + package)
|
||||
package = package.split()
|
||||
Pmodule_pckg = PmodulePackage(package[0], package[1], package[3:])
|
||||
Pmodule_pckg.check_correct_status()
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user