DerwenAI / kglab

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, NetworkX, RAPIDS, RDFlib, pySHACL, PyVis, morph-kgc, pslpython, pyarrow, etc.
https://derwen.ai/docs/kgl/
MIT License
574 stars 65 forks source link

Support for Python 3.12 #341

Open IshanDindorkar opened 2 months ago

IshanDindorkar commented 2 months ago

I'm submitting a

Current Behaviour:

Recently, I tried to upgrade Python version to 3.12 in my dev environment. After this, my GitHub Actions pipeline started failing since one of the dependency for kglab didn't get installed, giving errors as shown below in the error log

 ChefBuildError

  Backend subprocess exited when trying to invoke get_requires_for_build_wheel

  /tmp/tmpxhi1ycbn/s3fs-0.2.0/versioneer.py:421: SyntaxWarning: invalid escape sequence '\s'
    LONG_VERSION_PY['git'] = '''
  Traceback (most recent call last):
    File "/github/home/.local/share/pypoetry/venv/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in <module>
      main()
    File "/github/home/.local/share/pypoetry/venv/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 357, in main
      json_out["return_val"] = hook(**hook_input["kwargs"])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/github/home/.local/share/pypoetry/venv/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 134, in get_requires_for_build_wheel
      return hook(config_settings)
             ^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/tmpwivoet33/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=[])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/tmpwivoet33/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires
      self.run_setup()
    File "/tmp/tmpwivoet33/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 497, in run_setup
      super().run_setup(setup_script=setup_script)
    File "/tmp/tmpwivoet33/.venv/lib/python3.12/site-packages/setuptools/build_meta.py", line 313, in run_setup
      exec(code, locals())
    File "<string>", line 7, in <module>
    File "/tmp/tmpxhi1ycbn/s3fs-0.2.0/versioneer.py", line 1480, in get_version
      return get_versions()["version"]
             ^^^^^^^^^^^^^^
    File "/tmp/tmpxhi1ycbn/s3fs-0.2.0/versioneer.py", line 1412, in get_versions
      cfg = get_config_from_root(root)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/tmpxhi1ycbn/s3fs-0.2.0/versioneer.py", line 342, in get_config_from_root
      parser = configparser.SafeConfigParser()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  AttributeError: module 'configparser' has no attribute 'SafeConfigParser'. Did you mean: 'RawConfigParser'?

  at ~/.local/share/pypoetry/venv/lib/python3.12/site-packages/poetry/installation/chef.py:164 in _prepare
      160│ 
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│ 
      163│             if error is not None:
    → 164│                 raise error from None
      165│ 
      166│             return path
      167│ 
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with s3fs (0.2.0) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "s3fs (==0.2.0)"'.

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel

  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-cpython-312
  creating build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/__init__.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_classpath.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_core.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_gui.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jarray.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jclass.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jcollection.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jcustomizer.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jexception.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jinit.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jio.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jmethod.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jobject.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jpackage.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jproxy.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jstring.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jthread.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jvmfinder.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_pykeywords.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/beans.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/config.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/dbapi2.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/imports.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/nio.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/pickle.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/protocol.py -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/types.py -> build/lib.linux-x86_64-cpython-312/jpype
  creating build/lib.linux-x86_64-cpython-312/jpype/_pyinstaller
  copying jpype/_pyinstaller/entry_points.py -> build/lib.linux-x86_64-cpython-312/jpype/_pyinstaller
  copying jpype/_pyinstaller/example.py -> build/lib.linux-x86_64-cpython-312/jpype/_pyinstaller
  copying jpype/_pyinstaller/hook-jpype.py -> build/lib.linux-x86_64-cpython-312/jpype/_pyinstaller
  copying jpype/_pyinstaller/test_jpype_pyinstaller.py -> build/lib.linux-x86_64-cpython-312/jpype/_pyinstaller
  copying jpype/_core.pyi -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jcollection.pyi -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jio.pyi -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jstring.pyi -> build/lib.linux-x86_64-cpython-312/jpype
  copying jpype/_jthread.pyi -> build/lib.linux-x86_64-cpython-312/jpype
  running build_ext
  Call build extensions
  Using Jar cache
  copying native/jars/org.jpype.jar -> build/lib.linux-x86_64-cpython-312
  Call build ext
  building '_jpype' extension
  creating build/temp.linux-x86_64-cpython-312
  creating build/temp.linux-x86_64-cpython-312/native
  creating build/temp.linux-x86_64-cpython-312/native/common
  creating build/temp.linux-x86_64-cpython-312/native/python
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_array.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_array.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_arrayclass.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_arrayclass.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_booleantype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_booleantype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_boxedtype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_boxedtype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_buffer.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_buffer.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_buffertype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_buffertype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_bytetype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_bytetype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_chartype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_chartype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_class.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_class.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_classhints.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_classhints.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_classloader.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_classloader.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_classtype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_classtype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_context.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_context.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_convert.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_convert.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_doubletype.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_doubletype.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_encoding.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_encoding.o -g0 -std=c++11 -O2
  gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -Wall -fPIC -Inative/common/include -Inative/python/include -Inative/embedded/include -Inative/jni_include -I/tmp/tmpo9gf9a5m/.venv/include -I/usr/local/include/python3.12 -c native/common/jp_exception.cpp -o build/temp.linux-x86_64-cpython-312/native/common/jp_exception.o -g0 -std=c++11 -O2
  native/common/jp_exception.cpp: In function ‘PyTracebackObject* tb_create(PyTracebackObject*, PyObject*, const char*, const char*, int)’:
  native/common/jp_exception.cpp:524:23: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘frame’; did you mean ‘cframe’?
    524 |                 state.frame = last_traceback->tb_frame;
        |                       ^~~~~
        |                       cframe
  native/common/jp_exception.cpp:526:23: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘frame’; did you mean ‘cframe’?
    526 |                 state.frame = NULL;
        |                       ^~~~~
        |                       cframe
  native/common/jp_exception.cpp:552:36: error: invalid use of incomplete type ‘PyFrameObject’ {aka ‘struct _frame’}
    552 |         traceback->tb_lasti = frame->f_lasti;
        |                                    ^~
  In file included from /usr/local/include/python3.12/Python.h:42,
                   from native/common/jp_exception.cpp:16:
  /usr/local/include/python3.12/pytypedefs.h:22:16: note: forward declaration of ‘PyFrameObject’ {aka ‘struct _frame’}
     22 | typedef struct _frame PyFrameObject;
        |                ^~~~~~
  error: command '/usr/bin/gcc' failed with exit code 1

  at ~/.local/share/pypoetry/venv/lib/python3.12/site-packages/poetry/installation/chef.py:164 in _prepare
      160│ 
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│ 
      163│             if error is not None:
    → 164│                 raise error from None
      165│ 
      166│             return path
      167│ 
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with jpype1 (1.4.0) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "jpype1 (==1.4.0)"'.

On doing some investigation, I found that jpype is needed by pslpython which in turn is a dependency for kglab. When I tried to revert back to Python 3.10, the issue got resolved.

Expected Behaviour:

The kglab library should have support for Python version 3.12 and should get installed without any errors.

Steps to reproduce:

  1. Create a new conda environment with Python version 3.12
    conda create -n test_kglab python=3.12
  2. Install kglab
    poetry add kglab 
    poetry install

Snapshot:

Environment:

* python version: 3.12 * pip version: 24.0 * OS details: Ubuntu 20.04