[med-svn] [Git][med-team/python-prefixed][upstream] New upstream version 0.5.0

Nilesh Patra (@nilesh) gitlab at salsa.debian.org
Sat Dec 31 12:13:26 GMT 2022



Nilesh Patra pushed to branch upstream at Debian Med / python-prefixed


Commits:
b1025837 by Nilesh Patra at 2022-12-31T17:32:31+05:30
New upstream version 0.5.0
- - - - -


9 changed files:

- − .github/workflows/tests.yml
- − .travis.yml
- README.rst
- doc/prefixes.rst
- doc/spelling_wordlist.txt
- prefixed/__init__.py
- pylintrc
- setup_helpers.py
- tests/test_float.py


Changes:

=====================================
.github/workflows/tests.yml deleted
=====================================
@@ -1,74 +0,0 @@
-name: Tests
-
-on:
-  push:
-  pull_request:
-  release:
-  schedule:
-    # Every Thursday at 1 AM
-    - cron: '0 1 * * 4'
-
-jobs:
-
-  Tests:
-    runs-on: ${{ matrix.os || 'ubuntu-latest' }}
-    name: ${{ startsWith(matrix.toxenv, 'py') && matrix.python-version || format('{0} ({1})', matrix.toxenv, matrix.python-version) }} ${{ matrix.optional && '[OPTIONAL]' }}
-    continue-on-error: ${{ matrix.optional || false }}
-
-    strategy:
-      fail-fast: false
-
-      matrix:
-        python-version: ['3.10']
-        toxenv: [lint, docs, codecov]
-        include:
-
-          - python-version: 3.11
-            toxenv: py311
-
-          - python-version: 3.9
-            toxenv: py39
-
-          - python-version: 3.8
-            toxenv: py38
-
-          - python-version: 3.7
-            toxenv: py37
-
-          - python-version: 3.6
-            toxenv: py36
-
-          - python-version: 3.5
-            toxenv: py35
-
-          - python-version: 2.7
-            toxenv: py27
-
-          - python-version: pypy-2.7
-            toxenv: pypy27
-
-          - python-version: pypy-3.9
-            toxenv: pypy39
-
-          - python-version: '3.12-dev'
-            optional: true
-            toxenv: py312
-            toxpython: 3.12
-
-    env:
-      TOXENV: ${{ matrix.toxenv }}
-      TOXPYTHON: python${{ matrix.toxpython || matrix.python-version }}
-
-    steps:
-      - uses: actions/checkout at v3
-
-      - name: Set up Python ${{ matrix.python-version }}
-        uses: actions/setup-python at v4
-        with:
-          python-version: ${{ matrix.python-version }}
-
-      - name: Install tox
-        run: pip install tox
-
-      - name: Run tox
-        run: tox -- --verbose


=====================================
.travis.yml deleted
=====================================
@@ -1,52 +0,0 @@
-language: python
-os: linux
-
-addons:
-    apt_packages:
-        - enchant
-        - aspell
-        - aspell-en
-
-matrix:
-  include:
-    - python: 3.9
-      env: TOXENV=lint
-
-    - python: 3.9
-      env: TOXENV=docs
-
-    - python: 3.9
-      env: TOXENV=codecov
-
-    - python: 3.10-dev
-      env: TOXENV=py310
-
-    - python: 3.8
-      env: TOXENV=py38
-
-    - python: 3.7
-      env: TOXENV=py37
-
-    - python: 3.6
-      env: TOXENV=py36
-
-    - python: 3.5
-      env: TOXENV=py35
-
-    - python: 2.7
-      env: TOXENV=py27
-
-    - python: pypy
-      env: TOXENV=pypy
-
-    - python: pypy3
-      env: TOXENV=pypy3
-
-  allow_failures:
-     - python: 3.10-dev
-
-install:
-  - pip install tox
-
-script:
-  - tox -- --verbose


=====================================
README.rst
=====================================
@@ -182,41 +182,49 @@ Supported Prefixes
 SI (Decimal) Prefixes
 ^^^^^^^^^^^^^^^^^^^^^
 
