Pygradle is used to build a python project.


The problem is that the CI runs a different Python version, resulting in different build outcomes, e.g. the build succeeded on the laptop, but failed on CI.


============================= test session starts ==============================
platform linux -- Python 3.6.3, pytest-2.9.1, py-1.4.29, pluggy-0.3.1
rootdir: /home/travis/build/user/project, inifile: 
plugins: cov-2.2.1
collected 1 items


============================= test session starts ==============================
platform linux2 -- Python 2.7.5, pytest-2.9.1, py-1.4.29, pluggy-0.3.1
rootdir: /home/user/dev/project, inifile: 
plugins: cov-2.2.1
collected 1 items


To ensure that the build fails both locally on CI and on the laptop, the same python version should be used.


Is it possible to set a minimum Python version in Pygradle?


Side note: personally I dislike using a minimum version: you never know beforehand how the language will evolve and if a certain future version will still be compatible with your code. For example many 2.7-compatible scripts can't actually work with python 3.X, setting 2.7 as the minimum version won't cut it.

I prefer to explicitly list as allowed the (existing) versions that I can test and confirm to be compatible. Any future version can be added later on, after such confirmation is obtained.

If you agree with the above then the com.linkedin.python plugin can apparently perform such version checks (it doesn't looks like it supports a minimum version):

Default and allowed Python version

This plugin enforces a set of default and allowed Python versions. For example, you can specify pythonVersion = '3' and you will get whatever the default Python 3 version is. Similarly pythonVersion = '2' gets you whatever the default Python 2 version is.

This plugin also enforces a set of allowed Python versions. If you choose a Python version that is not allowed, you will see an error messages such as:

Python 3.2 not allowed; choose from [2.6, 2.7, 3.4, 3.5, 3.6]

If you see this error message, you must adjust your pythonVersion setting to one of the allowed values.

Consumers of this extension can change the default Python 2, Python 3, and allowed versions by making a call on the PythonDetails object, either the one returned by PythonExtension.getDetails() or on any PythonDetails instance you create, e.g. in Groovy:

pythonDetails.setPythonDefaultVersions('2.7', '3.6', ['2.7', '3.5', '3.6'])

But I'm not familiar with pygradle, I can't really tell exactly how the plugin works and/or is configured to do the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.