Skip to content

Commit 5b01e22

Browse files
committed
👷 Provide requirements.txt
Problem: - Repositories that have python tests need to provide their own `requirements.txt` to drive `pip install`. Solution: - Provide a `requirements.txt` that will enable running python tests.
1 parent 1715c7a commit 5b01e22

File tree

6 files changed

+50
-13
lines changed

6 files changed

+50
-13
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ jobs:
4848
sudo apt install -y asciidoctor
4949
sudo gem install asciidoctor asciidoctor-diagram rouge
5050
51-
- name: Install cmake-format
52-
run: |
53-
pipx install cmakelang
54-
pipx inject cmakelang pyyaml
55-
56-
- name: Install python quality tools
57-
run: |
58-
pipx install pytest
59-
pipx inject pytest pytest-xdist hypothesis
60-
pipx install mypy
61-
pipx install black
62-
echo "/opt/pipx_bin" >> $GITHUB_PATH
63-
6451
- name: Checkout target branch
6552
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6653
with:
@@ -73,6 +60,21 @@ jobs:
7360
- name: Checkout PR branch
7461
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
7562

63+
- name: Install python test requirements
64+
run: |
65+
python3 -m venv ${{github.workspace}}/test_venv
66+
source ${{github.workspace}}/test_venv/bin/activate
67+
pip install -r ${{github.workspace}}/requirements.txt
68+
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH
69+
70+
- name: Install cmake-format
71+
run: |
72+
pip install cmakelang pyyaml
73+
74+
- name: Install python quality tools
75+
run: |
76+
pip install mypy black
77+
7678
- name: Restore CPM cache
7779
env:
7880
cache-name: cpm-cache-0

cmake/main.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ option(INFRA_PROVIDE_CLANG_TIDY "Provide .clang-tidy file" ON)
2626
option(INFRA_PROVIDE_CMAKE_FORMAT "Provide .cmake-format.yaml file" ON)
2727
option(INFRA_PROVIDE_PRESETS "Provide cmake presets and toolchains" ON)
2828
option(INFRA_PROVIDE_MULL "Provide mull.yml file" ON)
29+
option(INFRA_PROVIDE_PYTEST_REQS
30+
"Provide pip requirements.txt for python tests" ON)
2931
option(INFRA_PROVIDE_GITIGNORE "Add provided things to .gitignore" ON)
3032
option(INFRA_USE_SYMLINKS "Use symlinks to provide common files" ON)
3133

cmake/setup.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ function(make_gitignore)
4141
list(APPEND GITIGNORE_CONTENTS "mull.yml")
4242
endif()
4343
endif()
44+
if(INFRA_PROVIDE_PYTEST_REQS)
45+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/requirements.txt")
46+
list(APPEND GITIGNORE_CONTENTS "requirements.txt")
47+
endif()
48+
endif()
4449
endif()
4550

4651
string(REPLACE ";" "\n" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS}")
@@ -112,6 +117,9 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
112117
if(INFRA_PROVIDE_MULL)
113118
put_in_project_dir("mull.yml")
114119
endif()
120+
if(INFRA_PROVIDE_PYTEST_REQS)
121+
put_in_project_dir("requirements.txt")
122+
endif()
115123

116124
if(INFRA_PROVIDE_GITHUB_WORKFLOWS)
117125
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory

docs/options.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ level, and a `toolchains` directory.
3030

3131
When `ON`, this repository provides a `mull.yml` file at the root level.
3232

33+
*`INFRA_PROVIDE_PYTEST_REQS`*
34+
35+
When `ON`, this repository provides a `requirements.txt` file at the root level.
36+
When used with `pip install -r requirements.txt` this provides the packages
37+
sufficient to run python tests.
38+
3339
*`INFRA_PROVIDE_GITIGNORE`*
3440

3541
When `ON`, this repository provides a `.gitignore` file at the root level. It

docs/testing.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ dependencies that are not part of the CMake dependency tree. A `conftest.py`
6868
file in the same directory as any of the `FILE`​s is automatically discovered as
6969
such a dependency.
7070

71+
NOTE: Python tests use several testing packages; these can be installed using
72+
`requirements.txt` which is provided through the `INFRA_PROVIDE_PYTEST_REQS`
73+
option.
74+
7175
=== Fuzz tests
7276

7377
[source,cmake]

requirements.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# The contents of this file can be generated at latest versions available by running:
2+
#
3+
# $ python3 -m venv ./test_venv
4+
# $ source ./test_venv/bin/activate
5+
# $ pip install pytest pytest-xdist hypothesis | tail -n1 | cut -d' ' -f 3- | tr ' ' '\n' | sed 's/\(.*\)-\(.*\)/\1==\2/'
6+
#
7+
attrs==24.2.0
8+
execnet==2.1.1
9+
hypothesis==6.115.3
10+
iniconfig==2.0.0
11+
packaging==24.1
12+
pluggy==1.5.0
13+
pytest==8.3.3
14+
pytest-xdist==3.6.1
15+
sortedcontainers==2.4.0

0 commit comments

Comments
 (0)