Skip to content

Commit

Permalink
Merge pull request #121 from Jylpah/dev-1.0
Browse files Browse the repository at this point in the history
version 1.3
  • Loading branch information
Jylpah authored Feb 23, 2025
2 parents ea799ba + dcad0b0 commit a2ac040
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package-macos-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.11", "3.12"]
python-version: [ "3.11", "3.12", "3.13"]
os: [ windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.11", "3.12"]
python-version: [ "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyutils"
version = "1.2.3"
version = "1.3"
authors = [{ name = "Jylpah", email = "[email protected]" }]
description = "Misc Python utils and classes"
readme = "README.md"
Expand Down Expand Up @@ -66,7 +66,7 @@ include = ["pyproject.toml", "src/**/*.py", "tests/**/*.py"]
indent-width = 4
extend-include = ["*.ipynb"]
extend-exclude = [".venv", ".vscode" ]
fixable = ["ALL"]
lint.fixable = ["ALL"]

[tool.pytest.ini_options]
minversion = "7.4"
Expand All @@ -75,7 +75,10 @@ pythonpath = "src" # avoid import path append in test files
filterwarnings = [
'ignore:Inheritance class ThrottledClientSession from ClientSession is discouraged:DeprecationWarning',
]
asyncio_default_fixture_loop_scope = "function"


[tool.pyright]
reportGeneralTypeIssues = false
reportInvalidStringEscapeSequence = false
typeCheckingMode = "off"
6 changes: 6 additions & 0 deletions src/pyutils/asyncqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import logging
from asyncio import sleep

from deprecated import deprecated

T = TypeVar("T")

logger = logging.getLogger(__name__)
Expand All @@ -15,6 +17,10 @@
error = logger.error


@deprecated(
version="1.3",
reason="Please use queutils.AsyncQueue instead, will be removed in 1.4",
)
class AsyncQueue(asyncio.Queue, Generic[T]):
"""Async wrapper/interface for non-async queue.Queue."""

Expand Down
10 changes: 10 additions & 0 deletions src/pyutils/counterqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .utils import Countable
import logging

from deprecated import deprecated

logger = logging.getLogger()
error = logger.error
message = logger.warning
Expand All @@ -17,6 +19,10 @@
T = TypeVar("T")


@deprecated(
version="1.3",
reason="Please use queutils.CounterQueue instead, will be removed in 1.4, will be removed in 1.4",
)
class CounterQueue(Queue[T], Countable):
_counter: int
_count_items: bool
Expand Down Expand Up @@ -47,6 +53,10 @@ def count_items(self) -> bool:
return self._count_items


@deprecated(
version="1.3",
reason="Please use queutils.CounterQueue instead, will be removed in 1.4, will be removed in 1.4",
)
class QCounter:
def __init__(self, Q: Queue[int]):
self._count = 0
Expand Down
18 changes: 7 additions & 11 deletions src/pyutils/eventcounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
assert errors is not None, "param 'errors' cannot be None"

self.name: str = name
self._log: defaultdict[str, int] = defaultdict(self._def_value_zero)
self._log: defaultdict[str, int] = defaultdict(int)
self._error_cats: list[str] = errors
self._error_status: bool = False
self._totals = totals
Expand All @@ -54,10 +54,6 @@ def __init__(
for cat in categories:
self.log(cat, 0)

@classmethod
def _def_value_zero(cls) -> int:
return 0

def add_error_categories(self, errors: list[str] = list()) -> bool:
"""Add error categories and return if an error has been logged"""
self._error_cats += errors
Expand Down Expand Up @@ -115,9 +111,9 @@ def get_error_status(self) -> bool:

def merge(self, B: "EventCounter") -> bool:
"""Merge two EventCounter instances together"""
assert isinstance(
B, EventCounter
), f"input is not type of 'EventCounter' but: {type(B)}"
assert isinstance(B, EventCounter), (
f"input is not type of 'EventCounter' but: {type(B)}"
)

try:
if not isinstance(B, EventCounter):
Expand All @@ -136,9 +132,9 @@ def merge(self, B: "EventCounter") -> bool:

def merge_child(self, B: "EventCounter") -> bool:
"""Merge two EventCounter instances together"""
assert isinstance(
B, EventCounter
), f"input is not type of 'EventCounter' but: {type(B)}"
assert isinstance(B, EventCounter), (
f"input is not type of 'EventCounter' but: {type(B)}"
)

try:
for cat in B.get_categories():
Expand Down
46 changes: 38 additions & 8 deletions src/pyutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,22 @@ def count(self) -> int:


class ClickHelpGen:
"""Helper class to write Markdown docs for a Click CLI program"""
"""
Helper class to write Markdown docs for a Click CLI program
Usage:
from pyutils.utils import ClickHelpGen
from blitzreplays.blitzdata import app as blitzdata
bd = ClickHelpGen(blitzdata, "blitz-data")
bd.add_command(["tankopedia"])
bd.add_command(["tankopedia", "wg"])
bd.add_command(["tankopedia", "app"])
bd.add_command(["maps"])
bd.add_command(["maps", "app"])
print(bd.mk_docs())
"""

def __init__(self, cli: BaseCommand, name: str):
self.cli: BaseCommand = cli
Expand Down Expand Up @@ -82,7 +97,22 @@ def mk_docs(self) -> str:


class TyperHelpGen:
"""Helper class to write Markdown docs for a Click CLI program"""
"""
Helper class to write Markdown docs for a Click CLI program
Usage:
from pyutils.utils import TyperHelpGen
from blitzreplays.blitzdata import app as blitzdata
bd = TyperHelpGen(blitzdata, "blitz-data")
bd.add_command(["tankopedia"])
bd.add_command(["tankopedia", "wg"])
bd.add_command(["tankopedia", "app"])
bd.add_command(["maps"])
bd.add_command(["maps", "app"])
print(bd.mk_docs())
"""

def __init__(self, app: Typer, name: str):
self.app: Typer = app
Expand Down Expand Up @@ -341,11 +371,11 @@ def set_config(
section: str,
option: str,
value: str | int | float | bool | None = None,
) -> T:
) -> T | None:
"""Helper for setting ConfigParser config params"""
assert isinstance(
config, ConfigParser
), "config argument has to be instance of ConfigParser"
assert isinstance(config, ConfigParser), (
"config argument has to be instance of ConfigParser"
)
# opt_type: str | int | float | bool = str
# if fallback is not None:
# opt_type = type(fallback)
Expand All @@ -370,9 +400,9 @@ def set_config(
return config.get(section, option) # type: ignore


def add_suffix(path : Path, suffix: str) -> Path:
def add_suffix(path: Path, suffix: str) -> Path:
"""add suffix if it does not exists. Does not replace the suffix"""
if path.suffix == suffix:
return path
else:
return path.parent / (path.name + suffix)
return path.parent / (path.name + suffix)

0 comments on commit a2ac040

Please sign in to comment.