Skip to content

Commit

Permalink
Dependencies: Modernize to prepare unlocking more recent Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Nov 6, 2024
1 parent defdbcc commit 3f7db5b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install -r test-requirements.txt
python -m pip install pytest-cov
python -m pip install --editable='.[testing]'
- name: Run tests
run: |
pytest -vvv --cov=croud --cov-report=xml
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Croud
=====

|ci| |coverage| |rtd| |pypi-version|
|ci| |coverage| |rtd| |pypi-version| |python-versions|

|
Expand Down
15 changes: 13 additions & 2 deletions croud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
# with Crate these terms will supersede the license and you may use the
# software solely pursuant to the terms of the relevant commercial agreement.

import pkg_resources
try:
from importlib.metadata import PackageNotFoundError, version
except (ImportError, ModuleNotFoundError): # pragma:nocover
from importlib_metadata import ( # type: ignore[assignment,no-redef,unused-ignore]
PackageNotFoundError,
version,
)

__version__ = pkg_resources.require("croud")[0].version
__appname__ = "croud"

try:
__version__ = version(__appname__)
except PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
10 changes: 5 additions & 5 deletions croud/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# software solely pursuant to the terms of the relevant commercial agreement.

import sys
from distutils.util import strtobool

import colorama
import shtab
Expand Down Expand Up @@ -130,6 +129,7 @@
from croud.tools.spinner import HALO
from croud.users.commands import users_delete, users_list
from croud.users.roles.commands import roles_list
from croud.util import asbool

# Arguments common to all import-job create commands
import_job_create_common_args = [
Expand Down Expand Up @@ -161,7 +161,7 @@
),
Argument(
"--create-table",
type=lambda x: bool(strtobool(str(x))), # noqa
type=lambda x: asbool(x), # noqa
required=False,
help="Whether the table should be created automatically"
" if it does not exist. If true new columns will also be added when the data"
Expand Down Expand Up @@ -592,7 +592,7 @@
help="The CrateDB cluster ID to use.",
),
Argument(
"--value", type=lambda x: bool(strtobool(str(x))),
"--value", type=lambda x: asbool(x),
required=True, help="The deletion protection status",
),
],
Expand Down Expand Up @@ -636,7 +636,7 @@
help="The CrateDB cluster ID to use.",
),
Argument(
"--value", type=lambda x: bool(strtobool(str(x))),
"--value", type=lambda x: asbool(x),
required=True, help="The suspended status.",
),
],
Expand Down Expand Up @@ -891,7 +891,7 @@
"return the files."
),
Argument(
"--summary", type=lambda x: bool(strtobool(str(x))),
"--summary", type=lambda x: asbool(x),
required=False,
help="Show only global progress."
),
Expand Down
24 changes: 23 additions & 1 deletion croud/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import webbrowser
from argparse import Namespace
from datetime import datetime, timezone
from typing import Tuple
from typing import Any, Tuple

from croud.api import Client
from croud.config import CONFIG
Expand Down Expand Up @@ -156,3 +156,25 @@ def _set_gc_jwt(cmd_args: Namespace) -> None:
CONFIG.set_current_gc_jwt_token(data.get("token")) # type: ignore
CONFIG.set_current_gc_cluster_id(cmd_args.cluster_id) # type: ignore
CONFIG.set_current_gc_jwt_token_expiry(data.get("expiry")) # type: ignore


def strtobool(val: str) -> int:
"""Convert a string representation of truth to true (1) or false (0).
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
Copied from `distutils.util.strtobool` (Python 3.11).
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return 1
elif val in ("n", "no", "f", "false", "off", "0"):
return 0
else:
raise ValueError("invalid truth value %r" % (val,))


def asbool(val: Any) -> bool:
return bool(strtobool(str(val)))
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"bitmath==1.3.3.1",
"certifi",
"colorama==0.4.6",
"importlib-metadata; python_version < '3.8'",
"marshmallow==3.22.0",
"pyyaml==6.0.2",
"requests==2.32.3",
Expand All @@ -60,8 +61,11 @@
],
extras_require={
"testing": [
"tox==3.14.2",
"pytest-freezegun==0.4.2",
"pytest<9",
"pytest-cov<7",
"pytest-freezer<0.5",
"pytest-random-order<2",
"tox<4",
],
"development": [
"black==24.8.0",
Expand Down
3 changes: 0 additions & 3 deletions test-requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
envlist = py38,py39,py310,py311

[testenv]
deps = -r{toxinidir}/test-requirements.txt
deps = -e{toxinidir}[testing]
commands = pytest {posargs}
setenv = LANG=en_US.UTF-8

0 comments on commit 3f7db5b

Please sign in to comment.