Skip to content

Commit cf0bea7

Browse files
committed
ci: test dev against TA-Lib C's dev branch
The dev line requires a TA-Lib C that has no release yet, so a PR into dev could not build -- and in fact ran nothing at all, since tests.yml triggers on master only. This adds tests-dev.yml, which triggers on dev, builds the C library from source at the tip of its dev branch and caches it by commit, then runs the same steps tests.yml does. tests.yml is untouched: master keeps installing the published release. It resolves the commit with git ls-remote rather than api.github.com, which is rate limited per runner IP and answers 403 often enough to redden a job for a reason unrelated to the code under test. TA-Lib C has since retired the Metastock compatibility behaviour and made the setter inert, so test_compatibility pins only the default; asserting what the setter used to change would pass on one C release and fail on the next.
1 parent d7fc4d0 commit cf0bea7

2 files changed

Lines changed: 84 additions & 4 deletions

File tree

‎.github/workflows/tests-dev.yml‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Tests (dev)
2+
3+
# The dev branch tracks TA-Lib C's dev branch, which has no release yet, so this
4+
# builds the C library from source and the two dev lines move together. master
5+
# is tests.yml, which installs the published release; the steps after the C
6+
# build are that file's, and are meant to stay in step with it.
7+
8+
on:
9+
push:
10+
branches: [ dev ]
11+
pull_request:
12+
branches: [ dev ]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
20+
env:
21+
TA_INCLUDE_PATH: ${{ github.workspace }}/ta-lib-c/include
22+
TA_LIBRARY_PATH: ${{ github.workspace }}/ta-lib-c/lib
23+
LD_LIBRARY_PATH: ${{ github.workspace }}/ta-lib-c/lib
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
# git, not api.github.com: the API is rate limited per runner IP and its 403
28+
# would redden a job for a reason unrelated to the code under test.
29+
- name: Resolve TA-Lib C dev
30+
id: talib_c
31+
run: |
32+
set -euo pipefail
33+
SHA=$(git ls-remote https://github.com/TA-Lib/ta-lib.git refs/heads/dev | cut -f1)
34+
[ -n "$SHA" ] || { echo "::error::cannot resolve ta-lib dev"; exit 1; }
35+
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
36+
37+
- name: Cache TA-Lib C
38+
id: talib_c_cache
39+
uses: actions/cache@v4
40+
with:
41+
path: ta-lib-c
42+
key: ta-lib-c-${{ runner.os }}-${{ steps.talib_c.outputs.sha }}
43+
44+
- name: Build TA-Lib C
45+
if: steps.talib_c_cache.outputs.cache-hit != 'true'
46+
run: |
47+
set -euo pipefail
48+
# the exact commit the cache key names, so a cache hit and a build agree
49+
git init -q ta-lib-c-src
50+
git -C ta-lib-c-src remote add origin https://github.com/TA-Lib/ta-lib.git
51+
git -C ta-lib-c-src fetch -q --depth 1 origin ${{ steps.talib_c.outputs.sha }}
52+
git -C ta-lib-c-src checkout -q FETCH_HEAD
53+
cmake -S ta-lib-c-src -B ta-lib-c-build -DCMAKE_BUILD_TYPE=Release \
54+
-DBUILD_DEV_TOOLS=OFF -DCMAKE_INSTALL_PREFIX="$PWD/ta-lib-c"
55+
cmake --build ta-lib-c-build -j"$(nproc)"
56+
cmake --install ta-lib-c-build
57+
58+
- name: Set up Python ${{ matrix.python-version }}
59+
uses: actions/setup-python@v4
60+
with:
61+
python-version: ${{ matrix.python-version }}
62+
allow-prereleases: true
63+
64+
- name: Install dependencies
65+
run: |
66+
pip install --upgrade pip wheel setuptools
67+
pip install -r requirements_test.txt
68+
pip install flake8
69+
70+
- name: Build cython modules in-place
71+
run: |
72+
python setup.py build_ext --inplace
73+
74+
- name: Lint with flake8
75+
run: |
76+
# stop the build if there are Python syntax errors or undefined names
77+
flake8 talib --count --select=E9,F63,F7,F82 --show-source --statistics
78+
79+
- name: Test with pytest
80+
run: |
81+
PYTHONPATH=. pytest

‎tests/test_func.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,13 @@ def test_unstable_period_retired_is_a_warning_and_a_noop(name):
173173

174174

175175
def test_compatibility():
176+
# Only the default is pinned: TA-Lib C retired the Metastock behaviour and
177+
# made the setter inert, so asserting what it used to change would pass on
178+
# one C release and fail on the next.
176179
a = np.arange(10, dtype=float)
177180
talib.set_compatibility(0)
178181
r = func.EMA(a, 3)
179182
assert_array_equal(r, [np.nan, np.nan, 1, 2, 3, 4, 5, 6, 7, 8])
180-
talib.set_compatibility(1)
181-
r = func.EMA(a, 3)
182-
assert_array_equal(r, [np.nan, np.nan,1.25,2.125,3.0625,4.03125,5.015625,6.0078125,7.00390625,8.001953125])
183-
talib.set_compatibility(0)
184183

185184

186185
def test_MIN(series):

0 commit comments

Comments
 (0)