Commit 3b124483 authored by Richard Berger's avatar Richard Berger
Browse files

Add Python::has_minimum_version

parent 8b75fb29
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -75,24 +75,20 @@ using namespace LAMMPS_NS;

kimProperty::kimProperty(LAMMPS *lmp) : Pointers(lmp)
{
#if LMP_PYTHON
#if PY_MAJOR_VERSION != 3
  // one-time initialization of Python interpreter
  python->init();

  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.");
#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
  }
}

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.");

+7 −0
Original line number Diff line number Diff line
@@ -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);
}
+1 −0
Original line number Diff line number Diff line
@@ -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;
+8 −0
Original line number Diff line number Diff line
@@ -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);
}
+2 −0
Original line number Diff line number Diff line
@@ -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();