From 60a95f93ca66d18df5943dd78d75fd93c0359fc4 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 13:47:31 -0600 Subject: [PATCH 01/23] Update setup.py --- setup.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 4687965..3dd720b 100644 --- a/setup.py +++ b/setup.py @@ -15,10 +15,11 @@ 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Topic :: Utilities' ], ) From 51e1b466853fba5e764b74bc7474231096d7103c Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 13:53:08 -0600 Subject: [PATCH 02/23] Update __init__.py --- str2bool/__init__.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/str2bool/__init__.py b/str2bool/__init__.py index 4dc0017..41b968e 100644 --- a/str2bool/__init__.py +++ b/str2bool/__init__.py @@ -1,21 +1,22 @@ -import sys +from typing import Union -_true_set = {'yes', 'true', 't', 'y', '1'} -_false_set = {'no', 'false', 'f', 'n', '0'} +# Refactored Python 3.9 compatible code for string to boolean conversion - -def str2bool(value, raise_exc=False): - if isinstance(value, str) or sys.version_info[0] < 3 and isinstance(value, basestring): +def str2bool(value: Union[str, None], raise_exc: bool = False) -> Union[bool, None]: + true_set = {'yes', 'true', 't', 'y', '1'} + false_set = {'no', 'false', 'f', 'n', '0'} + + if isinstance(value, str): value = value.lower() - if value in _true_set: + if value in true_set: return True - if value in _false_set: + if value in false_set: return False - + if raise_exc: - raise ValueError('Expected "%s"' % '", "'.join(_true_set | _false_set)) + raise ValueError(f'Expected one of: {", ".join(true_set | false_set)}') + return None - -def str2bool_exc(value): +def str2bool_exc(value: Union[str, None]) -> bool: return str2bool(value, raise_exc=True) From 477423b163aa9b6e05288c642e8ba07dadbfca5b Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 13:57:51 -0600 Subject: [PATCH 03/23] Update setup.py --- setup.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/setup.py b/setup.py index 3dd720b..dc2bad4 100644 --- a/setup.py +++ b/setup.py @@ -23,3 +23,29 @@ 'Topic :: Utilities' ], ) + + +from setuptools import setup # Prefer setuptools over distutils + +setup( + name='str2bool3', + packages=['str2bool3'], + version='1.0.0', + description='Convert string to boolean (Forked from SymonSoft/str2bool)', + author='Sam Fakhreddine', + author_email='sam.fakhreddine@gmail.com', + url='https://github.com/sam-fakhreddine/str2bool3', + download_url='https://github.com/sam-fakhreddine/str2bool3/tarball/1.0.0', + keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false'], + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Topic :: Utilities' + ], +) From 9e7fb699df747a43d94c493bc4f5233919c1c32d Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 13:58:04 -0600 Subject: [PATCH 04/23] Update setup.py --- setup.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/setup.py b/setup.py index dc2bad4..6c05349 100644 --- a/setup.py +++ b/setup.py @@ -1,30 +1,3 @@ -from distutils.core import setup - - -setup( - name='str2bool', - packages=['str2bool'], - version='1.1', - description='Convert string to boolean', - author='SymonSoft', - author_email='symonsoft@gmail.com', - url='https://github.com/symonsoft/str2bool', - download_url='https://github.com/symonsoft/str2bool/tarball/1.1', - keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false'], - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Topic :: Utilities' - ], -) - - from setuptools import setup # Prefer setuptools over distutils setup( From 63499e6ca38df022bd0c91b5c04b638e0f47561f Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:05:42 -0600 Subject: [PATCH 05/23] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6c05349..b5c5272 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ author='Sam Fakhreddine', author_email='sam.fakhreddine@gmail.com', url='https://github.com/sam-fakhreddine/str2bool3', - download_url='https://github.com/sam-fakhreddine/str2bool3/tarball/1.0.0', + download_url='https://github.com/sam-fakhreddine/str2bool3/archive/refs/tags/1.0.0.tar.gz', keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false'], classifiers=[ 'Development Status :: 5 - Production/Stable', From cdac3b9cef2bd0f5b94cd7ad5456ab324eea7651 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:16:48 -0600 Subject: [PATCH 06/23] Create workflows.yml --- .github/workflows/workflows.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workflows/workflows.yml diff --git a/.github/workflows/workflows.yml b/.github/workflows/workflows.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workflows/workflows.yml @@ -0,0 +1 @@ + From 6b4b09d085c8bb1490d64761dd1eb265852535a1 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:43:38 -0600 Subject: [PATCH 07/23] Update setup.py --- setup.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index b5c5272..03d996f 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,18 @@ -from setuptools import setup # Prefer setuptools over distutils +import os +from setuptools import setup + +# Read version from environment variable, with fallback to default version +version = os.environ.get('PACKAGE_VERSION', '1.0.0') setup( name='str2bool3', - packages=['str2bool3'], - version='1.0.0', + packages=['str2bool3'], + version=version, description='Convert string to boolean (Forked from SymonSoft/str2bool)', - author='Sam Fakhreddine', - author_email='sam.fakhreddine@gmail.com', + author='Your Name', + author_email='your.email@example.com', url='https://github.com/sam-fakhreddine/str2bool3', - download_url='https://github.com/sam-fakhreddine/str2bool3/archive/refs/tags/1.0.0.tar.gz', + download_url=f'https://github.com/sam-fakhreddine/str2bool3/archive/refs/tags/{version}.tar.gz', keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false'], classifiers=[ 'Development Status :: 5 - Production/Stable', From 1f2e4c354b91a7a689aba5131ebffb203cd0ea4b Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:44:40 -0600 Subject: [PATCH 08/23] Update workflows.yml --- .github/workflows/workflows.yml | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.github/workflows/workflows.yml b/.github/workflows/workflows.yml index 8b13789..b09c884 100644 --- a/.github/workflows/workflows.yml +++ b/.github/workflows/workflows.yml @@ -1 +1,55 @@ +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI + +on: + push: + tags: + - '*' + +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Extract version from git tag + run: echo "PACKAGE_VERSION=${{GITHUB_REF#refs/tags/}}" >> $GITHUB_ENV + + - name: Install pypa/build + run: python3 -m pip install build --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v2 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: Publish Python 🐍 distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags/') + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/str2bool3 + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v2 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} From 1d49df7bd7e1528a302fe935147df6c15292e2ac Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:53:11 -0600 Subject: [PATCH 09/23] Update workflows.yml --- .github/workflows/workflows.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflows.yml b/.github/workflows/workflows.yml index b09c884..80271a2 100644 --- a/.github/workflows/workflows.yml +++ b/.github/workflows/workflows.yml @@ -17,7 +17,8 @@ jobs: python-version: '3.x' - name: Extract version from git tag - run: echo "PACKAGE_VERSION=${{GITHUB_REF#refs/tags/}}" >> $GITHUB_ENV + run: echo "PACKAGE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + - name: Install pypa/build run: python3 -m pip install build --user From 1dc5ffe3680a666ccabb72207eaddfd793558138 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:57:00 -0600 Subject: [PATCH 10/23] Create __init__.py --- str2bool3/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 str2bool3/__init__.py diff --git a/str2bool3/__init__.py b/str2bool3/__init__.py new file mode 100644 index 0000000..4b90f67 --- /dev/null +++ b/str2bool3/__init__.py @@ -0,0 +1,22 @@ +from typing import Union + +# Refactored Python 3.9 compatible code for string to boolean conversion + +def str2bool(value: Union[str, None], raise_exc: bool = False) -> Union[bool, None]: + true_set = {'yes', 'true', 't', 'y', '1'} + false_set = {'no', 'false', 'f', 'n', '0'} + + if isinstance(value, str): + value = value.lower() + if value in true_set: + return True + if value in false_set: + return False + + if raise_exc: + raise ValueError(f'Expected one of: {", ".join(true_set | false_set)}') + + return None + +def str2bool_exc(value: Union[str, None]) -> bool: + return str2bool(value, raise_exc=True) From 33e9481c33c90a91905b0206cc914d1776cd0cd2 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:57:20 -0600 Subject: [PATCH 11/23] Delete str2bool directory --- str2bool/__init__.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 str2bool/__init__.py diff --git a/str2bool/__init__.py b/str2bool/__init__.py deleted file mode 100644 index 41b968e..0000000 --- a/str2bool/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -from typing import Union - -# Refactored Python 3.9 compatible code for string to boolean conversion - -def str2bool(value: Union[str, None], raise_exc: bool = False) -> Union[bool, None]: - true_set = {'yes', 'true', 't', 'y', '1'} - false_set = {'no', 'false', 'f', 'n', '0'} - - if isinstance(value, str): - value = value.lower() - if value in true_set: - return True - if value in false_set: - return False - - if raise_exc: - raise ValueError(f'Expected one of: {", ".join(true_set | false_set)}') - - return None - -def str2bool_exc(value: Union[str, None]) -> bool: - return str2bool(value, raise_exc=True) From 85888e79f876d94f4b2f48a797075a01e8cef09c Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:58:19 -0600 Subject: [PATCH 12/23] Update setup.cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index a2f3748..20ce750 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -description-file = README.md \ No newline at end of file +description_file = README.md From 6ab0d87d6aed48b0919c29f8fa8d5fcaf1fac2d0 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 14:59:16 -0600 Subject: [PATCH 13/23] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 001f470..6561d2b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# str2bool v.1.1 +# str2bool3 v1.0.0 ## About Convert string to boolean. @@ -7,14 +7,16 @@ Case insensitive. ## Installation - $ pip install str2bool + $ pip install str2bool3 ## Examples Here's a basic example: - >>> from str2bool import str2bool - >>> print(str2bool('Yes')) + >>> from str2bool3 import str2bool3 + >>> print(str2bool3('Yes')) True ## License BSD + +forked from symonsoft/str2bool From f3fc1893a5a5a0d27e073365195289fe727a4d7e Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 15:07:55 -0600 Subject: [PATCH 14/23] Update setup.py --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 03d996f..863ebe8 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,9 @@ # Read version from environment variable, with fallback to default version version = os.environ.get('PACKAGE_VERSION', '1.0.0') - +with open("README.md", "r", encoding="utf-8") as f: + long_description = f.read() + setup( name='str2bool3', packages=['str2bool3'], @@ -12,6 +14,8 @@ author='Your Name', author_email='your.email@example.com', url='https://github.com/sam-fakhreddine/str2bool3', + long_description=long_description, + long_description_content_type='text/markdown', download_url=f'https://github.com/sam-fakhreddine/str2bool3/archive/refs/tags/{version}.tar.gz', keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false'], classifiers=[ From 8f995ff6c40845cf877fd391e51a557bcb545092 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 15:08:47 -0600 Subject: [PATCH 15/23] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 863ebe8..9e88387 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ version=version, description='Convert string to boolean (Forked from SymonSoft/str2bool)', author='Your Name', - author_email='your.email@example.com', + author_email='sam.fakhreddine@gmail.com', url='https://github.com/sam-fakhreddine/str2bool3', long_description=long_description, long_description_content_type='text/markdown', From 3d3389b2ec72f12d5a4fbc2b89e2922307a2509c Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 15:46:59 -0600 Subject: [PATCH 16/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6561d2b..dcaca9d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Case insensitive. ## Examples Here's a basic example: - >>> from str2bool3 import str2bool3 + >>> from str2bool3 import str2bool >>> print(str2bool3('Yes')) True From 963fc48f2bedc45012edf61c71e21c8df8306d3b Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 15:47:53 -0600 Subject: [PATCH 17/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dcaca9d..deb0925 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Case insensitive. Here's a basic example: >>> from str2bool3 import str2bool - >>> print(str2bool3('Yes')) + >>> print(str2bool('Yes')) True ## License From 297b40133a5720349fe057e349c9efb28b55cd47 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Tue, 17 Oct 2023 16:08:11 -0600 Subject: [PATCH 18/23] fixed some typos --- .github/workflows/workflows.yml | 3 --- setup.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/workflows.yml b/.github/workflows/workflows.yml index 80271a2..f6d5a4b 100644 --- a/.github/workflows/workflows.yml +++ b/.github/workflows/workflows.yml @@ -15,11 +15,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: '3.x' - - name: Extract version from git tag run: echo "PACKAGE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV - - - name: Install pypa/build run: python3 -m pip install build --user - name: Build a binary wheel and a source tarball diff --git a/setup.py b/setup.py index 9e88387..573f603 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ packages=['str2bool3'], version=version, description='Convert string to boolean (Forked from SymonSoft/str2bool)', - author='Your Name', + author='Sam Fakhreddine', author_email='sam.fakhreddine@gmail.com', url='https://github.com/sam-fakhreddine/str2bool3', long_description=long_description, From 1e03f3442b13ddf7f91cb139440554323a17cd1a Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Thu, 29 Aug 2024 18:47:40 -0600 Subject: [PATCH 19/23] Update __init__.py --- str2bool3/__init__.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/str2bool3/__init__.py b/str2bool3/__init__.py index 4b90f67..0897d21 100644 --- a/str2bool3/__init__.py +++ b/str2bool3/__init__.py @@ -1,22 +1,26 @@ -from typing import Union +from typing import Optional -# Refactored Python 3.9 compatible code for string to boolean conversion +class StrUtils: + TRUE_SET = {'yes', 'true', 't', 'y', '1'} + FALSE_SET = {'no', 'false', 'f', 'n', '0'} + + @staticmethod + def str2bool(value: Optional[str], raise_exc: bool = False, default: Optional[bool] = None) -> Optional[bool]: + if value is None: + return default -def str2bool(value: Union[str, None], raise_exc: bool = False) -> Union[bool, None]: - true_set = {'yes', 'true', 't', 'y', '1'} - false_set = {'no', 'false', 'f', 'n', '0'} - - if isinstance(value, str): value = value.lower() - if value in true_set: + if value in StrUtils.TRUE_SET: return True - if value in false_set: + if value in StrUtils.FALSE_SET: return False - - if raise_exc: - raise ValueError(f'Expected one of: {", ".join(true_set | false_set)}') - - return None -def str2bool_exc(value: Union[str, None]) -> bool: - return str2bool(value, raise_exc=True) + if raise_exc: + valid_values = ', '.join(sorted(StrUtils.TRUE_SET | StrUtils.FALSE_SET)) + raise ValueError(f"Invalid value '{value}'. Expected one of: {valid_values}.") + + return default + + @staticmethod + def str2bool_exc(value: Optional[str]) -> bool: + return StrUtils.str2bool(value, raise_exc=True) From e2d5425291a773d0cdeeac8d1163c92407b5ac78 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Thu, 29 Aug 2024 18:48:34 -0600 Subject: [PATCH 20/23] Update README.md --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index deb0925..6b1433a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # str2bool3 v1.0.0 ## About -Convert string to boolean. -Library recognizes "yes", "true", "y", "t", "1" as True, and "no", "false", "n", "f", "0" as False. +Convert string to boolean. +The library recognizes "yes", "true", "y", "t", "1" as True, and "no", "false", "n", "f", "0" as False. Case insensitive. ## Installation @@ -12,11 +12,17 @@ Case insensitive. ## Examples Here's a basic example: - >>> from str2bool3 import str2bool - >>> print(str2bool('Yes')) + >>> from str2bool3 import StrUtils + >>> print(StrUtils.str2bool('Yes')) True +To raise an exception on invalid input: + + >>> from str2bool3 import StrUtils + >>> StrUtils.str2bool_exc('invalid') + ValueError: Invalid value 'invalid'. Expected one of: false, f, n, no, t, true, y, yes, 0, 1. + ## License BSD -forked from symonsoft/str2bool +Forked from symonsoft/str2bool From 7034208b9d3543c94204c1d50f270586bb165a95 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Thu, 29 Aug 2024 18:50:54 -0600 Subject: [PATCH 21/23] Update __init__.py --- str2bool3/__init__.py | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/str2bool3/__init__.py b/str2bool3/__init__.py index 0897d21..1b01fea 100644 --- a/str2bool3/__init__.py +++ b/str2bool3/__init__.py @@ -1,26 +1 @@ -from typing import Optional - -class StrUtils: - TRUE_SET = {'yes', 'true', 't', 'y', '1'} - FALSE_SET = {'no', 'false', 'f', 'n', '0'} - - @staticmethod - def str2bool(value: Optional[str], raise_exc: bool = False, default: Optional[bool] = None) -> Optional[bool]: - if value is None: - return default - - value = value.lower() - if value in StrUtils.TRUE_SET: - return True - if value in StrUtils.FALSE_SET: - return False - - if raise_exc: - valid_values = ', '.join(sorted(StrUtils.TRUE_SET | StrUtils.FALSE_SET)) - raise ValueError(f"Invalid value '{value}'. Expected one of: {valid_values}.") - - return default - - @staticmethod - def str2bool_exc(value: Optional[str]) -> bool: - return StrUtils.str2bool(value, raise_exc=True) +from .str_utils import str2bool, str2bool_exc From a043350545aa2c1c3a78f8098f7d358cd869190a Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Thu, 29 Aug 2024 18:51:47 -0600 Subject: [PATCH 22/23] Create str_utils.py --- str2bool3/str_utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 str2bool3/str_utils.py diff --git a/str2bool3/str_utils.py b/str2bool3/str_utils.py new file mode 100644 index 0000000..5c5a769 --- /dev/null +++ b/str2bool3/str_utils.py @@ -0,0 +1,23 @@ +from typing import Optional + +TRUE_SET = {'yes', 'true', 't', 'y', '1'} +FALSE_SET = {'no', 'false', 'f', 'n', '0'} + +def str2bool(value: Optional[str], raise_exc: bool = False, default: Optional[bool] = None) -> Optional[bool]: + if value is None: + return default + + value = value.lower() + if value in TRUE_SET: + return True + if value in FALSE_SET: + return False + + if raise_exc: + valid_values = ', '.join(sorted(TRUE_SET | FALSE_SET)) + raise ValueError(f"Invalid value '{value}'. Expected one of: {valid_values}.") + + return default + +def str2bool_exc(value: Optional[str]) -> bool: + return str2bool(value, raise_exc=True) From 0ad4bb50ae798c46cdba6cf6aa17d2769e925c41 Mon Sep 17 00:00:00 2001 From: Sam Fakhreddine Date: Thu, 29 Aug 2024 19:06:31 -0600 Subject: [PATCH 23/23] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 573f603..2a88dde 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup # Read version from environment variable, with fallback to default version -version = os.environ.get('PACKAGE_VERSION', '1.0.0') +version = os.environ.get('PACKAGE_VERSION', '1.3.0') with open("README.md", "r", encoding="utf-8") as f: long_description = f.read()