-+--------+-------+----------+
-| Prefix | Name  |   Base   |
-+========+=======+==========+
-|   Y    | Yotta | |10^24|  |
-+--------+-------+----------+
-|   Z    | Zetta | |10^21|  |
-+--------+-------+----------+
-|   E    | Exa   | |10^18|  |
-+--------+-------+----------+
-|   P    | Peta  | |10^15|  |
-+--------+-------+----------+
-|   T    | Tera  | |10^12|  |
-+--------+-------+----------+
-|   G    | Giga  | |10^9|   |
-+--------+-------+----------+
-|   M    | Mega  | |10^6|   |
-+--------+-------+----------+
-|   k    | Kilo  | |10^3|   |
-+--------+-------+----------+
-|   m    | Milli | |10^-3|  |
-+--------+-------+----------+
-|   μ    | Micro | |10^-6|  |
-+--------+-------+----------+
-|   n    | Nano  | |10^-9|  |
-+--------+-------+----------+
-|   p    | Pico  | |10^-12| |
-+--------+-------+----------+
-|   f    | Femto | |10^-15| |
-+--------+-------+----------+
-|   a    | Atto  | |10^-18| |
-+--------+-------+----------+
-|   z    | Zepto | |10^-21| |
-+--------+-------+----------+
-|   y    | Yocto | |10^-24| |
-+--------+-------+----------+
++--------+--------+----------+
+| Prefix | Name   |   Base   |
++========+========+==========+
+|   Q    | Quetta | |10^30|  |
++--------+--------+----------+
+|   R    | Ronna  | |10^27|  |
++--------+--------+----------+
+|   Y    | Yotta  | |10^24|  |
++--------+--------+----------+
+|   Z    | Zetta  | |10^21|  |
++--------+--------+----------+
+|   E    | Exa    | |10^18|  |
++--------+--------+----------+
+|   P    | Peta   | |10^15|  |
++--------+--------+----------+
+|   T    | Tera   | |10^12|  |
++--------+--------+----------+
+|   G    | Giga   | |10^9|   |
++--------+--------+----------+
+|   M    | Mega   | |10^6|   |
++--------+--------+----------+
+|   k    | Kilo   | |10^3|   |
++--------+--------+----------+
+|   m    | Milli  | |10^-3|  |
++--------+--------+----------+
+|   μ    | Micro  | |10^-6|  |
++--------+--------+----------+
+|   n    | Nano   | |10^-9|  |
++--------+--------+----------+
+|   p    | Pico   | |10^-12| |
++--------+--------+----------+
+|   f    | Femto  | |10^-15| |
++--------+--------+----------+
+|   a    | Atto   | |10^-18| |
++--------+--------+----------+
+|   z    | Zepto  | |10^-21| |
++--------+--------+----------+
+|   y    | Yocto  | |10^-24| |
++--------+--------+----------+
+|   r    | Ronto  | |10^-27| |
++--------+--------+----------+
+|   q    | Quecto | |10^-30| |
++--------+--------+----------+
 
 IEC (Binary) Prefixes
 ^^^^^^^^^^^^^^^^^^^^^
@@ -248,6 +256,8 @@ IEC (Binary) Prefixes
 .. _prefixed.Float: https://prefixed.readthedocs.io/en/stable/api.html#prefixed.Float
 .. _format(): https://docs.python.org/3/library/functions.html#format
 
+.. |10^30| replace:: 10\ :sup:`30`\
+.. |10^27| replace:: 10\ :sup:`27`\
 .. |10^24| replace:: 10\ :sup:`24`\
 .. |10^21| replace:: 10\ :sup:`21`\
 .. |10^18| replace:: 10\ :sup:`18`\
@@ -264,6 +274,8 @@ IEC (Binary) Prefixes
 .. |10^-18| replace:: 10\ :sup:`-18`\
 .. |10^-21| replace:: 10\ :sup:`-21`\
 .. |10^-24| replace:: 10\ :sup:`-24`\
+.. |10^-27| replace:: 10\ :sup:`-27`\
+.. |10^-30| replace:: 10\ :sup:`-30`\
 
 .. |2^80| replace:: 2\ :sup:`80`\
 .. |2^70| replace:: 2\ :sup:`70`\


=====================================
doc/prefixes.rst
=====================================
@@ -1,5 +1,5 @@
 ..
-  Copyright 2020 Avram Lubkin, All Rights Reserved
+  Copyright 2020 - 2022 Avram Lubkin, All Rights Reserved
 
   This Source Code Form is subject to the terms of the Mozilla Public
   License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,41 +13,49 @@ Supported Prefixes
 SI (Decimal) Prefixes
 ^^^^^^^^^^^^^^^^^^^^^
 
