Add Python::has_minimum_version

This commit is contained in:
Richard Berger
2020-03-27 16:28:43 -04:00
parent 8b75fb2950
commit 3b1244831e
5 changed files with 25 additions and 11 deletions

View File

@ -75,24 +75,20 @@ using namespace LAMMPS_NS;
kimProperty::kimProperty(LAMMPS *lmp) : Pointers(lmp)
{
#if LMP_PYTHON
#if PY_MAJOR_VERSION != 3
error->all(FLERR, "Invalid Python version.\n"
"The kim-property Python package requires Python "
"3 >= 3.6 support.");
#endif
// one-time initialization of Python interpreter
python->init();
#else
error->all(FLERR, "Error Python support missing! Compile with PYTHON "
"package installed!");
#endif // LMP_PYTHON
if (!python->has_minimum_version(3, 6)) {
error->all(FLERR, "Invalid Python version.\n"
"The kim-property Python package requires Python "
"3 >= 3.6 support.");
}
}
void kimProperty::command(int narg, char **arg)
{
#if LMP_PYTHON
#if PY_MAJOR_VERSION == 3
#if PY_MAJOR_VERSION >= 3
if (narg < 2)
error->all(FLERR, "Invalid `kim_property` command.");

View File

@ -535,3 +535,10 @@ void PythonImpl::deallocate(int i)
delete [] pfuncs[i].ovarname;
delete [] pfuncs[i].longstr;
}
/* ------------------------------------------------------------------ */
bool PythonImpl::has_minimum_version(int major, int minor)
{
return (PY_MAJOR_VERSION == major && PY_MINOR_VERSION >= minor) || (PY_MAJOR_VERSION > major);
}

View File

@ -32,6 +32,7 @@ class PythonImpl : protected Pointers, public PythonInterface {
char *long_string(int);
int execute_string(char *);
int execute_file(char *);
bool has_minimum_version(int major, int minor);
private:
int ninput,noutput,length_longstr;

View File

@ -117,3 +117,11 @@ int Python::execute_file(char *fname)
init();
return impl->execute_file(fname);
}
/* ------------------------------------------------------------------ */
bool Python::has_minimum_version(int major, int minor)
{
init();
return impl->has_minimum_version(major, minor);
}

View File

@ -28,6 +28,7 @@ public:
virtual char * long_string(int ifunc) = 0;
virtual int execute_string(char *) = 0;
virtual int execute_file(char *) = 0;
virtual bool has_minimum_version(int major, int minor) = 0;
};
class Python : protected Pointers {
@ -42,6 +43,7 @@ public:
char * long_string(int ifunc);
int execute_string(char *);
int execute_file(char *);
bool has_minimum_version(int major, int minor);
bool is_enabled() const;
void init();