diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..15db22e67 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include msgq *.h *.cc *.pyx *.pxd diff --git a/msgq/__init__.py b/msgq/__init__.py index 574e100a8..54cc1427a 100644 --- a/msgq/__init__.py +++ b/msgq/__init__.py @@ -1,18 +1,13 @@ -# must be built with scons +import os +from typing import Optional, List, Union + +BASEDIR = os.path.dirname(os.path.abspath(__file__)) +INCLUDE_PATH = os.path.abspath(os.path.join(BASEDIR, "../")) + from msgq.ipc_pyx import Context, Poller, SubSocket, PubSocket, SocketEventHandle, toggle_fake_events, \ set_fake_prefix, get_fake_prefix, delete_fake_prefix, wait_for_one_event from msgq.ipc_pyx import MultiplePublishersError, IpcError -from typing import Optional, List, Union - -assert MultiplePublishersError -assert IpcError -assert toggle_fake_events -assert set_fake_prefix -assert get_fake_prefix -assert delete_fake_prefix -assert wait_for_one_event - NO_TRAVERSAL_LIMIT = 2**64-1 context = Context() diff --git a/pyproject.toml b/pyproject.toml index efbb89ad7..27ea44e3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,33 +1,34 @@ [project] name = "msgq" -version = "0.0.1" -description = "Code powering the comma.ai panda" -readme = "README.md" +version = "0.1.0" +description = "Lock-free IPC message queue and VisionIPC" requires-python = ">=3.11,<3.13" license = {text = "MIT"} authors = [{name = "comma.ai"}] -classifiers = [ - "Natural Language :: English", - "Programming Language :: Python :: 3", - "Topic :: System :: Hardware", -] dependencies = [ - "setuptools", # for distutils - "Cython", - "scons", - "ruff", - "parameterized", - "coverage", "numpy", - "pytest", - "pytest-retry", - "cppcheck", - "cpplint", - "codespell", - "ty", - "lefthook", ] +[project.optional-dependencies] +dev = [ + "setuptools", "Cython", "scons", "ruff", + "parameterized", "coverage", "numpy", + "pytest", "pytest-retry", + "cppcheck", "cpplint", "codespell", "ty", "lefthook", +] + +[build-system] +requires = ["setuptools", "Cython", "numpy"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.package-data] +"msgq" = ["*.h", "*.cc", "*.pyx", "*.pxd"] +"msgq.visionipc" = ["*.h", "*.cc", "*.pyx", "*.pxd"] +"msgq.logger" = ["*.h"] + # https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml [tool.ruff] lint.select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100", "A"] @@ -47,6 +48,7 @@ exclude = ["site_scons/"] [tool.ty.rules] # Cython modules are compiled at build time, not available for static analysis unresolved-import = "ignore" +possibly-missing-attribute = "ignore" [tool.pytest.ini_options] addopts = "--durations=10" diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..d8a3e7931 --- /dev/null +++ b/setup.py @@ -0,0 +1,46 @@ +import os +import numpy as np +from setuptools import setup +from Cython.Build import cythonize +from setuptools import Extension + +msgq_dir = os.path.dirname(os.path.abspath(__file__)) + +# Common C++ compile args +cpp_args = ["-std=c++17", "-fPIC", "-O2"] + +# msgq core C++ sources +msgq_cc_sources = [ + "msgq/ipc.cc", + "msgq/event.cc", + "msgq/impl_msgq.cc", + "msgq/impl_fake.cc", + "msgq/msgq.cc", +] + +# visionipc C++ sources +vipc_cc_sources = [ + "msgq/visionipc/visionipc.cc", + "msgq/visionipc/visionipc_server.cc", + "msgq/visionipc/visionipc_client.cc", + "msgq/visionipc/visionbuf.cc", +] + +extensions = [ + Extension( + "msgq.ipc_pyx", + sources=["msgq/ipc_pyx.pyx"] + msgq_cc_sources, + language="c++", + extra_compile_args=cpp_args, + include_dirs=[msgq_dir, np.get_include()], + ), + Extension( + "msgq.visionipc.visionipc_pyx", + sources=["msgq/visionipc/visionipc_pyx.pyx"] + vipc_cc_sources + msgq_cc_sources, + language="c++", + extra_compile_args=cpp_args, + include_dirs=[msgq_dir, np.get_include()], + ), +] + +setup(ext_modules=cythonize(extensions, language_level="3"))