From 9b355c28d780e87c8795b8f1912fa80914b10aee Mon Sep 17 00:00:00 2001 From: GDeLaurentis Date: Sat, 4 May 2024 21:08:14 +0100 Subject: [PATCH] Improved ModP and PAdic constructors accept a wider range on inputs. Splitting CI into lint and test. Automating PyPI release on github release. --- .github/workflows/ci_lint.yml | 35 +++++++++++++++++++ ...continuous_integration.yml => ci_test.yml} | 15 ++++---- .github/workflows/pypi_release.yml | 28 +++++++++++++++ CHANGELOG.md | 17 +++++++-- README.md | 5 +-- pyadic/finite_field.py | 12 ++++--- pyadic/padic.py | 8 ++++- setup.py | 2 +- 8 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/ci_lint.yml rename .github/workflows/{continuous_integration.yml => ci_test.yml} (76%) create mode 100644 .github/workflows/pypi_release.yml diff --git a/.github/workflows/ci_lint.yml b/.github/workflows/ci_lint.yml new file mode 100644 index 0000000..62aee3c --- /dev/null +++ b/.github/workflows/ci_lint.yml @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +name: CI Lint + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + branches: [ main ] + +jobs: + + CI: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: 3.9 + - name: Checkout this Repo + uses: actions/checkout@v3 + with: + path: pyadic + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 + - name: Lint with flake8 + run: | + cd pyadic + flake8 pyadic/ --count --max-line-length=190 --statistics --verbose diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/ci_test.yml similarity index 76% rename from .github/workflows/continuous_integration.yml rename to .github/workflows/ci_test.yml index 95a3609..dd7fb4b 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/ci_test.yml @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -name: Continuous Integration +name: CI Test on: push: @@ -28,16 +28,19 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest pytest-cov + pip install pytest pytest-cov pip install -e pyadic - - name: Lint with flake8 - run: | - cd pyadic - flake8 pyadic/ --count --max-line-length=190 --statistics --verbose - name: Test with pytest run: | cd pyadic pytest |& tee coverage.txt + PYTEST_EXIT_CODE=${PIPESTATUS[0]} + if [ "$PYTEST_EXIT_CODE" -ne 0 ]; then + echo "pytest failed with exit code $PYTEST_EXIT_CODE" + exit 1 + else + echo "pytest passed with exit code 0" + fi - name: Run update-badges script run: | cd pyadic diff --git a/.github/workflows/pypi_release.yml b/.github/workflows/pypi_release.yml new file mode 100644 index 0000000..1ed3ef7 --- /dev/null +++ b/.github/workflows/pypi_release.yml @@ -0,0 +1,28 @@ +name: PyPI Release + +on: + release: + types: [created] + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build + run: | + python setup.py sdist bdist_wheel + - name: Publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/* diff --git a/CHANGELOG.md b/CHANGELOG.md index e1d7eb3..b9409eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed + +### Fixed + +## [0.2.1] - 2024-05-04 + +### Added + - Multivariate Newton interpolation algorithm, `multivariate_Newton_polynomial_interpolation`. ### Changed - Improved compatibility of `extended_euclidean_algorithm`: output is of same type as input. +- Improved `ModP` and `PAdic` constructors to handle a wider variety of inputs, e.g. `ModP('+1', 2 ** 31 - 1)` is now valid. +- Splitting CI Test and Lint, adding automatic PyPI release workflow. ### Fixed @@ -54,7 +64,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Finite fields, `ModP`. -[unreleased]: https://github.com/GDeLaurentis/pyadic/compare/v0.2.0...HEAD -[0.2.0]: https://github.com/GDeLaurentis/pyadic/releases/tag/v0.2.0 -[0.1.2]: https://github.com/GDeLaurentis/pyadic/releases/tag/v0.1.2 +[unreleased]: https://github.com/GDeLaurentis/pyadic/compare/v0.2.1...HEAD +[0.2.1]: https://github.com/GDeLaurentis/pyadic/compare/v0.2.0...v0.2.1 +[0.2.0]: https://github.com/GDeLaurentis/pyadic/compare/v0.1.2...v0.2.0 +[0.1.2]: https://github.com/GDeLaurentis/pyadic/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/GDeLaurentis/pyadic/releases/tag/v0.1.1 diff --git a/README.md b/README.md index 4c3b6a3..fb64b9d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # pyAdic -[![Continuous Integration Status](https://github.com/GDeLaurentis/pyadic/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/GDeLaurentis/pyadic/actions) +[![CI Lint](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_lint.yml/badge.svg)](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_lint.yml) +[![CI Test](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_test.yml/badge.svg)](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_test.yml) [![Coverage](https://img.shields.io/badge/Coverage-91%25-green?labelColor=2a2f35)](https://github.com/GDeLaurentis/pyadic/actions) -[![pypi](https://img.shields.io/pypi/v/pyadic)](https://pypi.org/project/pyadic/) +[![PyPI](https://img.shields.io/pypi/v/pyadic?label=PyPI)](https://pypi.org/project/pyadic/) [![PyPI Downloads](https://img.shields.io/pypi/dm/pyadic.svg?label=PyPI%20downloads)](https://pypistats.org/packages/pyadic) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/GDeLaurentis/pyadic/HEAD) diff --git a/pyadic/finite_field.py b/pyadic/finite_field.py index 8fd7401..4782d46 100644 --- a/pyadic/finite_field.py +++ b/pyadic/finite_field.py @@ -60,16 +60,18 @@ def __init__(self, n, p=None): raise ValueError("Complex to ModP conversion requires √-1 in field or zero imaginary part.") self.n = res.n self.p = res.p - elif p is None and isinstance(n, ModP): + elif isinstance(n, ModP): + if p is not None: + assert p == n.p self.n = n.n self.p = n.p elif p is None and isinstance(n, padic.PAdic): self.n = int(n) - self.p = n.p ** n.k - elif p is None and isinstance(n, str): - self.n, self.p = self.__rstr__(n) - elif isinstance(n, str) and (n.isnumeric() or n.lstrip("+-").isnumeric()): + self.p = n.p ** n._k + elif isinstance(n, str) and (n.isnumeric() or n.lstrip("+-").isnumeric()) and p is not None: self.n, self.p = int(n) % int(p), p + elif isinstance(n, str): + self.n, self.p = self.__rstr__(n) else: raise TypeError('Bad finite field constructor, (n, p) of value:({}, {}) and type:({}, {}).'.format(n, p, type(n), type(p))) diff --git a/pyadic/padic.py b/pyadic/padic.py index 1a90398..3fa4131 100644 --- a/pyadic/padic.py +++ b/pyadic/padic.py @@ -119,6 +119,8 @@ def __init__(self, num, p=None, k=None, n=0, from_addition=False): elif isinstance(num, fractions.Fraction): res = PAdic(num.numerator, p, k, n, from_addition) / PAdic(num.denominator, p, k, n, from_addition) self.num, self.p, self.k, self.n = res.num, res.p, res.k, res.n + elif isinstance(num, PAdic): + self.num, self.p, self.k, self.n = num.num, num.p, num.k, num.n elif hasattr(num, "imag"): res = PAdic(num.real, p, k, n, from_addition) if num.imag != 0: @@ -131,8 +133,12 @@ def __init__(self, num, p=None, k=None, n=0, from_addition=False): self.k = res.k self.n = res.n self.num = res.num - elif isinstance(num, str): + elif p is None and k is None and isinstance(num, str): self.num, self.p, self.k, self.n = self.__rstr__(num) + elif isinstance(num, str): + num = fractions.Fraction(num) + res = PAdic(num.numerator, p, k, n, from_addition) / PAdic(num.denominator, p, k, n, from_addition) + self.num, self.p, self.k, self.n = res.num, res.p, res.k, res.n else: raise Exception(f"Invalid p-adic initialisation: {num}, {p}, {k}, {n}, {from_addition}.") diff --git a/setup.py b/setup.py index f00bbf6..2b8feeb 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='pyadic', - version='0.2.0', + version='0.2.1', license='GNU General Public License v3.0', description='p-Adic numbers and finite fields in Python', long_description=long_description,