Skip to content

Commit

Permalink
feat: add cython pxd for base_scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 3, 2023
1 parent 12cc76f commit 8f3cf16
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
45 changes: 45 additions & 0 deletions build_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Build optional cython modules."""

import logging
import os
from distutils.command.build_ext import build_ext
from typing import Any

_LOGGER = logging.getLogger(__name__)


class BuildExt(build_ext):
"""Build extension."""

def build_extensions(self) -> None:
"""Build extensions."""
try:
super().build_extensions()
except Exception as ex: # nosec
_LOGGER.debug("Failed to build extensions: %s", ex, exc_info=True)
pass


def build(setup_kwargs: Any) -> None:
"""Build optional cython modules."""
if os.environ.get("SKIP_CYTHON", False):
return
try:
from Cython.Build import cythonize

setup_kwargs.update(
{
"ext_modules": cythonize(
["src/habluetooth/base_scanner.py"],
compiler_directives={"language_level": "3"}, # Python 3
),
"cmdclass": {"build_ext": BuildExt},
}
)
setup_kwargs["exclude_package_data"] = {
pkg: ["*.c"] for pkg in setup_kwargs["packages"]
}
except Exception:
if os.environ.get("REQUIRE_CYTHON"):
raise
pass
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ packages = [
{ include = "habluetooth", from = "src" },
]

[tool.poetry.build]
generate-setup-file = true
script = "build_ext.py"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/bluetooth-devices/habluetooth/issues"
"Changelog" = "https://github.com/bluetooth-devices/habluetooth/blob/main/CHANGELOG.md"
Expand Down Expand Up @@ -147,5 +151,5 @@ module = "docs.*"
ignore_errors = true

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ['setuptools>=65.4.1', 'Cython', "poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 8f3cf16

Please sign in to comment.