Skip to content

Commit 1cdb8cb

Browse files
tych0Tycho Andersen
authored andcommitted
ci: always use $PATH python
Consider the following output form `which python3` and `which pytest-3` in the CI environment: which python3 shell: /usr/bin/bash -e {0} env: pythonLocation: /opt/hostedtoolcache/Python/3.10.15/x64 PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.15/x64/lib/pkgconfig Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64 Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64 Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64 LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.15/x64/lib /opt/hostedtoolcache/Python/3.10.15/x64/bin/python3 which pytest-3 shell: /usr/bin/bash -e {0} env: pythonLocation: /opt/hostedtoolcache/Python/3.10.15/x64 PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.15/x64/lib/pkgconfig Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64 Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64 Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64 LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.15/x64/lib /usr/bin/pytest-3 Since we were getting e.g. cffi vi `apt-get install python3-cffi`, we were using the *system* python's cffi for everything. That worked because we invoked the *system* pytest-3. Of course, that means we were not really using the github python action's python in our CI matrix, since we were always using the system python for everything. Instead, let's set up a venv as a traditional project would, and that way we can explicitly call that venv's python everywhere in the makefile, so we always use that venv's packages and get the right python. Then, we need only be careful to use the $PATH python, not /usr/bin/python, to set up this venv, and we always get the right version of python to test with. This likely explains some weirdness that I've seen in the past, should have investigated sooner... Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
1 parent d91df9f commit 1cdb8cb

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
with:
2626
ghc-version: '9.6'
2727
cabal-version: latest
28-
- run: cabal update
29-
- run: sudo apt install x11-apps python3-pytest python3-cffi python3-pytest-xdist flake8
28+
- run: sudo apt install x11-apps
3029
- run: git clone https://gitlab.freedesktop.org/xorg/proto/xcbproto.git proto && cd proto && git checkout ${{ matrix.xcbver }}
3130
- run: make XCBDIR=./proto/src check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dist-newstyle
77
*__pycache__*
88
*.egg-info
99
xcffib
10+
xcffib_venv
1011
build/
1112
*egg*
1213
*deb

Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ NCPUS=$(shell grep -c processor /proc/cpuinfo)
1010
PARALLEL=$(shell which parallel)
1111
CABAL=cabal --config-file=./cabal.config
1212
GEN=$(CABAL) new-run --minimize-conflict-set -j$(NCPUS) exe:xcffibgen --
13+
VENV=xcffib_venv
14+
PYTHON=$(VENV)/bin/python3
15+
FLAKE=$(VENV)/bin/flake8
1316

1417
# you should have xcb-proto installed to run this
1518
xcffib: module/*.py xcffib.cabal $(shell find . -path ./test -prune -false -o -name \*.hs)
@@ -36,7 +39,7 @@ gen: dist-newstyle
3639
.PHONY: clean
3740
clean:
3841
-$(CABAL) new-clean
39-
-rm -rf xcffib
42+
-rm -rf xcffib xcffib_venv
4043
-rm -rf module/*pyc module/__pycache__
4144
-rm -rf test/*pyc test/__pycache__
4245
-rm -rf build *egg* *deb .pybuild dist
@@ -51,18 +54,23 @@ newtests:
5154

5255
# These are all split out so make -j3 check goes as fast as possible.
5356
.PHONY: lint
54-
lint:
55-
flake8 --config=./test/flake8.cfg ./module
57+
lint: $(VENV)
58+
$(FLAKE) --config=./test/flake8.cfg ./module
5659

5760
.PHONY: htests
5861
htests:
5962
$(CABAL) new-test -j$(NCPUS) --enable-tests
6063

61-
check: xcffib lint htests
64+
$(VENV): requirements.txt
65+
# the python in $PATH in CI is the python from the matrix, so it is the
66+
# "right" python to start with
67+
python3 -m venv $(VENV)
68+
$(PYTHON) -m pip install -r requirements.txt
69+
70+
check: xcffib htests $(VENV) lint
6271
cabal check
63-
flake8 -j$(NCPUS) --ignore=E128,E231,E251,E301,E302,E305,E501,F401,E402,W503,E741,E999 xcffib/*.py
64-
python3 -m compileall xcffib
65-
pytest-3 -v --durations=3 -n auto
72+
$(PYTHON) -m compileall xcffib
73+
$(PYTHON) -m pytest -v --durations=3 -n $(NCPUS)
6674

6775
# make release ver=0.99.99
6876
release: xcffib

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
flake8
22
autopep8
33
cffi>=0.8.2
4+
pytest
5+
pytest-xdist
6+
cffi >= 1.6

0 commit comments

Comments
 (0)