Skip to content

Commit b641a90

Browse files
guillaumegrolleronguillaume.grolleronjlenain
authored
TRR tests implementation in the core nectarchain module (#173)
* move TRR test suite into nectarchain * add h5py dependency * add lmfit to pyproject.toml * fix docstring * rebase on main * Fix Sphinx intermapping with PyQt documentation * Switch back to PyQt5 instead of PyQt6, to be able to launch the TRR GUI, on Linux at least * To try to ensure that the TRR GUI is launchable both from Linux and macOS * very simple unit test for TRR * change test_gui to work on macos * remove pyqt6 * install pyqt5 in CI for mac * sqlite issue * check pyqt installation in CI * install pyqt with brew before mamba installation on mac * add --no-deps to pip install nectarchain for pytest * add cleaner pip installation of nectarchain * clean separation of the installation through pip and mamba * tomlib -> toml for python < 3.11 * fix pip install * clean * Remove any use of PyQt6 in TRR GUI * Try to re-simplify the installation of dependencies for CI tests * Upload codecov report only for 1 platform/python version/installation method, not for all of them. --------- Co-authored-by: guillaume.grolleron <[email protected]> Co-authored-by: jlenain <[email protected]>
1 parent f2df538 commit b641a90

File tree

18 files changed

+629
-343
lines changed

18 files changed

+629
-343
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ name: CI
44
on:
55
workflow_dispatch:
66
push:
7-
# TODO
8-
# Remove comment: just a test to force CI on push
9-
# branches:
10-
# - main
11-
# tags:
12-
# - '**'
7+
branches:
8+
- main
9+
tags:
10+
- "**"
1311
pull_request:
1412

1513
env:
@@ -61,6 +59,7 @@ jobs:
6159
python-version: "3.11"
6260
ctapipe-version: "v0.19.3"
6361
install-method: "pip"
62+
extra-args: ["codecov"]
6463
# macos 14 image is arm64 based
6564
- os: "macos-14"
6665
python-version: "3.11"
@@ -70,6 +69,7 @@ jobs:
7069
env :
7170
DISPLAY: ":99.0"
7271
QT_SELECT: "qt5"
72+
7373
defaults:
7474
run:
7575
# We need login shells (-l) for micromamba to work.
@@ -82,6 +82,10 @@ jobs:
8282
sudo apt-get update
8383
sudo apt-get install freeglut3-dev
8484
85+
- name: Install dependencies for Qt on mac-OS
86+
if: matrix.os == 'macos-14'
87+
run: |
88+
brew install pyqt
8589
- uses: actions/checkout@v4
8690
with:
8791
fetch-depth: 0
@@ -92,63 +96,85 @@ jobs:
9296
run: |
9397
sed -i -e "s/- python=.*/- python=$PYTHON_VERSION/g" environment.yml
9498
99+
- name: Setup xvfb for X11 display
100+
if: matrix.os == 'ubuntu-latest'
101+
run: |
102+
# Stuff copied wildly from several stackoverflow posts
103+
sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 libxcb-shape0 libglib2.0-0 libgl1-mesa-dev
104+
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
105+
# start xvfb in the background
106+
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 &
107+
95108
- name: Mamba setup
96109
if: matrix.install-method == 'mamba'
97110
uses: mamba-org/setup-micromamba@v2
98111
with:
99112
environment-name: "ci"
100113
environment-file: environment.yml
101114

102-
103115
- name: Python setup
104116
if: matrix.install-method == 'pip'
105117
uses: actions/setup-python@v5
106118
with:
107119
python-version: ${{ matrix.python-version }}
108120
check-latest: true
109-
110-
- name: Setup xvfb for X11 display
111-
if: matrix.os == 'ubuntu-latest'
112-
run: |
113-
# Stuff copied wildly from several stackoverflow posts
114-
sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 libxcb-shape0 libglib2.0-0 libgl1-mesa-dev
115-
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
116-
# start xvfb in the background
117-
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 &
118-
119-
- name: Instal QT and setup environment on macOS
120-
if: matrix.os == 'macos-14'
121-
run: |
122-
brew install pyqt@6
123-
echo "DYLD_FRAMEWORK_PATH=$(brew --prefix qt)/lib" >> $GITHUB_ENV
124121

125122
- name: Install dependencies
126123
env:
127124
CTAPIPE_VERSION: ${{ matrix.ctapipe-version }}
128-
129125
run: |
130126
python --version
131127
echo "Installing additional pip packages"
132128
# we install ctapipe using pip to be able to select any commit, e.g. the current main
133129
pip install \
134130
"git+https://github.com/cta-observatory/ctapipe@$CTAPIPE_VERSION"
135131
136-
echo "pip install -e ."
137-
pip install -e .[test]
138-
139-
- name: Check pyqt version
132+
if [ "${{ matrix.os }}" == "macos-14" ]; then
133+
# nectarchain installation with pip
134+
if [ "${{ matrix.install-method }}" == "pip" ]; then
135+
pip install -e .
136+
else
137+
pip install --no-deps -e .
138+
fi
139+
# install with pip dependencies for pytest (NB : when we will use python > 3.10 for all configs, use tomllib instead of toml)
140+
pip install toml
141+
python -c "import toml, sys; print('\n'.join(toml.load('pyproject.toml')['project']['optional-dependencies']['test']))" | xargs pip install
142+
else
143+
echo "pip install -e ."
144+
pip install -e .[test]
145+
fi
146+
147+
- name: Check pyqt version and installation
140148
run: |
141-
pip list | grep PyQt
149+
if [ "${{ matrix.install-method }}" == "pip" ]; then
150+
pip list | grep PyQt
151+
else
152+
micromamba list -n ci qt
153+
pip list | grep PyQt
154+
fi
155+
156+
- name: Check mac-os installation
157+
if: matrix.os == 'macos-14'
158+
run: |
159+
micromamba list -n ci | grep qt
160+
eval "$(micromamba shell hook --shell=bash)"
161+
micromamba activate ci
162+
otool -L $(python -c "import PyQt5.QtCore; print(PyQt5.QtCore.__file__)")
142163
143164
- name: Tests
144165
run: |
145166
pytest -n auto --dist loadscope --cov=nectarchain --cov-report=xml --ignore=src/nectarchain/user_scripts
146167
147168
- name: Upload coverage reports to Codecov with GitHub Action
148169
uses: codecov/codecov-action@v5
170+
if: contains(matrix.extra-args, 'codecov')
149171
env:
150172
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
151173

174+
# - name: Start SSH Debugging Session
175+
# if: ${{ failure() }}
176+
# uses: mxschmitt/action-tmate@v3
177+
152178

153179
docs:
154180
needs: lint

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
# class signature)
5252
"numpydoc",
5353
"sphinx_design",
54+
"sphinx_qt_documentation",
5455
]
5556

