py-pgproto
py-pgproto copied to clipboard
Cython compilation error with const variable assignments in datetime.pyx (commit a29a6f6a)
When building from a29a6f6aaa09013cb33ffadb8dd57e21d671ab55 there are compilation errors on 3.12. On relatively newer versions of cython declaring a const at module initialization has been deprecated.
Error compiling Cython file:
------------------------------------------------------------
...
pg_epoch_date = datetime.date(2000, 1, 1)
cdef int32_t pg_date_offset_ord = \
<int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())
# Binary representations of infinity for datetimes.
cdef const int64_t pg_time64_infinity = 0x7fffffffffffffff
^
------------------------------------------------------------
asyncpg/pgproto/./codecs/datetime.pyx:30:5: Assignment to const 'pg_time64_infinity'
Error compiling Cython file:
------------------------------------------------------------
...
cdef int32_t pg_date_offset_ord = \
<int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())
# Binary representations of infinity for datetimes.
cdef const int64_t pg_time64_infinity = 0x7fffffffffffffff
cdef const int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
^
------------------------------------------------------------
asyncpg/pgproto/./codecs/datetime.pyx:31:5: Assignment to const 'pg_time64_negative_infinity'
Error compiling Cython file:
------------------------------------------------------------
...
<int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())
# Binary representations of infinity for datetimes.
cdef const int64_t pg_time64_infinity = 0x7fffffffffffffff
cdef const int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
cdef const int32_t pg_date_infinity = 0x7fffffff
^
------------------------------------------------------------
asyncpg/pgproto/./codecs/datetime.pyx:32:5: Assignment to const 'pg_date_infinity'
Error compiling Cython file:
------------------------------------------------------------
...
# Binary representations of infinity for datetimes.
cdef const int64_t pg_time64_infinity = 0x7fffffffffffffff
cdef const int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
cdef const int32_t pg_date_infinity = 0x7fffffff
cdef const int32_t pg_date_negative_infinity = <int32_t>0x80000000
^
------------------------------------------------------------
asyncpg/pgproto/./codecs/datetime.pyx:33:5: Assignment to const 'pg_date_negative_infinity'
Compiling asyncpg/pgproto/pgproto.pyx because it changed.
Compiling asyncpg/protocol/protocol.pyx because it changed.
[1/2] Cythonizing asyncpg/pgproto/pgproto.pyx
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
main()
File "/usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main
json_out["return_val"] = hook(**hook_input["kwargs"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 175, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/setuptools/build_meta.py", line 374, in prepare_metadata_for_build_wheel
self.run_setup()
File "/usr/local/lib/python3.12/site-packages/setuptools/build_meta.py", line 317, in run_setup
exec(code, locals())
File "<string>", line 234, in <module>
File "/usr/local/lib/python3.12/site-packages/setuptools/__init__.py", line 115, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186, in setup
return run_commands(dist)
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
dist.run_commands()
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python3.12/site-packages/setuptools/dist.py", line 1102, in run_command
super().run_command(command)
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
cmd_obj.run()
File "/usr/local/lib/python3.12/site-packages/setuptools/command/dist_info.py", line 94, in run
self.egg_info.run()
File "/usr/local/lib/python3.12/site-packages/setuptools/command/egg_info.py", line 312, in run
self.find_sources()
File "/usr/local/lib/python3.12/site-packages/setuptools/command/egg_info.py", line 320, in find_sources
mm.run()
File "/usr/local/lib/python3.12/site-packages/setuptools/command/egg_info.py", line 543, in run
self.add_defaults()
File "/usr/local/lib/python3.12/site-packages/setuptools/command/egg_info.py", line 581, in add_defaults
sdist.add_defaults(self)
File "/usr/local/lib/python3.12/site-packages/setuptools/command/sdist.py", line 109, in add_defaults
super().add_defaults()
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/command/sdist.py", line 245, in add_defaults
self._add_defaults_ext()
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/command/sdist.py", line 329, in _add_defaults_ext
build_ext = self.get_finalized_command('build_ext')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 334, in get_finalized_command
cmd_obj.ensure_finalized()
File "/usr/local/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 135, in ensure_finalized
self.finalize_options()
File "<string>", line 216, in finalize_options
File "/usr/local/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
cythonize_one(*args)
File "/usr/local/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: asyncpg/pgproto/pgproto.pyx
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> No available output.
note: This error originates from a subprocess, and is likely not a problem with pip.
full command: /usr/local/bin/python3.12 /usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpk5opk_pk
cwd: /tmp/eugo/asyncpg
Preparing metadata (pyproject.toml) ... error
error: metadata-generation-failed
Fix
Remove the const keyword from lines 30-33 in codecs/datetime.pyx:
# Change from:
cdef const int64_t pg_time64_infinity = 0x7fffffffffffffff
cdef const int64_t pg_time64_negative_infinity = 0x8000000000000000
cdef const int32_t pg_date_infinity = 0x7fffffff
cdef const int32_t pg_date_negative_infinity = 0x80000000
# To:
cdef int64_t pg_time64_infinity = 0x7fffffffffffffff
cdef int64_t pg_time64_negative_infinity = 0x8000000000000000
cdef int32_t pg_date_infinity = 0x7fffffff
cdef int32_t pg_date_negative_infinity = 0x80000000