Skip to content

Commit

Permalink
refactor: Use apigen to generate cython.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jan 7, 2024
1 parent 3a9e66b commit 7cf088b
Show file tree
Hide file tree
Showing 20 changed files with 1,601 additions and 604 deletions.
42 changes: 27 additions & 15 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@ load("//tools/project:build_defs.bzl", "project")

project(license = "gpl3-https")

genrule(
name = "pytox/core",
srcs = [
"pytox/src/core.pyx",
"//c-toxcore:tox/tox.h",
],
outs = ["pytox/core.pyx"],
cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(location //c-toxcore:tox/tox.h) > $@",
tools = ["//py_toxcore_c/tools:gen_api"],
)
#genrule(
# name = "pytox/core",
# srcs = [
# "pytox/src/core.pyx",
# "//c-toxcore:tox/tox.h",
# ],
# outs = ["pytox/core.pyx"],
# cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(location //c-toxcore:tox/tox.h) > $@",
# tools = ["//py_toxcore_c/tools:gen_api"],
#)

pyx_library(
name = "pytox",
srcs = [
"pytox/av.pyx",
"pytox/core.pyx",
],
srcs = glob([
"pytox/**/*.pxd",
"pytox/**/*.pyx",
]),
cdeps = ["//c-toxcore"],
cython_directives = {"language_level": "3"},
cython_directives = {
"embedsignature": "True",
"embedsignature.format": "python",
"language_level": "3",
},
tags = ["no-cross"],
visibility = ["//visibility:public"],
)

genrule(
name = "pytox_stubs",
outs = [mod[:-4] + ".pyi" for mod in glob(["pytox/**/*.pyx"])],
cmd = "$(location //py_toxcore_c/tools:stubgen) -o $(GENDIR)/py_toxcore_c" + " ".join([" -m %s" % mod[:-4].replace("/", ".") for mod in glob(["pytox/**/*.pyx"])]),
tags = ["manual"],
tools = ["//py_toxcore_c/tools:stubgen"],
)
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ RUN git clone --depth=1 --recursive https://github.com/TokTok/c-toxcore /build/c
&& ldconfig

COPY pytox /build/pytox
COPY tools /build/tools

RUN mypy --strict tools/gen_api.py \
&& tools/gen_api.py pytox/src/core.pyx /usr/local/include/tox/tox.h > pytox/core.pyx \
&& cython pytox/av.pyx pytox/core.pyx
RUN cython -I. $(find pytox -name "*.pyx")

COPY setup.py /build/
RUN python3 setup.py install \
Expand Down
6 changes: 0 additions & 6 deletions pytox/av.pyx

This file was deleted.

233 changes: 0 additions & 233 deletions pytox/src/core.pyx

This file was deleted.

Loading

0 comments on commit 7cf088b

Please sign in to comment.