diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa8c5d3..84dca89 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,89 +8,9 @@ on: [pull_request, push] jobs: test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - name: View context attributes - uses: actions/github-script@v6 + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main with: - script: console.log(JSON.stringify(context, null, 2)) - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v1 - with: - python-version: 3.x - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit sphinx-autoapi - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - 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 - [ -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: Build assets - run: circuitpython-build-bundles --package_folder_prefix jepler --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Archive bundles - uses: actions/upload-artifact@v2 - 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 - python setup.py bdist_wheel --universal - twine check dist/* + package-prefix: jepler_udecimal diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index dab7c88..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,85 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-20.04 - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --package_folder_prefix jepler --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v1 - - name: Check For setup.py - id: need-pypi - run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.pypi_token }} - run: | - python setup.py sdist - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..26d9703 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: GitHub Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} + package-prefix: jepler_udecimal diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..97b80f8 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: PyPI Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: __token__ + pypi-password: ${{ secrets.pypi_token }} diff --git a/.gitignore b/.gitignore index b6dc5d2..cb1ae01 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ docs/api circuitpython /*.exp /*.out +*/__version__.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7629f6b..a99a1f2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,28 +4,28 @@ repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 25.1.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v1.0.0 + rev: v5.1.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v6.0.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.14.1 + rev: v3.3.8 hooks: - id: pylint name: lint (examples) types: [python] files: ^examples/ args: - - --disable=missing-docstring,invalid-name,bad-whitespace + - --disable=missing-docstring,invalid-name - id: pylint name: lint (code) types: [python] diff --git a/.pylintrc b/.pylintrc index a4ddafa..203e349 100644 --- a/.pylintrc +++ b/.pylintrc @@ -391,10 +391,3 @@ max-statements=50 # Minimum number of public methods for a class (see R0903). min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=Exception diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..2b59355 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +build: + os: ubuntu-20.04 + tools: + python: "3" + +sphinx: + configuration: docs/conf.py + +python: + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 338427a..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt diff --git a/README.rst b/README.rst index 9bd113f..288b456 100644 --- a/README.rst +++ b/README.rst @@ -23,9 +23,15 @@ Introduction Reduced version of the decimal library for CircuitPython +Important Note +============== +From version 1.0.9 through 1.0.12, this package was incorrectly published on pypi under the name +`circuitpython-jepler-udecimal `_. +The correct package name is +`jepler-circuitpython-udecimal `_. Dependencies -============= +============ This library depends on: * `Adafruit CircuitPython `_ diff --git a/build.sh b/build.sh index 9d4dc37..00dc322 100755 --- a/build.sh +++ b/build.sh @@ -1,57 +1,80 @@ #!/bin/bash set -eo pipefail +in_section=false +if [ "${CI}" -eq "true" ]; then + start_section () { + if $in_section; then end_section; fi + echo "::group::$*" + export in_section=true + } + end_section () { + echo "::endgroup::$*" + in_section=false + } +else + start_section () { + if $in_section; then end_section; fi + echo "=== $*" + export in_section=true + } + end_section () { + echo + in_section=false + } +fi + repo_name=`git config remote.origin.url | sed -e 's,^.*/,,;s/\.git$//' | tr A-Z_ a-z-` -echo "=== Building package: $repo_name" +echo "*** Building package: $repo_name" -echo "=== Create and set up virtual environment" +start_section "Create and set up virtual environment" [ -d .venv ] || python3 -m venv .env . .env/bin/activate -echo "=== Install requirements" +start_section "Install requirements" pip3 install wheel -pip3 install -r requirements.txt -echo "=== Run pre-commit" +pip3 install -r optional_requirements.txt +start_section "Run pre-commit" pre-commit run --all-files -echo "=== Run pylint" -pylint jepler_udecimal -if [ -d examples ]; then - pylint --disable=missing-docstring,invalid-name,bad-whitespace examples -fi -echo "=== Clone and build circuitpython unix port" -[ -e circuitpython/py/py.mk ] || git clone --depth=1 https://github.com/adafruit/circuitpython +start_section "Clone and build circuitpython unix port" +[ -e circuitpython/py/py.mk ] || git clone --shallow-since=2021-07-01 https://github.com/adafruit/circuitpython [ -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) deplibs submodules make -C circuitpython/ports/unix -j$(nproc) DEBUG=1 STRIP=: ) -echo "=== Run tests" +start_section "Run tests" python -m jepler_udecimal.test -if ! env MICROPYPATH=. PYTHONPATH=. MICROPY_MICROPYTHON=circuitpython/ports/unix/micropython circuitpython/tests/run-tests -d examples; then - for exp in *.exp; do - testbase=$(basename $exp .exp); - echo -e "\nFAILURE $testbase"; - diff -u $testbase.exp $testbase.out; - done +run_tests () { + env MICROPYPATH="`readlink -f .`" PYTHONPATH="`readlink -f .`" MICROPY_MICROPYTHON=circuitpython/ports/unix/build-standard/micropython circuitpython/tests/run-tests.py --keep-path "$@" +} + +run_tests --clean-failures +if ! run_tests -d examples; then + run_tests --print-failures + exit 1 fi PYTHONPATH=. python examples/test_udecimal.py > test_udecimal.exp -echo "=== Build CircuitPython bundle" +start_section "Build CircuitPython bundle" circuitpython-build-bundles --package_folder_prefix jepler --filename_prefix $repo_name --library_location . -echo "=== Build docs" +start_section "Build docs" rm -rf docs/_build (cd docs && sphinx-build -E -W -b html . _build/html) -echo "=== Build pypi files" -python setup.py sdist -python setup.py bdist_wheel --universal +start_section "Build pypi files" +python -m build -echo "=== Check pypi files" +start_section "Check pypi files" twine check dist/* +end_section + +echo "=== Success" + # SPDX-FileCopyrightText: Copyright (c) 2020 jepler for Unpythonic Networks # # SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index c77900d..b7c4b6f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,6 +19,7 @@ "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.todo", + "sphinx_rtd_theme", ] autoapi_keep_files = True @@ -107,19 +108,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get("READTHEDOCS", None) == "True" - -if not on_rtd: # only import and set the theme if we're building docs locally - try: - import sphinx_rtd_theme - - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/docs/requirements.txt b/docs/requirements.txt index 8912f83..b187142 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,3 +4,4 @@ sphinx>=4.0.0 sphinx-autoapi +sphinx-rtd-theme diff --git a/examples/udecimal_moneyfmt.py b/examples/udecimal_moneyfmt.py index d4eb10f..7ce8559 100644 --- a/examples/udecimal_moneyfmt.py +++ b/examples/udecimal_moneyfmt.py @@ -8,7 +8,9 @@ from jepler_udecimal import Decimal -def moneyfmt(value, places=2, curr="", sep=",", dp=".", pos="", neg="-", trailneg=""): +def moneyfmt( + value, *, places=2, curr="", sep=",", dp=".", pos="", neg="-", trailneg="" +): """Convert Decimal to a money formatted string. places: required number of places after the decimal point diff --git a/jepler_udecimal/__init__.py b/jepler_udecimal/__init__.py index d322e9f..84e5bcf 100644 --- a/jepler_udecimal/__init__.py +++ b/jepler_udecimal/__init__.py @@ -1798,16 +1798,16 @@ def _round_05up(self, prec): else: return -self._round_down(prec) - _pick_rounding_function = dict( - ROUND_DOWN=_round_down, - ROUND_UP=_round_up, - ROUND_HALF_UP=_round_half_up, - ROUND_HALF_DOWN=_round_half_down, - ROUND_HALF_EVEN=_round_half_even, - ROUND_CEILING=_round_ceiling, - ROUND_FLOOR=_round_floor, - ROUND_05UP=_round_05up, - ) + _pick_rounding_function = { + ROUND_DOWN: _round_down, + ROUND_UP: _round_up, + ROUND_HALF_UP: _round_half_up, + ROUND_HALF_DOWN: _round_half_down, + ROUND_HALF_EVEN: _round_half_even, + ROUND_CEILING: _round_ceiling, + ROUND_FLOOR: _round_floor, + ROUND_05UP: _round_05up, + } def __round__(self, n=None): """Round self to the nearest integer, or to a given precision. @@ -3357,7 +3357,7 @@ class Context(object): :param bool clamp: If true, change exponents if too high """ - def __init__( + def __init__( # pylint: disable=too-many-positional-arguments self, prec=None, rounding=None, diff --git a/requirements_dev.txt b/optional_requirements.txt similarity index 96% rename from requirements_dev.txt rename to optional_requirements.txt index 82911ac..6000f3f 100644 --- a/requirements_dev.txt +++ b/optional_requirements.txt @@ -2,9 +2,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2020 jepler for Unpythonic Networks # # SPDX-License-Identifier: MIT +build pre-commit recommonmark==0.6.0 -sphinx<4 +sphinx sphinx-autoapi sphinxcontrib-svg2pdfconverter==0.1.0 sphinx-rtd-theme diff --git a/pyproject.toml b/pyproject.toml index f3c35ae..674646d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,5 +2,45 @@ # # SPDX-License-Identifier: Unlicense -[tool.black] -target-version = ['py35'] +[build-system] +requires = [ + "setuptools", + "wheel", + "setuptools_scm[toml]>=6.0", +] + +[project] +name = "jepler-circuitpython-udecimal" +description = "Reduced version of the decimal library for CircuitPython" +readme = "README.rst" +authors = [ + {name = "Jeff Epler", email = "jepler@unpythonic.net"} +] +urls = { Source = "https://github.com/jepler/Jepler_CircuitPython_udecimal", Documentation = "https://jepler-udecimal.readthedocs.io/en/latest/api/jepler_udecimal/index.html", Tracker = "https://github.com/jepler/Jepler_CircuitPython_udecimal/issues" } +# "Pull Requests" = "https://github.com/jepler/Jepler_CircuitPython_udecimal/pulls", +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "udecimal", + "numeric", + "helper", + "arbitraryprecision", + "math", +] +license = "MIT" +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "Programming Language :: Python :: 3", +] +dynamic = ["version", "dependencies", "optional-dependencies"] + + +[tool.setuptools] +packages=['jepler_udecimal'] +[tool.setuptools_scm] +write_to = "jepler_udecimal/__version__.py" diff --git a/setup.py b/setup.py deleted file mode 100644 index a8fbd90..0000000 --- a/setup.py +++ /dev/null @@ -1,65 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# SPDX-FileCopyrightText: Copyright (c) 2020 jepler for Unpythonic Networks -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - name="jepler-circuitpython-udecimal", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="Reduced version of the decimal library for CircuitPython", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/jepler/Jepler_CircuitPython_udecimal", - project_urls={ - "Source": "https://github.com/jepler/Jepler_CircuitPython_udecimal", - "Documentation": "https://jepler-udecimal.readthedocs.io/en/latest/api/jepler_udecimal/index.html", - "Tracker": "https://github.com/jepler/Jepler_CircuitPython_udecimal/issues", - "Pull Requests": "https://github.com/jepler/Jepler_CircuitPython_udecimal/pulls", - }, - # Author details - author="Jeff Epler", - author_email="jepler@gmail.com", - install_requires=[], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "License :: OSI Approved :: MIT License", - "License :: OSI Approved :: Python Software Foundation License ", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - ], - # What does your project relate to? - keywords="adafruit blinka circuitpython micropython udecimal numeric helper " - "arbitraryprecision math", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - packages=["jepler_udecimal"], -)