Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tych0 committed Jan 8, 2025
1 parent 2213aff commit e5211d4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
40 changes: 9 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ VENV=xcffib_venv
PYTHON=$(VENV)/bin/python3
FLAKE=$(VENV)/bin/flake8

GENERATOR_FILES=$(shell find . -path ./test -prune -false -o -name \*.hs)
HANDWRITTEN_MODULE_FILES=$(shell find ./module -name \*.py)

# you should have xcb-proto installed to run this
xcffib: xcffib_py_files xcffib.cabal $(shell find . -path ./test -prune -false -o -name \*.hs)
xcffib: xcffib.cabal $(GENERATOR_FILES) $(HANDWRITTEN_MODULE_FILES)
$(GEN) --input $(XCBDIR) --output ./xcffib
cp ./module/*.py ./xcffib/
touch ./xcffib/py.typed
sed -i -e "s/__xcb_proto_version__ = .*/__xcb_proto_version__ = \"${XCBVER}\"/" xcffib/__init__.py

xcffib_py_files: $(addprefix xcffib/, $(notdir $(wildcard module/*.py)))

xcffib/%.py: module/%.py
mkdir -p xcffib/
cp $^ $@
sed -i "s/__xcb_proto_version__ = .*/__xcb_proto_version__ = \"${XCBVER}\"/" xcffib/__init__.py

.PHONY: xcffib-fmt
xcffib-fmt: module/*.py
Expand Down Expand Up @@ -72,32 +70,12 @@ $(VENV): requirements.txt
python -m venv $(VENV)
$(PYTHON) -m pip install -r requirements.txt

check-abi: xcffib $(VENV)
# check abi precompiled mode
# make a temporary env to test install and ensure we cd somewhere
# we won't pick up the local source xcffib module
$(eval TMPLOC=$(shell mktemp -d))
python -m venv $(TMPLOC)
CC=/bin/false ${TMPLOC}/bin/python -m pip install --no-cache -v .
${TMPLOC}/bin/python -m pip install pytest pytest-xdist
${TMPLOC}/bin/python -c "import os; os.chdir('${TMPLOC}'); import xcffib; print(xcffib.cffi_mode); assert xcffib.cffi_mode == 'abi_precompiled'"
${TMPLOC}/bin/python -m pytest -v --durations=3 -n auto

check-api: xcffib $(VENV)
# check abi precompiled mode
# make a temporary env to test install and ensure we cd somewhere
# we won't pick up the local source xcffib module
$(eval TMPLOC=$(shell mktemp -d))
python -m venv ${TMPLOC}
${TMPLOC}/bin/python -m pip install -v --no-cache .
${TMPLOC}/bin/python -m pip install pytest pytest-xdist
${TMPLOC}/bin/python -c "import os; os.chdir('${TMPLOC}'); import xcffib; print(xcffib.cffi_mode); assert xcffib.cffi_mode == 'api'"
${TMPLOC}/bin/python -m pytest -v --durations=3 -n auto
check-mode-%: xcffib requirements.txt
./test/test_mode.sh $*

check: xcffib htests $(VENV) lint check-api check-abi
check: xcffib htests lint check-mode-api check-mode-abi_precompiled
$(CABAL) check
$(PYTHON) -m compileall xcffib
$(PYTHON) -m pytest -v --durations=3 -n $(NCPUS)

# make release ver=0.99.99
release: xcffib
Expand Down
27 changes: 27 additions & 0 deletions test/test_mode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -eux

MODE=$1

VENV=$(mktemp -d xcffib-test-$MODE.XXXXXXXXXX)

function cleanup {
rm -rf "${VENV}"
}
trap cleanup EXIT

# mask CC in abi_precompiled so that we force compilation at runtime
if [ "${MODE}" == "abi" ] || [ "${MODE}" == "abi_precompiled" ]; then
export CC=false
fi

python -m venv "${VENV}"
source "${VENV}/bin/activate"

pip install -r requirements.txt
pip install --no-cache -v .

# make a temporary env to test install and ensure we cd somewhere
# we won't pick up the local source xcffib module. the venv dir is as good a
# place as any
python -I -c "import xcffib; print(\"mode is\", xcffib.cffi_mode, \"path is\", xcffib.__file__); assert xcffib.cffi_mode == \"${MODE}\""
python -I -m pytest --durations=3 -n auto

0 comments on commit e5211d4

Please sign in to comment.