Skip to content

Commit 5c341fc

Browse files
committed
refactor: Adapt pytox to the new tox_system stuff.
1 parent 1c574ed commit 5c341fc

26 files changed

+546
-125
lines changed

.circleci/config.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
pkg-config
3131
python3-dev
3232
python3-setuptools
33-
- run: git clone --depth=1 https://github.com/TokTok/c-toxcore
33+
- run: git clone --recursive --depth=1 https://github.com/TokTok/c-toxcore
3434
- run: cd c-toxcore;
3535
. .github/scripts/flags-gcc.sh;
3636
add_flag -fsanitize=address;
@@ -44,10 +44,10 @@ jobs:
4444
-DTRACE=ON
4545
-DMUST_BUILD_TOXAV=ON
4646
- run: cd c-toxcore/_build && ninja install -j$(nproc)
47-
# - run:
48-
# export CFLAGS="-I$PWD/c-toxcore/_install/include -fsanitize=address";
49-
# export LDFLAGS="-L$PWD/c-toxcore/_install/lib -Wl,-rpath,$PWD/c-toxcore/_install/lib";
50-
# python3 setup.py build_ext --inplace
47+
- run:
48+
export CFLAGS="-I$PWD/c-toxcore/_install/include -fsanitize=address";
49+
export LDFLAGS="-L$PWD/c-toxcore/_install/lib -Wl,-rpath,$PWD/c-toxcore/_install/lib";
50+
python3 setup.py build_ext --inplace
5151
# - run: ASAN_OPTIONS=detect_leaks=0
5252
# LD_PRELOAD=libasan.so.5
5353
# PYTHONPATH=.

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.mypy_cache

BUILD.bazel

+39-3
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,59 @@ package(features = ["layering_check"])
55

66
project()
77