5657
autosummary_generate = True # Turn on sphinx.ext.autosummary

environment.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ dependencies:
1717
- sphinx
1818
- sphinx-automodapi
1919
- pydata-sphinx-theme
20-
- pyqt # [linux]
20+
- lmfit # needed into TRR
21+
- h5py # needed into TRR (should be removed to use I/O methods of containers)
22+
- pyqt
2123
- pip:
2224
- zeo
2325
- zodb
2426
- mechanize
2527
- browser-cookie3
2628
- pyqtgraph
27-
- pyqt6 # [osx and arm64]
29+
- sphinx-qt-documentation

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ dependencies = [
2727
"scipy==1.11.4",
2828
"zodb",
2929
"zeo",
30-
"pyqt6",
30+
"lmfit",
31+
"h5py",
32+
"pyqt5",
3133
"pyqtgraph",
34+
"tomli; python_version < '3.11'",
3235
]
3336

3437
# needed for setuptools_scm, we don't define a static version
@@ -52,9 +55,9 @@ docs = [
5255
"sphinx-autodoc-typehints",
5356
"sphinx-automodapi",
5457
"sphinx-design",
58+
"sphinx-qt-documentation",
5559
"pydata_sphinx_theme",
5660
"numpydoc",
57-
"tomli; python_version < '3.11'"
5861
]
5962
# we can use self-references to simplify all
6063
all = [

src/nectarchain/makers/tests/test_core_makers.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
import pathlib
43
from unittest.mock import MagicMock, patch
54

@@ -58,22 +57,22 @@ class TestEventsLoopNectarCAMCalibrationTool(TestBaseNectarCAMCalibrationTool):
5857

5958
@pytest.fixture
6059
def tool_instance(self):
61-
return EventsLoopNectarCAMCalibrationTool(run_number=self.RUN_NUMBER)
60+
return EventsLoopNectarCAMCalibrationTool(
61+
run_number=self.RUN_NUMBER,
62+
output_path=pathlib.Path("/tmp/test_output.h5"),
63+
)
6264

6365
@pytest.fixture
6466
def tool_instance_run_file(self):
6567
return EventsLoopNectarCAMCalibrationTool(
6668
run_number=self.RUN_NUMBER,
6769
run_file=self.RUN_FILE,
68-
output_path=pathlib.Path(f"/tmp/{np.random.random()}test_output.h5")
70+
output_path=pathlib.Path(f"/tmp/{np.random.random()}test_output.h5"),
6971
# to avoid I/O conflicts between tests
7072
)
7173

7274
def test_init_output_path(self, tool_instance):
73-
expected_path = pathlib.Path(
74-
f"{os.environ.get('NECTARCAMDATA', '/tmp')}/runs"
75-
f"/EventsLoopNectarCAMCalibration_run{self.RUN_NUMBER}.h5"
76-
)
75+
expected_path = pathlib.Path("/tmp/test_output.h5")
7776
assert tool_instance.output_path == expected_path
7877
assert tool_instance.run_number == self.RUN_NUMBER
7978
assert tool_instance.max_events is None
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .gui import TestRunner
2+
3+
__all__ = [
4+
"TestRunner",
5+
]

0 commit comments

Comments
 (0)