diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml index de339c9..8813d22 100644 --- a/.github/actions/install-dependencies/action.yml +++ b/.github/actions/install-dependencies/action.yml @@ -12,7 +12,7 @@ runs: sudo apt-get install -y cmake sudo apt-get install -y libgmp-dev sudo apt-get install -y python3-pip - pip3 install sympy + python3 -m pip install sympy echo "Install Linux dependencies [DONE]" - name: Install Mac Dependencies @@ -20,9 +20,14 @@ runs: shell: bash run: | echo "Install Mac dependencies" - brew update + brew update || true ## gmp and python are already installed in the latest macOS # brew install gmp # brew install python - pip install sympy + ## Install sympy - use --break-system-packages for CI environment + ## First ensure pip is available and up to date + python3 -m ensurepip --upgrade || python3 -m ensurepip || true + python3 -m pip install --upgrade pip || true + ## Install sympy with --break-system-packages flag (required for PEP 668) + python3 -m pip install --break-system-packages sympy echo "Install Mac dependencies [DONE]" diff --git a/test/python/polypy_test.py b/test/python/polypy_test.py index 486b24c..5a04162 100644 --- a/test/python/polypy_test.py +++ b/test/python/polypy_test.py @@ -1,6 +1,12 @@ import polypy import random -import sympy + +try: + import sympy + _sympy_available = True +except ImportError: + _sympy_available = False + sympy = None PASS = 0 FAIL = 0 @@ -61,7 +67,13 @@ class SympyWrapper: enabled = True + def __init__(self): + if not _sympy_available: + self.enabled = False + def sympy_from_upolynomial(self, p): + if not _sympy_available: + raise RuntimeError("sympy is not available") coeffs = p.coefficients() sympy_p = 0 x = sympy.symbols('x') @@ -71,6 +83,8 @@ def sympy_from_upolynomial(self, p): return sympy_p def sympy_factor(self, p): + if not _sympy_available: + raise RuntimeError("sympy is not available") sympy_p = self.sympy_from_upolynomial(p) if (p.ring().modulus() is None): return sympy.factor_list(sympy_p) @@ -78,6 +92,8 @@ def sympy_factor(self, p): return sympy.factor_list(sympy_p, modulus=p.ring().modulus()) def sympy_gcd(self, p, q): + if not _sympy_available: + raise RuntimeError("sympy is not available") sympy_p = self.sympy_from_upolynomial(p) sympy_q = self.sympy_from_upolynomial(q) if (p.ring().modulus() is None): @@ -86,6 +102,8 @@ def sympy_gcd(self, p, q): return sympy.gcd(sympy_p, sympy_q, modulus=p.ring().modulus()) def sympy_extended_gcd(self, p, q): + if not _sympy_available: + raise RuntimeError("sympy is not available") sympy_p = self.sympy_from_upolynomial(p) sympy_q = self.sympy_from_upolynomial(q) if (p.ring().modulus() is None): @@ -143,9 +161,11 @@ def check_extended_gcd(self, p, q, gcd, u, v): """ - By default sympy is enabled. + By default sympy is enabled if available. """ sympy_checker = SympyWrapper(); +if not _sympy_available: + sympy_checker.enabled = False """ Initialize the testing.