8+
SUBSYSTEMS = [
9+
"log",
10+
"memory",
11+
"network",
12+
"options",
13+
"random",
14+
"system",
15+
"time",
16+
]
17+
18+
[genrule(
19+
name = "pytox/" + sys,
20+
srcs = [
21+
"pytox/src/%s.pxd" % sys,
22+
"pytox/src/%s.pyx" % sys,
23+
"//c-toxcore:public",
24+
],
25+
outs = [
26+
"pytox/%s.pxd" % sys,
27+
"pytox/%s.pyx" % sys,
28+
],
29+
cmd = " ".join([
30+
"$(location //py_toxcore_c/tools:gen_api)",
31+
"$(location pytox/src/%s.pyx)" % sys,
32+
"$(GENDIR)/c-toxcore",
33+
"> $(location pytox/%s.pyx);" % sys,
34+
"$(location //py_toxcore_c/tools:gen_api)",
35+
"$(location pytox/src/%s.pxd)" % sys,
36+
"$(GENDIR)/c-toxcore",
37+
"> $(location pytox/%s.pxd)" % sys,
38+
]),
39+
tools = ["//py_toxcore_c/tools:gen_api"],
40+
) for sys in SUBSYSTEMS]
41+
842
genrule(
943
name = "pytox/core",
1044
srcs = [
1145
"pytox/src/core.pyx",
12-
"//c-toxcore:tox/tox.h",
46+
"//c-toxcore:tox/toxcore/tox.h",
1347
],
1448
outs = ["pytox/core.pyx"],
15-
cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(location //c-toxcore:tox/tox.h) > $@",
49+
cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(GENDIR)/c-toxcore > $@",
1650
tools = ["//py_toxcore_c/tools:gen_api"],
1751
)
1852

1953
pyx_library(
2054
name = "pytox",
2155
srcs = [
56+
"pytox.pxd",
2257
"pytox/av.pyx",
2358
"pytox/core.pyx",
24-
],
59+
"pytox/error.pyx",
60+
] + ["pytox/%s.pxd" % sys for sys in SUBSYSTEMS] + ["pytox/%s.pyx" % sys for sys in SUBSYSTEMS],
2561
cdeps = ["//c-toxcore"],
2662
cython_directives = {"language_level": "3"},
2763
visibility = ["//visibility:public"],

Dockerfile

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:22.04
22
LABEL maintainer="iphydf@gmail.com"
33

44
RUN apt-get update \
55
&& DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
66
ca-certificates \
77
cmake \
8-
cython \
98
gcc \
109
g++ \
1110
git \
@@ -19,23 +18,47 @@ RUN apt-get update \
1918
python3-pip \
2019
&& apt-get clean \
2120
&& rm -rf /var/lib/apt/lists/* \
22-
&& pip3 install mypy
21+
&& pip3 install cython mypy
2322

2423
WORKDIR /build
25-
RUN git clone --depth=1 https://github.com/TokTok/c-toxcore /build/c-toxcore \
24+
RUN git clone --recursive --depth=1 --branch=system https://github.com/iphydf/c-toxcore /build/c-toxcore \
2625
&& cmake -GNinja -B/build/c-toxcore/_build -H/build/c-toxcore \
2726
-DBOOTSTRAP_DAEMON=OFF \
2827
-DENABLE_STATIC=OFF \
2928
-DMUST_BUILD_TOXAV=ON \
3029
&& cmake --build /build/c-toxcore/_build --target install --parallel "$(nproc)" \
31-
&& ldconfig
30+
&& ldconfig && echo 2
3231

33-
COPY pytox /build/pytox
32+
# Tools first, they change less.
3433
COPY tools /build/tools
34+
COPY pytox.pxd /build/
35+
COPY pytox /build/pytox
3536

3637
RUN mypy --strict tools/gen_api.py \
37-
&& tools/gen_api.py pytox/src/core.pyx /usr/local/include/tox/tox.h > pytox/core.pyx \
38-
&& cython pytox/av.pyx pytox/core.pyx
38+
&& tools/gen_api.py pytox/src/core.pyx /usr/local/include > pytox/core.pyx \
39+
&& tools/gen_api.py pytox/src/log.pxd /usr/local/include > pytox/log.pxd \
40+
&& tools/gen_api.py pytox/src/log.pyx /usr/local/include > pytox/log.pyx \
41+
&& tools/gen_api.py pytox/src/memory.pxd /usr/local/include > pytox/memory.pxd \
42+
&& tools/gen_api.py pytox/src/memory.pyx /usr/local/include > pytox/memory.pyx \
43+
&& tools/gen_api.py pytox/src/network.pxd /usr/local/include > pytox/network.pxd \
44+
&& tools/gen_api.py pytox/src/network.pyx /usr/local/include > pytox/network.pyx \
45+
&& tools/gen_api.py pytox/src/options.pxd /usr/local/include > pytox/options.pxd \
46+
&& tools/gen_api.py pytox/src/options.pyx /usr/local/include > pytox/options.pyx \
47+
&& tools/gen_api.py pytox/src/random.pxd /usr/local/include > pytox/random.pxd \
48+
&& tools/gen_api.py pytox/src/random.pyx /usr/local/include > pytox/random.pyx \
49+
&& tools/gen_api.py pytox/src/system.pxd /usr/local/include > pytox/system.pxd \
50+
&& tools/gen_api.py pytox/src/system.pyx /usr/local/include > pytox/system.pyx \
51+
&& tools/gen_api.py pytox/src/time.pxd /usr/local/include > pytox/time.pxd \
52+
&& tools/gen_api.py pytox/src/time.pyx /usr/local/include > pytox/time.pyx \
53+
&& cython -I $PWD -X "language_level=3" --line-directives pytox/av.pyx pytox/core.pyx \
54+
pytox/error.pyx \
55+
pytox/log.pyx \
56+
pytox/memory.pyx \
57+
pytox/network.pyx \
58+
pytox/options.pyx \
59+
pytox/random.pyx \
60+
pytox/system.pyx \
61+
pytox/time.pyx
3962

4063
COPY setup.py /build/
4164
RUN python3 setup.py install \

pytox.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

pytox/.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/core.pxd
2+
/core.pyx
3+
/log.pxd
4+
/log.pyx
5+
/memory.pxd
6+
/memory.pyx
7+
/network.pxd
8+
/network.pyx
9+
/random.pxd
10+
/random.pyx
11+
/system.pxd
12+
/system.pyx
13+
/time.pxd
14+
/time.pyx

pytox/error.pyx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class UseAfterFreeException(Exception):
2+
def __init__(self):
3+
super().__init__(
4+
"object used after it was killed/freed (or it was never initialised)")
5+
6+
class ToxException(Exception):
7+
pass
8+
9+
class ApiException(ToxException):
10+
def __init__(self, err):
11+
super().__init__(err)
12+
self.error = err
13+
14+
class LengthException(ToxException):
15+
pass

0 commit comments

Comments
 (0)