comparison version_command.py @ 0:7c60c0620fb3 draft default tip

planemo upload for repository https://github.com/usegalaxy-be/galaxytools/tree/main/astral commit 10aeeb461530c00256dc13695f45eba8d8c6ccb5
author iuc
date Wed, 28 Aug 2024 12:53:33 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7c60c0620fb3
1 #!/usr/bin/env python
2 """Modules to execute shell commands (through child process) and regex"""
3 import re
4 import subprocess
5
6
7 def get_astral_version():
8 """Function that will parse the Astral version from `astral --help`."""
9 try:
10 # run the `astral --help` command
11 result = subprocess.run(
12 ['astral', '--help'],
13 stdout=subprocess.PIPE,
14 stderr=subprocess.PIPE,
15 text=True,
16 check=False
17 )
18 # save the output
19 output = result.stdout + result.stderr
20 # Regex pattern that matches the version string from the help message
21 version_pattern = re.compile(r'This is ASTRAL version (\d+\.\d+\.\d+)')
22 # search for the version pattern in the output
23 match = version_pattern.search(output)
24 if match:
25 # extract and return the version string
26 return match.group(1)
27 print("Version information not found in `astral --help` output.")
28 return None
29 except subprocess.CalledProcessError as e:
30 print(f"Command failed with error: {e}")
31 return None
32 except FileNotFoundError as e:
33 print(f"Command not found: {e}")
34 return None
35 except Exception as e:
36 print(f"An error occurred: {e}")
37 return None
38
39
40 # call the function and print the version
41 version = get_astral_version()
42 if version:
43 print(version)