I would like to execute a python script via maven (say maven-antrun-plugin) only if the python runtime version is 3.2. How do I enforce this restriction via maven?
Asked
Active
Viewed 500 times
2
-
1http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script ? – Henry Jul 29 '11 at 10:32
-
is it acceptable to put the restriction in the script (`if sys.version_info[0:2] != (3, 2): sys.exit(1)`)? – Katriel Jul 29 '11 at 10:33
-
I would prefer if the enforcement can be done at the maven script and not within the python script. If its going to be harder doing via the maven script, I would probably modify the python script. – Joe Jul 29 '11 at 10:37
-
(1) Are you asking about writing a maven-ant plug in? If so, this is probably a Java question. (2) What do you think you mean by "python runtime version"? I've got 3.2 and 2.7 both running on this computer. What would you consider my "python runtime version"? – S.Lott Jul 29 '11 at 11:12
-
My understanding is that user has to pass information on python.home to the maven antrun plugin as an argument, I would like to use that information and stop running if it happens to be anything lesser than 3.2. – Joe Sep 01 '11 at 07:48
2 Answers
2
How would maven execute this script? Call it directly, or call python <script>
? Note that there may be several versions of Python installed on a single machine simultaneously.
In any case, to know what your system understands by "python", you can always run:
python --version
and parse the output.
Or some variation on this to provide the facts your script needs.
python -c 'import sys;print sys.version_info'

S.Lott
- 384,516
- 81
- 508
- 779

Eli Bendersky
- 263,248
- 89
- 350
- 412
-
My code base could be checked out on any dev machine and I just want to make sure that I am using python 3.2 and not anything lesser. I would like this check to be done programatically before executing the python script in the maven-antrun-plugin – Joe Sep 01 '11 at 07:50
0
Put in a hard exit as follow:
import sys
assert sys.version_info >= (3, 7, 9), f"Minimum python version supported is 3.7.9. Current version is: {sys.version}"
If fails, it will exit with AssertionError: Minimum python version supported is 3.7.9. Current version is: 3.7.8 (default, Dec 19 2020, 14:37:46)

Timothy C. Quinn
- 3,739
- 1
- 35
- 47