Skip to content

Commit

Permalink
feat: add cython
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jun 16, 2023
1 parent 7fea718 commit 1f7e83a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
35 changes: 35 additions & 0 deletions build_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Build optional cython modules."""

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


class BuildExt(build_ext):
def build_extensions(self) -> None:
with contextlib.suppress(Exception):
super().build_extensions()


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

setup_kwargs.update(
dict(
ext_modules=cythonize(
[
"src/kasa_crypt/kasa_crypt.py",
],
compiler_directives={"language_level": "3"}, # Python 3
),
cmdclass=dict(build_ext=BuildExt),
)
)
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 @@ -17,6 +17,10 @@ packages = [
{ include = "kasa_crypt", from = "src" },
]

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

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/bdraco/kasa-crypt/issues"
"Changelog" = "https://github.com/bdraco/kasa-crypt/blob/main/CHANGELOG.md"
Expand Down Expand Up @@ -73,5 +77,5 @@ module = "tests.*"
allow_untyped_defs = true

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ['setuptools>=65.4.1', 'wheel', 'Cython', "poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
9 changes: 0 additions & 9 deletions setup.py

This file was deleted.

0 comments on commit 1f7e83a

Please sign in to comment.