-
Notifications
You must be signed in to change notification settings - Fork 12
174 lines (155 loc) · 5.89 KB
/
python.yaml
File metadata and controls
174 lines (155 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Python Wheels
on:
push:
tags: ['v*']
workflow_dispatch:
jobs:
build_wheels:
name: Build wheels (${{ matrix.os }}, Python ${{ matrix.python }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64
- os: ubuntu-latest
python: '3.14'
target: linux-x86_64
- os: ubuntu-latest
python: '3.13'
target: linux-x86_64
- os: ubuntu-latest
python: '3.12'
target: linux-x86_64
- os: ubuntu-latest
python: '3.11'
target: linux-x86_64
- os: ubuntu-latest
python: '3.10'
target: linux-x86_64
# macOS ARM64
- os: macos-latest
python: '3.14'
target: macos-arm64
- os: macos-latest
python: '3.13'
target: macos-arm64
- os: macos-latest
python: '3.12'
target: macos-arm64
- os: macos-latest
python: '3.11'
target: macos-arm64
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Set up Zig
uses: mlugg/setup-zig@v2
with:
version: master
- name: Set version from tag
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION="0.0.0.dev"
fi
sed -i.bak "s/version = \".*\"/version = \"$VERSION\"/" bindings/python/pyproject.toml
sed -i.bak "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" bindings/python/astroz/__init__.py
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build Python bindings
run: |
PYTHON_INCLUDE=$(python -c "import sysconfig; print(sysconfig.get_path('include'))")
PYTHON_LIBDIR=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
PYTHON_LIB=$(python -c "import sys; print(f'python{sys.version_info.major}.{sys.version_info.minor}')")
echo "Python include: $PYTHON_INCLUDE"
echo "Python libdir: $PYTHON_LIBDIR"
echo "Python lib: $PYTHON_LIB"
# On macOS, don't link against Python library - symbols resolve at load time
if [[ "$RUNNER_OS" == "macOS" ]]; then
zig build python-bindings \
-Dpython-include="$PYTHON_INCLUDE" \
-Doptimize=ReleaseFast
else
zig build python-bindings \
-Dpython-include="$PYTHON_INCLUDE" \
-Dpython-lib="$PYTHON_LIB" \
-Dpython-lib-path="$PYTHON_LIBDIR" \
-Doptimize=ReleaseFast
fi
- name: Copy built library
run: |
ls -la zig-out/bindings/python/astroz/
# Zig builds lib_astroz.so (Linux) or lib_astroz.dylib (macOS)
if [ -f zig-out/bindings/python/astroz/lib_astroz.so ]; then
cp zig-out/bindings/python/astroz/lib_astroz.so bindings/python/astroz/_astroz.so
elif [ -f zig-out/bindings/python/astroz/lib_astroz.dylib ]; then
cp zig-out/bindings/python/astroz/lib_astroz.dylib bindings/python/astroz/_astroz.so
else
echo "ERROR: Could not find built library"
exit 1
fi
- name: Install build tools
run: pip install build wheel
- name: Build wheel
run: |
cd bindings/python
python -m build --wheel
- name: Repair wheel (Linux)
if: runner.os == 'Linux'
run: |
pip install auditwheel patchelf
auditwheel repair bindings/python/dist/*.whl -w bindings/python/dist/repaired/ || true
if [ -d "bindings/python/dist/repaired" ] && [ "$(ls -A bindings/python/dist/repaired/)" ]; then
rm bindings/python/dist/*.whl
mv bindings/python/dist/repaired/*.whl bindings/python/dist/
fi
- name: Test wheel
run: |
pip install bindings/python/dist/*.whl
python -c "from astroz import Tle, Constellation, propagate, __version__; print(f'astroz {__version__}')"
python -c "
from astroz import Tle, propagate
tle_text = '1 25544U 98067A 24127.82853009 .00015698 00000+0 27310-3 0 9995\n2 25544 51.6393 160.4574 0003580 140.6673 205.7250 15.50957674452123'
tle = Tle(tle_text)
pos = propagate(tle_text, [30.0])
print(f'Position: {pos[0, 0]}')
"
python -c "
from astroz.api import Satrec, SatrecArray, jday, WGS72
import numpy as np
line1 = '1 25544U 98067A 24127.82853009 .00015698 00000+0 27310-3 0 9995'
line2 = '2 25544 51.6393 160.4574 0003580 140.6673 205.7250 15.50957674452123'
sat = Satrec.twoline2rv(line1, line2, WGS72)
jd, fr = jday(2024, 5, 6, 12, 0, 0.0)
e, r, v = sat.sgp4(jd, fr)
print(f'astroz.api: pos=({r[0]:.1f}, {r[1]:.1f}, {r[2]:.1f})')
arr = SatrecArray([sat])
e, r, v = arr.sgp4(np.array([jd]), np.array([fr]))
print(f'SatrecArray: shape={r.shape}')
"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.target }}-py${{ matrix.python }}
path: bindings/python/dist/*.whl
publish:
name: Publish to PyPI
needs: [build_wheels]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: wheel-*
path: dist
merge-multiple: true
- name: List dist contents
run: ls -la dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1