-+--------+-------+----------+
-| Prefix | Name  |   Base   |
-+========+=======+==========+
-|   Y    | Yotta | |10^24|  |
-+--------+-------+----------+
-|   Z    | Zetta | |10^21|  |
-+--------+-------+----------+
-|   E    | Exa   | |10^18|  |
-+--------+-------+----------+
-|   P    | Peta  | |10^15|  |
-+--------+-------+----------+
-|   T    | Tera  | |10^12|  |
-+--------+-------+----------+
-|   G    | Giga  | |10^9|   |
-+--------+-------+----------+
-|   M    | Mega  | |10^6|   |
-+--------+-------+----------+
-|   k    | Kilo  | |10^3|   |
-+--------+-------+----------+
-|   m    | Milli | |10^-3|  |
-+--------+-------+----------+
-|   μ    | Micro | |10^-6|  |
-+--------+-------+----------+
-|   n    | Nano  | |10^-9|  |
-+--------+-------+----------+
-|   p    | Pico  | |10^-12| |
-+--------+-------+----------+
-|   f    | Femto | |10^-15| |
-+--------+-------+----------+
-|   a    | Atto  | |10^-18| |
-+--------+-------+----------+
-|   z    | Zepto | |10^-21| |
-+--------+-------+----------+
-|   y    | Yocto | |10^-24| |
-+--------+-------+----------+
++--------+--------+----------+
+| Prefix | Name   |   Base   |
++========+========+==========+
+|   Q    | Quetta | |10^30|  |
++--------+--------+----------+
+|   R    | Ronna  | |10^27|  |
++--------+--------+----------+
+|   Y    | Yotta  | |10^24|  |
++--------+--------+----------+
+|   Z    | Zetta  | |10^21|  |
++--------+--------+----------+
+|   E    | Exa    | |10^18|  |
++--------+--------+----------+
+|   P    | Peta   | |10^15|  |
++--------+--------+----------+
+|   T    | Tera   | |10^12|  |
++--------+--------+----------+
+|   G    | Giga   | |10^9|   |
++--------+--------+----------+
+|   M    | Mega   | |10^6|   |
++--------+--------+----------+
+|   k    | Kilo   | |10^3|   |
++--------+--------+----------+
+|   m    | Milli  | |10^-3|  |
++--------+--------+----------+
+|   μ    | Micro  | |10^-6|  |
++--------+--------+----------+
+|   n    | Nano   | |10^-9|  |
++--------+--------+----------+
+|   p    | Pico   | |10^-12| |
++--------+--------+----------+
+|   f    | Femto  | |10^-15| |
++--------+--------+----------+
+|   a    | Atto   | |10^-18| |
++--------+--------+----------+
+|   z    | Zepto  | |10^-21| |
++--------+--------+----------+
+|   y    | Yocto  | |10^-24| |
++--------+--------+----------+
+|   r    | Ronto  | |10^-27| |
++--------+--------+----------+
+|   q    | Quecto | |10^-30| |
++--------+--------+----------+
 
 IEC (Binary) Prefixes
 ^^^^^^^^^^^^^^^^^^^^^
@@ -72,6 +80,8 @@ IEC (Binary) Prefixes
 |   K    | Kibi | |2^10| |
 +--------+------+--------+
 
+.. |10^30| replace:: 10\ :sup:`30`\
+.. |10^27| replace:: 10\ :sup:`27`\
 .. |10^24| replace:: 10\ :sup:`24`\
 .. |10^21| replace:: 10\ :sup:`21`\
 .. |10^18| replace:: 10\ :sup:`18`\
@@ -88,6 +98,8 @@ IEC (Binary) Prefixes
 .. |10^-18| replace:: 10\ :sup:`-18`\
 .. |10^-21| replace:: 10\ :sup:`-21`\
 .. |10^-24| replace:: 10\ :sup:`-24`\
+.. |10^-27| replace:: 10\ :sup:`-27`\
+.. |10^-30| replace:: 10\ :sup:`-30`\
 
 .. |2^80| replace:: 2\ :sup:`80`\
 .. |2^70| replace:: 2\ :sup:`70`\


=====================================
doc/spelling_wordlist.txt
=====================================
@@ -14,6 +14,10 @@ Nano
 Pedi
 Peta
 Pico
+Quecto
+Quetta
+Ronna
+Ronto
 Tebi
 Tera
 Yobi


=====================================
prefixed/__init__.py
=====================================
@@ -15,7 +15,7 @@ from math import floor, log10
 import re
 import sys
 
-__version__ = '0.4.1'
+__version__ = '0.5.0'
 
 try:
     BASESTRING = basestring
