Skip to content

Commit 924a65e

Browse files
authored
Use python venv to run tests, coverage and building diagrams locally (#1132)
This change adds these make targets: * `venv` to create a virtual environment in `.venv` to be used by make targets below * NOTE: The `dnf` module needs to be installed through the operating system but we make it available to the venv by passing `--system-site-packages`. * `test` runs tests in the virtual environment created above * `coverage` runs coverage and produces a text and HTML report in the virtual environment created above * `update-requirements` this is a helper target to update `requirements.txt` when you change something in `requirements.txt.in`. This is also done in the venv created above. Other changes: * `requirements.txt` got `pytest` as a new dependency because we use it in some tests. * `.coveragerc` was added to include configuration for which files to omit from coverage. * Without this, coverage would include `/usr` directories. * `*_test.py` files will now be excluded from the coverage because we're not interested in them. * `cffi` was bumped from `1.15.1` to `1.17.1` for it to work with Python 3.13 This should fix this error: ``` building '_cffi_backend' extension creating build/temp.linux-x86_64-cpython-313/c gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fcf-protection -fexceptions -fcf-protection -fexceptions -fcf-protection -fexceptions -O3 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/home/kkleine/src/llvm-snapshots/.venv/include -I/usr/include/python3.13 -c c/_cffi_backend.c -o build/temp.linux-x86_64-cpython-313/c/_cffi_backend.o c/_cffi_backend.c: In function ‘b_do_dlopen’: c/_cffi_backend.c:4523:22: warning: ‘Py_FileSystemDefaultEncoding’ is deprecated [-Wdeprecated-declarations] 4523 | Py_FileSystemDefaultEncoding, &filename_or_null, &flags)) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/python3.13/Python.h:99, from c/_cffi_backend.c:2: /usr/include/python3.13/fileobject.h:22:46: note: declared here 22 | Py_DEPRECATED(3.12) PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ c/_cffi_backend.c: In function ‘_my_PyErr_WriteUnraisable’: c/_cffi_backend.c:6112:9: error: implicit declaration of function ‘_PyErr_WriteUnraisableMsg’; did you mean ‘PyErr_WriteUnraisable’? [-Wimplicit-function-declaration] 6112 | _PyErr_WriteUnraisableMsg(PyText_AS_UTF8(s), NULL); | ^~~~~~~~~~~~~~~~~~~~~~~~~ | PyErr_WriteUnraisable error: command '/usr/bin/gcc' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for cffi Failed to build cffi ```
1 parent bc5238d commit 924a65e

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

.coveragerc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[run]
2+
# See https://coverage.readthedocs.io/en/latest/config.html#run-omit
3+
omit =
4+
# omit anything in a .local or .venv directory anywhere
5+
*/.local/*
6+
*/.venv/*
7+
# omit everything in /usr
8+
/usr/*
9+
# Omit any test file
10+
*_test.py
11+
12+
# See https://coverage.readthedocs.io/en/latest/config.html#run-data-file
13+
data_file=.coverage

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
buildroot/
22
*.rpm
3-
.coverage
43
.vscode
54
__pycache__/
5+
# Ignore coverage
6+
.coverage*
7+
# Don't ignore coverage configuration
8+
!.coveragerc
9+
# Ignore virtual env
10+
.venv/

Makefile

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
1+
SHELL := /bin/bash
2+
3+
temp_dir:=$(shell mktemp -d)
4+
5+
venv: .venv/touchfile
6+
7+
.venv/touchfile: requirements.txt
8+
rpm -q python3-devel
9+
python3 -m venv --system-site-packages --upgrade-deps .venv
10+
. .venv/bin/activate \
11+
&& pip install -r requirements.txt \
12+
&& pip install --upgrade pip
13+
touch .venv/touchfile
14+
15+
.PHONY: update-requirements
16+
update-requirements: venv
17+
. .venv/bin/activate \
18+
&& pip install pip-tools \
19+
&& pip install --upgrade pip \
20+
&& pip-compile -o requirements.txt requirements.txt.in
21+
122
.PHONY: build-diagrams
2-
build-diagrams:
3-
$(eval temp_dir:=$(shell mktemp -d))
23+
build-diagrams: venv
424
$(eval yyyymmdd:=$(shell date '+%Y%m%d'))
525
git show origin/gh-pages:build-stats-big-merge.csv > $(temp_dir)/build-stats-big-merge.csv
626
git show origin/gh-pages:build-stats-pgo.csv > $(temp_dir)/build-stats-pgo.csv
7-
scripts/get-build-stats.py --copr-projectname "llvm-snapshots-big-merge-$(yyyymmdd)" | tee -a $(temp_dir)/build-stats-big-merge.csv
8-
scripts/get-build-stats.py --copr-projectname "llvm-snapshots-pgo-$(yyyymmdd)" | tee -a $(temp_dir)/build-stats-pgo.csv
9-
scripts/create-diagrams.py --datafile-big-merge $(temp_dir)/build-stats-big-merge.csv --datafile-pgo $(temp_dir)/build-stats-pgo.csv
27+
. .venv/bin/activate \
28+
&& scripts/get-build-stats.py --copr-projectname "llvm-snapshots-big-merge-$(yyyymmdd)" | tee -a $(temp_dir)/build-stats-big-merge.csv \
29+
&& scripts/get-build-stats.py --copr-projectname "llvm-snapshots-pgo-$(yyyymmdd)" | tee -a $(temp_dir)/build-stats-pgo.csv \
30+
&& scripts/create-diagrams.py --datafile-big-merge $(temp_dir)/build-stats-big-merge.csv --datafile-pgo $(temp_dir)/build-stats-pgo.csv
1031
xdg-open index.html
1132

12-
.PHONY: test-snapshot-manager
13-
test-snapshot-manager: ci-coverage
33+
.PHONY: test
34+
test: venv
35+
. .venv/bin/activate && pytest
36+
37+
.PHONY: coverage
38+
coverage: venv
39+
. .venv/bin/activate \
40+
&& coverage erase \
41+
&& coverage run -m pytest \
42+
&& coverage report --show-missing \
43+
&& coverage html
1444

1545
# CI recipes
1646

@@ -19,7 +49,7 @@ ci-coverage:
1949
# Ensure previous data won't interfere with the new execution.
2050
coverage erase
2151
coverage run -m pytest
22-
coverage report -m
52+
coverage report --show-missing
2353

2454
.PHONY: ci-test
2555
ci-test:

requirements.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.11
2+
# This file is autogenerated by pip-compile with Python 3.13
33
# by the following command:
44
#
55
# pip-compile --output-file=requirements.txt requirements.txt.in
66
#
77
certifi==2024.7.4
88
# via requests
9-
cffi==1.15.1
9+
cffi==1.17.1
1010
# via
1111
# cryptography
1212
# pynacl
@@ -50,6 +50,8 @@ humanize==4.9.0
5050
# via copr-cli
5151
idna==3.7
5252
# via requests
53+
iniconfig==2.0.0
54+
# via pytest
5355
jinja2==3.1.5
5456
# via copr-cli
5557
koji==1.35.2
@@ -65,11 +67,15 @@ narwhals==1.24.1
6567
numpy==1.26.3
6668
# via pandas
6769
packaging==23.2
68-
# via plotly
70+
# via
71+
# plotly
72+
# pytest
6973
pandas==2.2.3
7074
# via -r requirements.txt.in
7175
plotly==6.0.0
7276
# via -r requirements.txt.in
77+
pluggy==1.5.0
78+
# via pytest
7379
pycparser==2.21
7480
# via cffi
7581
pygithub==2.6.1
@@ -80,6 +86,8 @@ pyjwt[crypto]==2.6.0
8086
# via pygithub
8187
pynacl==1.5.0
8288
# via pygithub
89+
pytest==8.3.4
90+
# via -r requirements.txt.in
8391
python-dateutil==2.8.2
8492
# via
8593
# koji

requirements.txt.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ requests==2.32.3
1515
fnc
1616
coverage==7.6.12
1717
koji
18+
pytest==8.3.4

0 commit comments

Comments
 (0)