From c7eed9d36ced38c4f30104ee778bd85d9ec6da70 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 20 Dec 2022 10:17:39 -0600 Subject: [PATCH 1/5] re-work test runner so it can be called outside CI --- .github/workflows/build.yml | 23 ++--------------------- build-test-cp.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) create mode 100755 build-test-cp.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5ec1568..6de80fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,27 +52,8 @@ jobs: - name: Pre-commit hooks run: | pre-commit run --all-files - - name: Clone and build circuitpython unix port - run: | - set -e - [ -e circuitpython/py/py.mk ] || (git clone --depth=1 https://github.com/adafruit/circuitpython && cd circuitpython && git fetch --tags --recurse-submodules=no --shallow-since="2021-07-01" https://github.com/adafruit/circuitpython HEAD) - [ -e circuitpython/lib/libffi/autogen.sh ] || (cd circuitpython && git submodule update --init lib/libffi lib/axtls lib/berkeley-db-1.xx tools/huffman lib/uzlib extmod/ulab) - [ -x circuitpython/ports/unix/micropython ] || ( - make -C circuitpython/mpy-cross -j$(nproc) - make -C circuitpython/ports/unix -j$(nproc) deplibs - make -C circuitpython/ports/unix -j$(nproc) DEBUG=1 STRIP=: - ) - - name: Unit Test - run: | - python -m jepler_udecimal.test - if ! env MICROPYPATH=. PYTHONPATH=. MICROPY_MICROPYTHON=circuitpython/ports/unix/micropython circuitpython/tests/run-tests.py -d examples; then - for exp in *.exp; do - testbase=$(basename $exp .exp); - echo -e "\nFAILURE $testbase"; - diff -u $testbase.exp $testbase.out; - done - exit 1 - fi + - name: Test in circuitpython + run: ./build-test-cp.sh - name: Build assets run: circuitpython-build-bundles --package_folder_prefix jepler --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Build docs diff --git a/build-test-cp.sh b/build-test-cp.sh new file mode 100755 index 0000000..3a5fbba --- /dev/null +++ b/build-test-cp.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2022 Jeff Epler +# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: Unlicense + +set -e +TAG=8.0.0-beta.4 +if ! [ -e circuitpython/py/py.mk ]; then + git clone -b $TAG --depth=1 https://github.com/adafruit/circuitpython +fi + +(cd circuitpython && git submodule update --init lib/libffi lib/axtls lib/berkeley-db-1.xx tools/huffman extmod/ulab) + +if ! [ -x circuitpython/ports/unix/micropython ]; then + make -C circuitpython/ports/unix -j$(nproc) DEBUG=1 STRIP=: +fi + +if ! MICROPYPATH=. PYTHONPATH=. MICROPY_MICROPYTHON=circuitpython/ports/unix/micropython circuitpython/tests/run-tests.py -d examples; then + circuitpython/tests/run-tests.py --print-failures + exit 1 +fi From 3ed20aefea540ec241130a77ca2dec97a92c2396 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 20 Dec 2022 10:17:56 -0600 Subject: [PATCH 2/5] Note some technical limitations of exceptions --- jepler_udecimal/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jepler_udecimal/__init__.py b/jepler_udecimal/__init__.py index d322e9f..642003f 100644 --- a/jepler_udecimal/__init__.py +++ b/jepler_udecimal/__init__.py @@ -269,6 +269,10 @@ class DivisionByZero(DecimalException): The result of the operation is [sign,inf], where sign is the exclusive or of the signs of the operands for divide, or is 1 for an odd power of -0, for power. + + Due to technical limitations in MicroPython, this exception does not + inherit from ZeroDivisionError, an incompatibility with standard Python's + Decimal library. """ def handle(self, context, sign, *args): @@ -425,6 +429,10 @@ class FloatOperation(DecimalException): Otherwise (the signal is trapped), only equality comparisons and explicit conversions are silent. All other mixed operations raise FloatOperation. + + Due to technical limitations in MicroPython, this exception does not + inherit from TypeError, an incompatibility with standard Python's + Decimal library. """ From dd76e0a45eda233fc4aff481e76cf97ec10975d7 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 20 Dec 2022 10:18:26 -0600 Subject: [PATCH 3/5] Catch more specific exceptions --- examples/test_udecimal.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/test_udecimal.py b/examples/test_udecimal.py index 0a1721f..ec29dae 100644 --- a/examples/test_udecimal.py +++ b/examples/test_udecimal.py @@ -50,19 +50,19 @@ print(neginf * inf) try: print(dig / 0) - except Exception as e: + except ZeroDivisionError as e: print("Division by zero") getcontext().traps[DivisionByZero] = 1 try: print(dig / 0) - except Exception as e: + except DivisionByZero as e: print("Division by zero") c = Context() - c.traps[InvalidOperation] = 0 print(+c.flags[InvalidOperation]) + c.traps[InvalidOperation] = 0 try: c.divide(Decimal(0), Decimal(0)) - except Exception as e: + except ZeroDivisionError as e: print("Division by zero") c.traps[InvalidOperation] = 1 print(+c.flags[InvalidOperation]) @@ -70,17 +70,18 @@ print(+c.flags[InvalidOperation]) try: print(c.divide(Decimal(0), Decimal(0))) - except Exception as e: - print("Division by zero") + except InvalidOperation as e: + print("InvalidOperation") print(+c.flags[InvalidOperation]) try: print(c.divide(Decimal(0), Decimal(0))) - except Exception as e: - print("Division by zero") + except InvalidOperation as e: + print("InvalidOperation") print(+c.flags[InvalidOperation]) import jepler_udecimal.utrig from jepler_udecimal import Decimal +from jepler_udecimal import InvalidOperation print(Decimal(".7").atan()) print(Decimal(".1").acos()) @@ -96,12 +97,12 @@ print(Decimal("NaN").sin()) try: print(Decimal("2").acos()) -except Exception as e: - print("exception") +except InvalidOperation as e: + print("InvalidOperation") try: print(Decimal("2").asin()) -except Exception as e: - print("exception") +except InvalidOperation as e: + print("InvalidOperation") print(Decimal("2").atan()) print(Decimal("1").asin()) print(Decimal("-1").asin()) From b11a0c814e8bd1bab2483dc65b746e02b57cb3b0 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 20 Dec 2022 10:23:12 -0600 Subject: [PATCH 4/5] unconditionally build python package --- .github/workflows/build.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6de80fc..5d31304 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,12 +64,7 @@ jobs: with: name: bundles path: ${{ github.workspace }}/bundles/ - - name: Check For setup.py - id: need-pypi - run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') run: | pip install --upgrade setuptools wheel twine readme_renderer testresources python setup.py sdist From 08e16ac68d455fcd42e5aecd7221ffc44e8bec2a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 20 Dec 2022 10:26:02 -0600 Subject: [PATCH 5/5] get rid of set-output --- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d31304..0100be9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,11 +17,11 @@ jobs: - name: Translate Repo Name For Build Tools filename_prefix id: repo-name run: | - echo ::set-output name=repo-name::$( + echo repo-name=$( echo ${{ github.repository }} | awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) + tr '_' '-'h + )>> $GITHUB_OUTPUTS - name: Set up Python 3.x uses: actions/setup-python@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dab7c88..227fd5e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,11 +19,11 @@ jobs: - name: Translate Repo Name For Build Tools filename_prefix id: repo-name run: | - echo ::set-output name=repo-name::$( + echo repo-name=$( echo ${{ github.repository }} | awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) + tr '_' '-'h + )>> $GITHUB_OUTPUTS - name: Set up Python 3.7 uses: actions/setup-python@v1 with: