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