Practice cython wrapping of C++
This short project is just to gain some experience on wrapping C++ code with Cython.
It contains basic representation of crossfit workouts/metcons, as well as a means a representation of the movements involded.
The following two samples show how to create a For Time wod Murph
, and an AMRAP, Mary
, as well as their representation.
Murph
:
>>> import wodext as wod
>>> murph = wod.PyForTime("Murph", time_cap=50)
>>> movements = [
... wod.PyMovement("run", distance=1600),
... wod.PyMovement("pull-up", reps=100),
... wod.PyMovement("push-up", reps=200),
... wod.PyMovement("air squat", reps=300),
... wod.PyMovement("run", distance=1600)
... ]
>>> for mov in movements:
>>> murph.add(mov)
>>> print(murph)
PyForTime
---------
- run 1600.0 m
- pull-up, reps: 100
- push-up, reps: 200
- air squat, reps: 300
- run 1600.0 m
---------
Mary
:
>>> mary = wod.PyAMRAP("Mary", time=20)
>>> movements = [
... wod.PyMovement("hspu", reps=5),
... wod.PyMovement("pistols", reps=10),
... wod.PyMovement("pull-up", reps=15)
... ]
>>>
>>> for mov in movements:
... mary.add(mov)
>>> print(mary)
PyAMRAP
-------
- hspu, reps: 5
- pistols, reps: 10
- pull-up, reps: 15
-------
Install the dependencies in a new virtual environment:
pip install -r requirements.txt
Build the extension:
make compile
Run the unit tests:
make test
If everything worked properly, the extension is importable from python as wodext
.
Personal references for future me.
Documentation
Sample packages including cython:
Inheritance