@@ -51,6 +51,8 @@ RE_PREFIX = re.compile(
 )
 
 SI_PREFIXES = {
+    10**-30: 'q',  # Quecto
+    10**-27: 'r',  # Ronto
     10**-24: 'y',  # Yocto
     10**-21: 'z',  # Zepto
     10**-18: 'a',  # Atto
@@ -67,7 +69,10 @@ SI_PREFIXES = {
     10**18: 'E',  # Exa
     10**21: 'Z',  # Zetta
     10**24: 'Y',  # Yotta
+    10**27: 'R',  # Ronna
+    10**30: 'Q',  # Quetta
 }
+SI_SMALLEST = 10 ** -30
 
 SI_MAGNITUDE = {val: key for key, val in SI_PREFIXES.items()}
 
@@ -84,8 +89,8 @@ IEC_PREFIXES = {
 
 IEC_MAGNITUDE = {val: key for key, val in IEC_PREFIXES.items()}
 
-SI_SMALL = range(-24, 0, 3)
-SI_LARGE = range(3, 27, 3)
+SI_SMALL = range(-30, 0, 3)
+SI_LARGE = range(3, 33, 3)
 IEC_RANGE = range(10, 90, 10)
 
 SPEC_FIELDS = ('fill', 'align', 'sign', 'alt', 'zero', 'width', 'grouping')
@@ -100,12 +105,8 @@ def raise_from_none(exc):  # pragma: no cover
 
 if sys.version_info[0] >= 3:  # pragma: no branch
     exec('def raise_from_none(exc):\n    raise exc from None')  # pylint: disable=exec-used
-    maketrans = str.maketrans
-else:
-    from string import maketrans  # pragma: no cover
 
-DEPRECATED = {'j', 'J'}
-TRANS_DEPRECATED = maketrans('jJ', 'km')
+DEPRECATED = {'j': 'k', 'J': 'm'}
 
 
 def _convert(value, spec):
@@ -126,8 +127,8 @@ def _convert(value, spec):
 
     margin = 1.0 if spec['margin'] is None else (100.0 + float(spec['margin'])) / 100.0
 
-    if span is SI_SMALL and 0 < absolute_value < 10 ** -24 * margin:
-        magnitude = 10 ** -24
+    if span is SI_SMALL and 0 < absolute_value < SI_SMALLEST * margin:
+        magnitude = SI_SMALLEST
     else:
         magnitude = 0
         for exp in span:
@@ -302,7 +303,7 @@ class Float(float):
 
         # Handle deprecated spec types
         if spec['type'] in DEPRECATED:
-            spec['type'] = spec['type'].translate(TRANS_DEPRECATED)
+            spec['type'] = DEPRECATED[spec['type']]
 
         # If not a spec we handle, use float.__format__(()
         if spec['type'] not in {'h', 'H', 'k', 'K', 'm', 'M'}:
@@ -316,9 +317,15 @@ class Float(float):
         # Adjust precision for significant digits
         if spec['type'] in 'HKM':
             precision = precision or 6
-            int_digits = 1 if value == 0.0 else floor(log10(abs(value))) + 1
-            # In Python 2.7, floor sometimes returns a float, so ad coercion
-            value = round(value, int(precision - int_digits))
+
+            # Try to avoid floating point variance by limiting trailing decimals
+            if value >= 1:
+                value = round(value, precision + 1)
+
+            # In Python 2.7, floor sometimes returns a float, so coerce with int
+            int_digits = 1 if value == 0.0 else int(floor(log10(abs(value)))) + 1
+
+            value = round(value, precision - int_digits)
             precision = max(0, precision - int_digits)
 
             if precision and not spec['alt']:


=====================================
pylintrc
=====================================
@@ -25,7 +25,8 @@ spelling-ignore-words=
     mebi, milli, MPL,
     nano,
     pedi, peta, pragma, pico, py,
-    repr,
+    quecto, quetta,
+    repr, ronna, ronto,
     sphinxcontrib,
     tebi, tera,
     yobi, yocto, yotta,


=====================================
setup_helpers.py
=====================================
@@ -122,11 +122,12 @@ def check_copyrights():
     )
     for entry in process.stdout.splitlines():
         filename = entry[3:].strip()
+        diff_cmd = ['git', 'diff', filename]
+        if entry[0].strip():
+            diff_cmd.insert(-1, '--cached')
 
         # Get changes for file
-        process = subprocess.run(
-            ('git', 'diff', '-U0', filename), stdout=subprocess.PIPE, check=True, text=True
-        )
+        process = subprocess.run(diff_cmd, stdout=subprocess.PIPE, check=True, text=True)
 
         # Find files with changes that aren't only for copyright
         for line in process.stdout.splitlines():


=====================================
tests/test_float.py
=====================================
@@ -95,9 +95,17 @@ class TestFloatFormatting(unittest.TestCase):
             (1.01e24, '1.01Y', '1Y', '1.01Y'),
             (1.001e25, '10.01Y', '10Y', '10.0Y'),
             (1.0001e26, '100.01Y', '100Y', '100Y'),
-            (1.01e27, '1010.00Y', '1000Y', '1010Y'),
-            (1.001e28, '10010.00Y', '10000Y', '10000Y'),
-            (1.0001e28, '10001.00Y', '10000Y', '10000Y'),
+            (1.01e27, '1.01R', '1R', '1.01R'),
+            (1.001e28, '10.01R', '10R', '10.0R'),
+            (1.0001e29, '100.01R', '100R', '100R'),
+            (1.01e30, '1.01Q', '1Q', '1.01Q'),
+            (1.001e31, '10.01Q', '10Q', '10.0Q'),
+            (1.0001e32, '100.01Q', '100Q', '100Q'),
+
+            # Larger than largest magnitude
+            (1.01e33, '1010.00Q', '1000Q', '1010Q'),
+            (1.001e34, '10010.00Q', '10000Q', '10000Q'),
+            (1.0001e35, '100010.00Q', '100000Q', '100000Q'),
 
             (10, '10.00', '10', '10.0'),
             (1e2, '100.00', '100', '100'),
@@ -125,9 +133,17 @@ class TestFloatFormatting(unittest.TestCase):
             (1e24, '1.00Y', '1Y', '1.00Y'),
             (1e25, '10.00Y', '10Y', '10.0Y'),
             (1e26, '100.00Y', '100Y', '100Y'),
-            (1e27, '1000.00Y', '1000Y', '1000Y'),
-            (1e28, '10000.00Y', '10000Y', '10000Y'),
-            (1e29, '100000.00Y', '100000Y', '100000Y'),
+            (1e27, '1.00R', '1R', '1.00R'),
+            (1e28, '10.00R', '10R', '10.0R'),
+            (1e29, '100.00R', '100R', '100R'),
+            (1e30, '1.00Q', '1Q', '1.00Q'),
+            (1e31, '10.00Q', '10Q', '10.0Q'),
+            (1e32, '100.00Q', '100Q', '100Q'),
+
+            # Larger than largest magnitude
+            (1e33, '1000.00Q', '1000Q', '1000Q'),
+            (1e34, '10000.00Q', '10000Q', '10000Q'),
+            (1e35, '100000.00Q', '100000Q', '100000Q'),
         )
 
         for test in tests:
