././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1675007519.4718919 argparse_addons-0.12.0/0000755000175100001720000000000000000000000015527 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/LICENSE0000644000175100001720000000207000000000000016533 0ustar00runnerdocker00000000000000The MIT License (MIT) Copyright (c) 2020 Erik Moqvist Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/MANIFEST.in0000644000175100001720000000007600000000000017270 0ustar00runnerdocker00000000000000include LICENSE include Makefile recursive-include tests *.py ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/Makefile0000644000175100001720000000120000000000000017160 0ustar00runnerdocker00000000000000.PHONY: examples test: python3 setup.py test examples: ! PYTHONPATH=. python3 examples/integer.py --min-max -1 ! PYTHONPATH=. python3 examples/integer.py --min -1 ! PYTHONPATH=. python3 examples/integer.py --max 1000 ! PYTHONPATH=. python3 examples/integer.py --any a PYTHONPATH=. python3 examples/integer.py \ --min-max 47 --min 1000 --max -5 --any 1 test-sdist: rm -rf dist python3 setup.py sdist cd dist && \ mkdir test && \ cd test && \ tar xf ../*.tar.gz && \ cd argparse_addons-* && \ python3 setup.py test release-to-pypi: python3 setup.py sdist python3 setup.py bdist_wheel --universal twine upload dist/* ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1675007519.467892 argparse_addons-0.12.0/PKG-INFO0000644000175100001720000000531700000000000016632 0ustar00runnerdocker00000000000000Metadata-Version: 2.1 Name: argparse_addons Version: 0.12.0 Summary: Additional argparse types and actions. Home-page: https://github.com/eerimoq/argparse_addons Author: Erik Moqvist Author-email: erik.moqvist@gmail.com License: MIT Keywords: argparse Classifier: License :: OSI Approved :: MIT License Requires-Python: >=3.6 License-File: LICENSE About ===== Additional Python argparse types and actions. Project homepage: https://github.com/eerimoq/argparse_addons Installation ============ .. code-block:: text $ pip install argparse_addons Examples ======== Integer type ------------ The script. See `examples/integer.py`_ for the complete script. .. code-block:: python parser.add_argument('--min-max', type=argparse_addons.Integer(0, 255)) parser.add_argument('--min', type=argparse_addons.Integer(0, None)) parser.add_argument('--max', type=argparse_addons.Integer(None, 255)) parser.add_argument('--any', type=argparse_addons.Integer()) Error message for the ``--min-max`` argument. .. code-block:: text $ python3 examples/integer.py --min-max -1 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --min-max: -1 is not in the range 0..255 Error message for the ``--min`` argument. .. code-block:: text $ python3 examples/integer.py --min -1 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --min: -1 is not in the range 0..inf Error message for the ``--max`` argument. .. code-block:: text $ python3 examples/integer.py --max 1000 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --max: 1000 is not in the range -inf..255 Error message for the ``--any`` argument. .. code-block:: text $ python3 examples/integer.py --any a usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --any: invalid integer value: 'a' All values within allowed ranges. .. code-block:: text $ python3 examples/integer.py --min-max 47 --min 1000 --max -5 --any 1 --min-max: 47 --min: 1000 --max: -5 --any: 1 Contributing ============ #. Fork the repository. #. Install prerequisites. .. code-block:: text pip install -r requirements.txt #. Implement the new feature or bug fix. #. Implement test case(s) to ensure that future changes do not break legacy. #. Run the tests. .. code-block:: text make test #. Create a pull request. .. _examples/integer.py: https://github.com/eerimoq/argparse_addons/blob/master/examples/integer.py ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/README.rst0000644000175100001720000000456200000000000017225 0ustar00runnerdocker00000000000000About ===== Additional Python argparse types and actions. Project homepage: https://github.com/eerimoq/argparse_addons Installation ============ .. code-block:: text $ pip install argparse_addons Examples ======== Integer type ------------ The script. See `examples/integer.py`_ for the complete script. .. code-block:: python parser.add_argument('--min-max', type=argparse_addons.Integer(0, 255)) parser.add_argument('--min', type=argparse_addons.Integer(0, None)) parser.add_argument('--max', type=argparse_addons.Integer(None, 255)) parser.add_argument('--any', type=argparse_addons.Integer()) Error message for the ``--min-max`` argument. .. code-block:: text $ python3 examples/integer.py --min-max -1 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --min-max: -1 is not in the range 0..255 Error message for the ``--min`` argument. .. code-block:: text $ python3 examples/integer.py --min -1 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --min: -1 is not in the range 0..inf Error message for the ``--max`` argument. .. code-block:: text $ python3 examples/integer.py --max 1000 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --max: 1000 is not in the range -inf..255 Error message for the ``--any`` argument. .. code-block:: text $ python3 examples/integer.py --any a usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --any: invalid integer value: 'a' All values within allowed ranges. .. code-block:: text $ python3 examples/integer.py --min-max 47 --min 1000 --max -5 --any 1 --min-max: 47 --min: 1000 --max: -5 --any: 1 Contributing ============ #. Fork the repository. #. Install prerequisites. .. code-block:: text pip install -r requirements.txt #. Implement the new feature or bug fix. #. Implement test case(s) to ensure that future changes do not break legacy. #. Run the tests. .. code-block:: text make test #. Create a pull request. .. _examples/integer.py: https://github.com/eerimoq/argparse_addons/blob/master/examples/integer.py ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1675007519.467892 argparse_addons-0.12.0/argparse_addons.egg-info/0000755000175100001720000000000000000000000022355 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007519.0 argparse_addons-0.12.0/argparse_addons.egg-info/PKG-INFO0000644000175100001720000000531700000000000023460 0ustar00runnerdocker00000000000000Metadata-Version: 2.1 Name: argparse-addons Version: 0.12.0 Summary: Additional argparse types and actions. Home-page: https://github.com/eerimoq/argparse_addons Author: Erik Moqvist Author-email: erik.moqvist@gmail.com License: MIT Keywords: argparse Classifier: License :: OSI Approved :: MIT License Requires-Python: >=3.6 License-File: LICENSE About ===== Additional Python argparse types and actions. Project homepage: https://github.com/eerimoq/argparse_addons Installation ============ .. code-block:: text $ pip install argparse_addons Examples ======== Integer type ------------ The script. See `examples/integer.py`_ for the complete script. .. code-block:: python parser.add_argument('--min-max', type=argparse_addons.Integer(0, 255)) parser.add_argument('--min', type=argparse_addons.Integer(0, None)) parser.add_argument('--max', type=argparse_addons.Integer(None, 255)) parser.add_argument('--any', type=argparse_addons.Integer()) Error message for the ``--min-max`` argument. .. code-block:: text $ python3 examples/integer.py --min-max -1 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --min-max: -1 is not in the range 0..255 Error message for the ``--min`` argument. .. code-block:: text $ python3 examples/integer.py --min -1 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --min: -1 is not in the range 0..inf Error message for the ``--max`` argument. .. code-block:: text $ python3 examples/integer.py --max 1000 usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --max: 1000 is not in the range -inf..255 Error message for the ``--any`` argument. .. code-block:: text $ python3 examples/integer.py --any a usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY] integer.py: error: argument --any: invalid integer value: 'a' All values within allowed ranges. .. code-block:: text $ python3 examples/integer.py --min-max 47 --min 1000 --max -5 --any 1 --min-max: 47 --min: 1000 --max: -5 --any: 1 Contributing ============ #. Fork the repository. #. Install prerequisites. .. code-block:: text pip install -r requirements.txt #. Implement the new feature or bug fix. #. Implement test case(s) to ensure that future changes do not break legacy. #. Run the tests. .. code-block:: text make test #. Create a pull request. .. _examples/integer.py: https://github.com/eerimoq/argparse_addons/blob/master/examples/integer.py ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007519.0 argparse_addons-0.12.0/argparse_addons.egg-info/SOURCES.txt0000644000175100001720000000041700000000000024243 0ustar00runnerdocker00000000000000LICENSE MANIFEST.in Makefile README.rst argparse_addons.py setup.py argparse_addons.egg-info/PKG-INFO argparse_addons.egg-info/SOURCES.txt argparse_addons.egg-info/dependency_links.txt argparse_addons.egg-info/top_level.txt tests/__init__.py tests/test_argparse_addons.py././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007519.0 argparse_addons-0.12.0/argparse_addons.egg-info/dependency_links.txt0000644000175100001720000000000100000000000026423 0ustar00runnerdocker00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007519.0 argparse_addons-0.12.0/argparse_addons.egg-info/top_level.txt0000644000175100001720000000002000000000000025077 0ustar00runnerdocker00000000000000argparse_addons ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/argparse_addons.py0000755000175100001720000000301600000000000021240 0ustar00runnerdocker00000000000000import argparse __version__ = '0.12.0' class Integer: def __init__(self, minimum=None, maximum=None): self.minimum = minimum self.maximum = maximum def __call__(self, string): value = int(string, 0) if self.minimum is not None and self.maximum is not None: if not self.minimum <= value <= self.maximum: raise argparse.ArgumentTypeError( f'{string} is not in the range {self.minimum}..{self.maximum}') elif self.minimum is not None: if value < self.minimum: raise argparse.ArgumentTypeError( f'{string} is not in the range {self.minimum}..inf') elif self.maximum is not None: if value > self.maximum: raise argparse.ArgumentTypeError( f'{string} is not in the range -inf..{self.maximum}') return value def __repr__(self): return 'integer' def parse_log_level(value): """Parse given set log level value. Examples: = =:= ,= """ result = [] if value is None: return result for part in value.split(':'): if '=' in part: names, level = part.split('=') for name in names.split(','): result.append((name, level)) else: # None for root logger. result.append((None, part)) return result ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1675007519.4718919 argparse_addons-0.12.0/setup.cfg0000644000175100001720000000004600000000000017350 0ustar00runnerdocker00000000000000[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/setup.py0000755000175100001720000000122000000000000017237 0ustar00runnerdocker00000000000000#!/usr/bin/env python from setuptools import setup import argparse_addons setup(name='argparse_addons', version=argparse_addons.__version__, description=('Additional argparse types and actions.'), long_description=open('README.rst', 'r').read(), author='Erik Moqvist', author_email='erik.moqvist@gmail.com', license='MIT', classifiers=[ 'License :: OSI Approved :: MIT License', ], keywords=['argparse'], url='https://github.com/eerimoq/argparse_addons', py_modules=['argparse_addons'], python_requires='>=3.6', install_requires=[ ], test_suite="tests") ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1675007519.467892 argparse_addons-0.12.0/tests/0000755000175100001720000000000000000000000016671 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/tests/__init__.py0000644000175100001720000000000000000000000020770 0ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1675007508.0 argparse_addons-0.12.0/tests/test_argparse_addons.py0000644000175100001720000000541100000000000023437 0ustar00runnerdocker00000000000000import unittest import argparse import argparse_addons class ArgparseAddonsTest(unittest.TestCase): def test_integer(self): integer = argparse_addons.Integer() self.assertEqual(integer('0'), 0) self.assertEqual(integer('0x1a'), 0x1a) with self.assertRaises(ValueError): integer('ab') def test_integer_min_and_max(self): integer = argparse_addons.Integer(0, 255) self.assertEqual(integer('0'), 0) self.assertEqual(integer('255'), 255) with self.assertRaises(argparse.ArgumentTypeError) as cm: integer('-1') self.assertEqual(str(cm.exception), '-1 is not in the range 0..255') with self.assertRaises(argparse.ArgumentTypeError) as cm: integer('256') self.assertEqual(str(cm.exception), '256 is not in the range 0..255') with self.assertRaises(ValueError): integer('foobar') def test_integer_min(self): integer = argparse_addons.Integer(0, None) self.assertEqual(integer('0'), 0) self.assertEqual(integer('100000'), 100000) with self.assertRaises(argparse.ArgumentTypeError) as cm: integer('-1') self.assertEqual(str(cm.exception), '-1 is not in the range 0..inf') def test_integer_max(self): integer = argparse_addons.Integer(None, 5) self.assertEqual(integer('5'), 5) self.assertEqual(integer('-111'), -111) with self.assertRaises(argparse.ArgumentTypeError) as cm: integer('6') self.assertEqual(str(cm.exception), '6 is not in the range -inf..5') def test_integer_repr(self): self.assertEqual(repr(argparse_addons.Integer(0, 1)), 'integer') def test_integer_hex(self): integer = argparse_addons.Integer(0, 5) self.assertEqual(integer('0x1'), 1) def test_parse_log_level(self): levels = argparse_addons.parse_log_level('info') self.assertEqual(levels, [(None, 'info')]) levels = argparse_addons.parse_log_level('foo=info') self.assertEqual(levels, [('foo', 'info')]) levels = argparse_addons.parse_log_level('foo=info:bar=debug') self.assertEqual(levels, [ ('foo', 'info'), ('bar', 'debug') ]) levels = argparse_addons.parse_log_level('foo,fie=kalle:bar=debug:debug') self.assertEqual(levels, [ ('foo', 'kalle'), ('fie', 'kalle'), ('bar', 'debug'), (None, 'debug') ]) levels = argparse_addons.parse_log_level(None) self.assertEqual(levels, [])