Skip to content

Commit 0ffad69

Browse files
authored
CI fix for python3 only PR (#108)
* sympy issue on github action -- try 1 * Fix macOS dependency installation in GitHub Actions - Make brew update non-fatal - Add fallback logic for pip installation (try pip3, python3 -m pip, or ensurepip first) - This fixes the 'Install Dependencies' step failure on macOS runners * Fix PEP 668 externally-managed-environment error on macOS Add --user flag to all pip install commands on macOS to comply with PEP 668 restrictions in Python 3.12+. This installs sympy to the user directory instead of system-wide, which is allowed and safe. * Make sympy installation non-fatal on macOS and use --break-system-packages - Add --break-system-packages flag along with --user to comply with PEP 668 - Make sympy installation non-fatal using set +e/set -e - Since sympy is optional (tests work without it), continue even if installation fails - This fixes the externally-managed-environment error on macOS CI runners * Ensure sympy is successfully installed on macOS CI - Simplify installation approach: use --break-system-packages flag - Ensure pip is available and up to date before installing sympy - Remove error handling that made installation optional - This ensures sympy is actually installed for tests to use * Make sympy import optional in polypy_test.py - Wrap sympy import in try/except to handle missing sympy gracefully - Add _sympy_available flag to track sympy availability - Automatically disable sympy checking when sympy is not available - Add guards in SympyWrapper methods to handle missing sympy - This allows tests to run even when sympy is not installed
1 parent fa3d614 commit 0ffad69

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

.github/actions/install-dependencies/action.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@ runs:
1212
sudo apt-get install -y cmake
1313
sudo apt-get install -y libgmp-dev
1414
sudo apt-get install -y python3-pip
15-
pip3 install sympy
15+
python3 -m pip install sympy
1616
echo "Install Linux dependencies [DONE]"
1717
1818
- name: Install Mac Dependencies
1919
if: runner.os == 'macOS'
2020
shell: bash
2121
run: |
2222
echo "Install Mac dependencies"
23-
brew update
23+
brew update || true
2424
## gmp and python are already installed in the latest macOS
2525
# brew install gmp
2626
# brew install python
27-
pip install sympy
27+
## Install sympy - use --break-system-packages for CI environment
28+
## First ensure pip is available and up to date
29+
python3 -m ensurepip --upgrade || python3 -m ensurepip || true
30+
python3 -m pip install --upgrade pip || true
31+
## Install sympy with --break-system-packages flag (required for PEP 668)
32+
python3 -m pip install --break-system-packages sympy
2833
echo "Install Mac dependencies [DONE]"

test/python/polypy_test.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import polypy
22
import random
3-
import sympy
3+
4+
try:
5+
import sympy
6+
_sympy_available = True
7+
except ImportError:
8+
_sympy_available = False
9+
sympy = None
410

511
PASS = 0
612
FAIL = 0
@@ -61,7 +67,13 @@ class SympyWrapper:
6167

6268
enabled = True
6369

70+
def __init__(self):
71+
if not _sympy_available:
72+
self.enabled = False
73+
6474
def sympy_from_upolynomial(self, p):
75+
if not _sympy_available:
76+
raise RuntimeError("sympy is not available")
6577
coeffs = p.coefficients()
6678
sympy_p = 0
6779
x = sympy.symbols('x')
@@ -71,13 +83,17 @@ def sympy_from_upolynomial(self, p):
7183
return sympy_p
7284

7385
def sympy_factor(self, p):
86+
if not _sympy_available:
87+
raise RuntimeError("sympy is not available")
7488
sympy_p = self.sympy_from_upolynomial(p)
7589
if (p.ring().modulus() is None):
7690
return sympy.factor_list(sympy_p)
7791
else:
7892
return sympy.factor_list(sympy_p, modulus=p.ring().modulus())
7993

8094
def sympy_gcd(self, p, q):
95+
if not _sympy_available:
96+
raise RuntimeError("sympy is not available")
8197
sympy_p = self.sympy_from_upolynomial(p)
8298
sympy_q = self.sympy_from_upolynomial(q)
8399
if (p.ring().modulus() is None):
@@ -86,6 +102,8 @@ def sympy_gcd(self, p, q):
86102
return sympy.gcd(sympy_p, sympy_q, modulus=p.ring().modulus())
87103

88104
def sympy_extended_gcd(self, p, q):
105+
if not _sympy_available:
106+
raise RuntimeError("sympy is not available")
89107
sympy_p = self.sympy_from_upolynomial(p)
90108
sympy_q = self.sympy_from_upolynomial(q)
91109
if (p.ring().modulus() is None):
@@ -143,9 +161,11 @@ def check_extended_gcd(self, p, q, gcd, u, v):
143161

144162

145163
"""
146-
By default sympy is enabled.
164+
By default sympy is enabled if available.
147165
"""
148166
sympy_checker = SympyWrapper();
167+
if not _sympy_available:
168+
sympy_checker.enabled = False
149169

150170
"""
151171
Initialize the testing.

0 commit comments

Comments
 (0)