@@ -167,9 +183,19 @@ class TestFloatFormatting(unittest.TestCase):
             (1e-22, '100.00y', '100y', '100y'),
             (1e-23, '10.00y', '10y', '10.0y'),
             (1e-24, '1.00y', '1y', '1.00y'),
-            (1e-25, '0.10y', '0.1y', '0.100y'),
-            (1e-26, '0.01y', '0.01y', '0.0100y'),
-            (1e-27, '0.00y', '0.001y', '0.00100y'),
+            (1e-25, '100.00r', '100r', '100r'),
+            (1e-26, '10.00r', '10r', '10.0r'),
+            (1e-27, '1.00r', '1r', '1.00r'),
+            (1e-28, '100.00q', '100q', '100q'),
+
+
+            (1e-29, '10.00q', '10q', '10.0q'),
+            (1e-30, '1.00q', '1q', '1.00q'),
+
+            # Smaller than smallest magnitude
+            (1e-31, '0.10q', '0.1q', '0.100q'),
+            (1e-32, '0.01q', '0.01q', '0.0100q'),
+            (1e-33, '0.00q', '0.001q', '0.00100q'),
         )
 
         for test in tests:
@@ -426,6 +452,10 @@ class TestFloatFormatting(unittest.TestCase):
         self.assertEqual(format(Float(2048), '.2j'), '2.00Ki')
         self.assertEqual(format(Float(2048), '.2J'), '2.00K')
 
+        # Unicode for Python 2
+        self.assertEqual(format(Float(2048), u'.2j'), '2.00Ki')
+        self.assertEqual(format(Float(2048), u'.2J'), '2.00K')
+
 
 class TestFloatMath(unittest.TestCase):
     """



View it on GitLab: https://salsa.debian.org/med-team/python-prefixed/-/commit/b1025837910027da855f91f3c83ced025c007825

-- 
View it on GitLab: https://salsa.debian.org/med-team/python-prefixed/-/commit/b1025837910027da855f91f3c83ced025c007825
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20221231/a99918ca/attachment-0001.htm>


More information about the debian-med-commit mailing list