Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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_name }}" >> $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 }}

20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# str2bool v.1.1
# 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

$ pip install str2bool
$ pip install str2bool3

## Examples
Here's a basic example:

>>> from str2bool 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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
36 changes: 22 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
from distutils.core import setup

import os
from setuptools import setup

# Read version from environment variable, with fallback to default version
version = os.environ.get('PACKAGE_VERSION', '1.3.0')
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()

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',
name='str2bool3',
packages=['str2bool3'],
version=version,
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',
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=[
'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'
],
)
21 changes: 0 additions & 21 deletions str2bool/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions str2bool3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .str_utils import str2bool, str2bool_exc
23 changes: 23 additions & 0 deletions str2bool3/str_utils.py
Original file line number Diff line number Diff line change
@@ -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)