Skip to content

Commit

Permalink
Merge pull request #142 from Callum027/python-3.12
Browse files Browse the repository at this point in the history
Add Python 3.10 and 3.12 support
  • Loading branch information
tobias-urdin authored Aug 20, 2024
2 parents ee93722 + 24818b0 commit a7f9e4e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
22 changes: 22 additions & 0 deletions gnocchiclient/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,25 @@ def parse_date(s):

def dt_to_localtz(d):
return d.astimezone(LOCAL_TIMEZONE)


def str_to_bool(val):
"""Convert a string representation of truth to ``True`` or ``False``.
``True`` values are ``y``, ``yes``, ``t``, ``true``, ``on``, and ``1``.
``False`` values are ``n``, ``no``, ``f``, ``false``, ``off``, and ``0``.
:param val: Value to convert to a boolean.
:type val: str
:raises ValueError: If ``val`` is anything other than the allowed values.
:return: ``True`` if the value is a truthy value, otherwise ``False``.
:rtype: bool
"""
val = str(val).lower()

if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError(f"Invalid truth value {val!r}")
4 changes: 1 addition & 3 deletions gnocchiclient/v1/resource_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import distutils.util

from cliff import command
from cliff import lister
from cliff import show
Expand Down Expand Up @@ -174,7 +172,7 @@ def _resource_from_args(self, parsed_args, update=False):
if attr_type == "number":
value = float(value)
elif attr_type == "bool":
value = bool(distutils.util.strtobool(value))
value = utils.str_to_bool(value)
resource[attr] = value
if (parsed_args.add_metric or
parsed_args.create_metric or
Expand Down
4 changes: 1 addition & 3 deletions gnocchiclient/v1/resource_type_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import distutils.util

from cliff import command
from cliff import lister
from cliff import show
Expand Down Expand Up @@ -60,7 +58,7 @@ def _resource_attribute(cls, value):
if config:
attrs["type"] = config.pop(0)
if config:
attrs["required"] = bool(distutils.util.strtobool(config.pop(0)))
attrs["required"] = utils.str_to_bool(config.pop(0))
while config:
param, _, value = config.pop(0).partition("=")
opts = attrs
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ classifier =
Programming Language :: Python :: 3 :: Only
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

[options]
packages =
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 3.1
envlist = py38,py39,py311,pep8,docs-gnocchi-web
envlist = py38,py39,py310,py311,py312,pep8,docs-gnocchi-web
skipsdist = True

[testenv]
Expand Down Expand Up @@ -48,7 +48,7 @@ commands =

[flake8]
show-source = True
ignore = D100,D101,D102,D103,D104,D105,D107,A002,A003,W504
ignore = D100,D101,D102,D103,D104,D105,D107,A002,A003,A005,W504
exclude=.git,.tox,dist,doc,*egg,build
enable-extensions=G
application-import-names = gnocchiclient
Expand Down

0 comments on commit a7f9e4e

Please sign in to comment.