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 afba833
Show file tree
Hide file tree
Showing 21 changed files with 1,651 additions and 606 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
*.o
*.tox
.mypy_cache
# TODO(iphydf): Remove once .gen is removed from the name.
*.gen.pyx
46 changes: 31 additions & 15 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,41 @@ 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",
],
# TODO(iphydf): Remove.
exclude = ["**/*.gen.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"],
)
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ 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 \
&& python3 -c 'from pytox import core; print(core.__doc__)'
&& python3 -c 'import pytox.toxcore.tox as core; print(core.__doc__)'

COPY test /build/test
RUN python3 test/core_test.py
RUN python3 test/tox_test.py
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 afba833

Please sign in to comment.