diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f2abbd..0bbfd3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ 3.8, 3.11 ] + python-version: [ 3.11, 3.12 ] toxenv: [ py, quality ] steps: diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 17eb5fd..355716e 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -15,7 +15,7 @@ jobs: - name: setup python uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.11 - name: Install pip run: pip install -r requirements/pip.txt diff --git a/README.rst b/README.rst index 078aad0..bceb563 100644 --- a/README.rst +++ b/README.rst @@ -1,16 +1,165 @@ openedx-calc -============ +############ + +|pypi-badge| |ci-badge| |codecov-badge| |doc-badge| |pyversions-badge| +|license-badge| |status-badge| + + +Purpose +******* A helper library for mathematical calculations and symbolic mathematics, used by the `edx-platform`_. This code originally lived in the `edx-platform`_ repo, but now exists here independently. -License +Getting Started with Development +******************************** + +General ------- -The code in this repository is licensed under version 3 of the AGPL unless otherwise noted. Please see the `LICENSE`_ file for details. +Please see the Open edX documentation for `guidance on Python development`_ in this repo. + +.. _guidance on Python development: https://docs.openedx.org/en/latest/developers/how-tos/get-ready-for-python-dev.html + +Instructions +------------ + +Fork and clone the repository, then open a terminal and cd into the repo folder. + +Create a virtual environment with one of the python versions specified for the repo. +Currently those are Python 3.11 and 3.12. Example: + +.. code-block:: bash + + python3.11 -m venv ../openedx-calc-venv + source ../openedx-calc-venv/bin/activate + +Install the dependencies: + +.. code-block:: bash + + make requirements + +Then you can run the tests with just `tox`. + +When Upgrading Requirements +--------------------------- + +Run `make upgrade` to get new versions, and `tox -r` to build the new virtual environment. + + +Getting Help +************ + +Documentation +============= + +PLACEHOLDER: Start by going through `the documentation`_. If you need more help see below. + +.. _the documentation: https://docs.openedx.org/projects/{{cookiecutter.repo_name}} + +(TODO: `Set up documentation `_) + +More Help +========= + +If you're having trouble, we have discussion forums at +https://discuss.openedx.org where you can connect with others in the +community. + +Our real-time conversations are on Slack. You can request a `Slack +invitation`_, then join our `community Slack workspace`_. + +For anything non-trivial, the best path is to open an issue in this +repository with as many details about the issue you are facing as you +can provide. +https://github.com/openedx/openedx-calc/issues + +For more information about these options, see the `Getting Help `__ page. + +.. _Slack invitation: https://openedx.org/slack +.. _community Slack workspace: https://openedx.slack.com/ + +License +******* + +The code in this repository is licensed under version 3 of the AGPL unless otherwise noted. +Please see the `LICENSE`_ file for details. .. _edx-platform: https://github.com/openedx/edx-platform .. _LICENSE: https://github.com/openedx/openedx-calc/blob/master/LICENSE + + +Contributing +************ + +Contributions are very welcome. +Please read `How To Contribute `_ for details. + +This project is currently accepting all types of contributions, bug fixes, +security fixes, maintenance work, or new features. However, please make sure +to discuss your new feature idea with the maintainers before beginning development +to maximize the chances of your change being accepted. +You can start a conversation by creating a new issue on this repo summarizing +your idea. + +Because this repo is used for a wide variety of mathematical calculations, +including learner grades, it may occasionally be desirable to maintain +bug-for-bug compatibility with previous versions. Additions to the repo +are more likely to be accepted than changes that could alter the outputs +of existing functions. + + +The Open edX Code of Conduct +**************************** + +All community members are expected to follow the `Open edX Code of Conduct`_. + +.. _Open edX Code of Conduct: https://openedx.org/code-of-conduct/ + +People +****** + +The assigned maintainers for this component and other project details may be +found in `Backstage`_. Backstage pulls this data from the ``catalog-info.yaml`` +file in this repo. + +.. _Backstage: https://backstage.openedx.org/catalog/default/component/openedx-calc + +Reporting Security Issues +************************* + +Please do not report security issues in public. Please email security@openedx.org. + +.. |pypi-badge| image:: https://img.shields.io/pypi/v/openedx-calc.svg + :target: https://pypi.python.org/pypi/openedx-calc/ + :alt: PyPI + +.. |ci-badge| image:: https://github.com/openedx/openedx-calc/workflows/Python%20CI/badge.svg?branch=main + :target: https://github.com/openedx/openedx-calc/actions + :alt: CI + +.. |codecov-badge| image:: https://codecov.io/github/openedx/openedx-calc/coverage.svg?branch=main + :target: https://codecov.io/github/openedx/openedx-calc?branch=main + :alt: Codecov + +.. |doc-badge| image:: https://readthedocs.org/projects/openedx-calc/badge/?version=latest + :target: https://docs.openedx.org/projects/openedx-calc + :alt: Documentation + +.. |pyversions-badge| image:: https://img.shields.io/pypi/pyversions/openedx-calc.svg + :target: https://pypi.python.org/pypi/openedx-calc/ + :alt: Supported Python versions + +.. |license-badge| image:: https://img.shields.io/github/license/openedx/openedx-calc.svg + :target: https://github.com/openedx/openedx-calc/blob/main/LICENSE.txt + :alt: License + +.. TODO: Choose one of the statuses below and remove the other status-badge lines. +.. |status-badge| image:: https://img.shields.io/badge/Status-Experimental-yellow +.. .. |status-badge| image:: https://img.shields.io/badge/Status-Maintained-brightgreen +.. .. |status-badge| image:: https://img.shields.io/badge/Status-Deprecated-orange +.. .. |status-badge| image:: https://img.shields.io/badge/Status-Unsupported-red diff --git a/calc/__init__.py b/calc/__init__.py index 1a2dd23..d880a97 100644 --- a/calc/__init__.py +++ b/calc/__init__.py @@ -6,4 +6,4 @@ from .calc import * -__version__ = '3.1.2' +__version__ = '4.0.0' diff --git a/requirements/base.txt b/requirements/base.txt index c3accbc..c48a348 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,22 +1,22 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -lxml==5.2.1 +lxml==5.3.0 # via -r requirements/base.in -markupsafe==2.1.5 +markupsafe==3.0.2 # via -r requirements/base.in mpmath==1.3.0 # via sympy -numpy==1.24.4 +numpy==2.1.3 # via # -r requirements/base.in # scipy -pyparsing==3.1.2 +pyparsing==3.2.0 # via -r requirements/base.in -scipy==1.10.1 +scipy==1.14.1 # via -r requirements/base.in -sympy==1.12 +sympy==1.13.3 # via -r requirements/base.in diff --git a/requirements/ci.txt b/requirements/ci.txt index 53fbcda..4ed8419 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -1,72 +1,67 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -cachetools==5.3.3 +cachetools==5.5.0 # via # -r requirements/tox.txt # tox -certifi==2024.2.2 +certifi==2024.8.30 # via requests chardet==5.2.0 # via # -r requirements/tox.txt # tox -charset-normalizer==3.3.2 +charset-normalizer==3.4.0 # via requests colorama==0.4.6 # via # -r requirements/tox.txt # tox -coverage==6.5.0 +coverage[toml]==7.6.4 # via coveralls -coveralls==3.3.1 +coveralls==4.0.1 # via -r requirements/ci.in -distlib==0.3.8 +distlib==0.3.9 # via # -r requirements/tox.txt # virtualenv docopt==0.6.2 # via coveralls -filelock==3.13.3 +filelock==3.16.1 # via # -r requirements/tox.txt # tox # virtualenv -idna==3.6 +idna==3.10 # via requests -packaging==24.0 +packaging==24.2 # via # -r requirements/tox.txt # pyproject-api # tox -platformdirs==4.2.0 +platformdirs==4.3.6 # via # -r requirements/tox.txt # tox # virtualenv -pluggy==1.4.0 +pluggy==1.5.0 # via # -r requirements/tox.txt # tox -pyproject-api==1.6.1 +pyproject-api==1.8.0 # via # -r requirements/tox.txt # tox -requests==2.31.0 +requests==2.32.3 # via coveralls -tomli==2.0.1 - # via - # -r requirements/tox.txt - # pyproject-api - # tox -tox==4.14.2 +tox==4.23.2 # via -r requirements/tox.txt -urllib3==2.2.1 +urllib3==2.2.3 # via requests -virtualenv==20.25.1 +virtualenv==20.27.1 # via # -r requirements/tox.txt # tox diff --git a/requirements/common_constraints.txt b/requirements/common_constraints.txt index e3bf8ea..cadbfbd 100644 --- a/requirements/common_constraints.txt +++ b/requirements/common_constraints.txt @@ -17,16 +17,19 @@ Django<5.0 # elasticsearch>=7.14.0 includes breaking changes in it which caused issues in discovery upgrade process. # elastic search changelog: https://www.elastic.co/guide/en/enterprise-search/master/release-notes-7.14.0.html +# See https://github.com/openedx/edx-platform/issues/35126 for more info elasticsearch<7.14.0 # django-simple-history>3.0.0 adds indexing and causes a lot of migrations to be affected django-simple-history==3.0.0 -# opentelemetry requires version 6.x at the moment: -# https://github.com/open-telemetry/opentelemetry-python/issues/3570 -# Normally this could be added as a constraint in edx-django-utils, where we're -# adding the opentelemetry dependency. However, when we compile pip-tools.txt, -# that uses version 7.x, and then there's no undoing that when compiling base.txt. -# So we need to pin it globally, for now. -# Ticket for unpinning: https://github.com/openedx/edx-lint/issues/407 -importlib-metadata<7 +# Cause: https://github.com/openedx/event-tracking/pull/290 +# event-tracking 2.4.1 upgrades to pymongo 4.4.0 which is not supported on edx-platform. +# We will pin event-tracking to do not break existing installations +# This can be unpinned once https://github.com/openedx/edx-platform/issues/34586 +# has been resolved and edx-platform is running with pymongo>=4.4.0 +event-tracking<2.4.1 + +# Cause: https://github.com/openedx/edx-lint/issues/458 +# This can be unpinned once https://github.com/openedx/edx-lint/issues/459 has been resolved. +pip<24.3 diff --git a/requirements/pip.txt b/requirements/pip.txt index cf44902..a5d49fa 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1,14 +1,16 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -wheel==0.43.0 +wheel==0.44.0 # via -r requirements/pip.in # The following packages are considered to be unsafe in a requirements file: -pip==24.0 - # via -r requirements/pip.in -setuptools==69.2.0 +pip==24.2 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # -r requirements/pip.in +setuptools==75.3.0 # via -r requirements/pip.in diff --git a/requirements/pip_tools.txt b/requirements/pip_tools.txt index e64299a..bbfb435 100644 --- a/requirements/pip_tools.txt +++ b/requirements/pip_tools.txt @@ -1,34 +1,23 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -build==1.2.1 +build==1.2.2.post1 # via pip-tools click==8.1.7 # via pip-tools -importlib-metadata==6.11.0 - # via - # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt - # build -packaging==24.0 +packaging==24.2 # via build pip-tools==7.4.1 # via -r requirements/pip_tools.in -pyproject-hooks==1.0.0 - # via - # build - # pip-tools -tomli==2.0.1 +pyproject-hooks==1.2.0 # via # build # pip-tools - # pyproject-hooks -wheel==0.43.0 +wheel==0.44.0 # via pip-tools -zipp==3.18.1 - # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/requirements/test.in b/requirements/test.in index a5353a8..6e6f3e5 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -7,4 +7,5 @@ coverage edx-lint pycodestyle pylint +pytest tox diff --git a/requirements/test.txt b/requirements/test.txt index 597918f..e18e505 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,14 +1,14 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -astroid==3.1.0 +astroid==3.3.5 # via # pylint # pylint-celery -cachetools==5.3.3 +cachetools==5.5.0 # via tox chardet==5.2.0 # via tox @@ -19,29 +19,31 @@ click==8.1.7 # edx-lint click-log==0.4.0 # via edx-lint -code-annotations==1.7.0 +code-annotations==1.8.0 # via edx-lint colorama==0.4.6 # via tox -coverage==7.4.4 +coverage==7.6.4 # via -r requirements/test.in -dill==0.3.8 +dill==0.3.9 # via pylint -distlib==0.3.8 +distlib==0.3.9 # via virtualenv -edx-lint==5.3.6 +edx-lint==5.4.1 # via -r requirements/test.in -filelock==3.13.3 +filelock==3.16.1 # via # tox # virtualenv +iniconfig==2.0.0 + # via pytest isort==5.13.2 # via pylint -jinja2==3.1.3 +jinja2==3.1.4 # via code-annotations -lxml==5.2.1 +lxml==5.3.0 # via -r requirements/base.txt -markupsafe==2.1.5 +markupsafe==3.0.2 # via # -r requirements/base.txt # jinja2 @@ -51,26 +53,29 @@ mpmath==1.3.0 # via # -r requirements/base.txt # sympy -numpy==1.24.4 +numpy==2.1.3 # via # -r requirements/base.txt # scipy -packaging==24.0 +packaging==24.2 # via # pyproject-api + # pytest # tox -pbr==6.0.0 +pbr==6.1.0 # via stevedore -platformdirs==4.2.0 +platformdirs==4.3.6 # via # pylint # tox # virtualenv -pluggy==1.4.0 - # via tox -pycodestyle==2.11.1 +pluggy==1.5.0 + # via + # pytest + # tox +pycodestyle==2.12.1 # via -r requirements/test.in -pylint==3.1.0 +pylint==3.3.1 # via # -r requirements/test.in # edx-lint @@ -79,42 +84,35 @@ pylint==3.1.0 # pylint-plugin-utils pylint-celery==0.3 # via edx-lint -pylint-django==2.5.5 +pylint-django==2.6.1 # via edx-lint pylint-plugin-utils==0.8.2 # via # pylint-celery # pylint-django -pyparsing==3.1.2 +pyparsing==3.2.0 # via -r requirements/base.txt -pyproject-api==1.6.1 +pyproject-api==1.8.0 # via tox +pytest==8.3.3 + # via -r requirements/test.in python-slugify==8.0.4 # via code-annotations -pyyaml==6.0.1 +pyyaml==6.0.2 # via code-annotations -scipy==1.10.1 +scipy==1.14.1 # via -r requirements/base.txt six==1.16.0 # via edx-lint -stevedore==5.2.0 +stevedore==5.3.0 # via code-annotations -sympy==1.12 +sympy==1.13.3 # via -r requirements/base.txt text-unidecode==1.3 # via python-slugify -tomli==2.0.1 - # via - # pylint - # pyproject-api - # tox -tomlkit==0.12.4 +tomlkit==0.13.2 # via pylint -tox==4.14.2 +tox==4.23.2 # via -r requirements/test.in -typing-extensions==4.10.0 - # via - # astroid - # pylint -virtualenv==20.25.1 +virtualenv==20.27.1 # via tox diff --git a/requirements/tox.txt b/requirements/tox.txt index cc5293d..fbfdeef 100644 --- a/requirements/tox.txt +++ b/requirements/tox.txt @@ -1,38 +1,34 @@ # -# This file is autogenerated by pip-compile with Python 3.8 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -cachetools==5.3.3 +cachetools==5.5.0 # via tox chardet==5.2.0 # via tox colorama==0.4.6 # via tox -distlib==0.3.8 +distlib==0.3.9 # via virtualenv -filelock==3.13.3 +filelock==3.16.1 # via # tox # virtualenv -packaging==24.0 +packaging==24.2 # via # pyproject-api # tox -platformdirs==4.2.0 +platformdirs==4.3.6 # via # tox # virtualenv -pluggy==1.4.0 +pluggy==1.5.0 # via tox -pyproject-api==1.6.1 +pyproject-api==1.8.0 # via tox -tomli==2.0.1 - # via - # pyproject-api - # tox -tox==4.14.2 +tox==4.23.2 # via -r requirements/tox.in -virtualenv==20.25.1 +virtualenv==20.27.1 # via tox diff --git a/setup.py b/setup.py index c1914ab..87ecf0d 100644 --- a/setup.py +++ b/setup.py @@ -135,7 +135,7 @@ def get_version(*file_paths): ], include_package_data=True, install_requires=load_requirements('requirements/base.in'), - python_requires=">=3.8", + python_requires=">=3.11", license="AGPL 3.0", test_suite='tests', tests_require=[ @@ -149,7 +149,7 @@ def get_version(*file_paths): 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)', 'Natural Language :: English', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', ], ) diff --git a/symmath/formula.py b/symmath/formula.py index c377f4e..4f9d83e 100644 --- a/symmath/formula.py +++ b/symmath/formula.py @@ -113,7 +113,7 @@ def my_evalf(expr, chop=False): return expr -def my_sympify(expr, normphase=False, matrix=False, abcsym=False, do_qubit=False, symtab=None): +def my_sympify(expr, normphase=False, matrix=False, abcsym=False, do_qubit=False, symtab=None): # pylint: disable=too-many-positional-arguments """ Version of sympify to import expression into sympy """ diff --git a/symmath/symmath_check.py b/symmath/symmath_check.py index 343c9a8..fd7cead 100644 --- a/symmath/symmath_check.py +++ b/symmath/symmath_check.py @@ -62,7 +62,7 @@ def symmath_check_simple(expect, ans, adict={}, symtab=None, extra_options=None) # pretty generic checking function -def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym=False, do_qubit=True, symtab=None, dosimplify=False): # lint-amnesty, pylint: disable=line-too-long +def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym=False, do_qubit=True, symtab=None, dosimplify=False): # lint-amnesty, pylint: disable=line-too-long, too-many-positional-arguments """ Returns dict with @@ -172,7 +172,7 @@ def is_within_tolerance(expected, actual, tolerance): # This is one of the main entry points to call. -def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None): # lint-amnesty, pylint: disable=too-many-statements +def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None): # lint-amnesty, pylint: disable=too-many-statements, too-many-positional-arguments """ Check a symbolic mathematical expression using sympy. The input may be presentation MathML. Uses formula. diff --git a/tests/test_calc.py b/tests/test_calc.py index 2efccc0..e9118a1 100644 --- a/tests/test_calc.py +++ b/tests/test_calc.py @@ -352,13 +352,9 @@ def test_other_functions(self): self.assert_function_values('factorial', fact_inputs, fact_values) self.assertRaises(ValueError, calc.evaluator, {}, {}, "fact(-1)") - # There are 2 errors below because py3.8 raises ValueError and 3.11 raises TypeError - # Value error to be removed when we remove py3.8 support - self.assertRaises((TypeError, ValueError), calc.evaluator, {}, {}, "fact(0.5)") + self.assertRaises(TypeError, calc.evaluator, {}, {}, "fact(0.5)") self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(-1)") - # There are 2 errors below because py3.8 raises ValueError and 3.11 raises TypeError - # Value error to be removed when we remove py3.8 support - self.assertRaises((TypeError, ValueError), calc.evaluator, {}, {}, "factorial(0.5)") + self.assertRaises(TypeError, calc.evaluator, {}, {}, "factorial(0.5)") def test_constants(self): """ diff --git a/tox.ini b/tox.ini index 3d77849..9b9d583 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{38,311},quality +envlist = py{311,312},quality [testenv] allowlist_externals = @@ -8,7 +8,7 @@ deps = setuptools -r requirements/test.txt commands = - coverage run setup.py test + coverage run -m pytest coverage report [testenv:quality]