Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python 3.12 support #483

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-20.04"]
python: ["3.8", "3.9", "3.10", "3.11.1"]
python: ["3.8", "3.9", "3.10", "3.11.1", "3.12"]
redis: [5, 6, 7, 7.2]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion iredis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def split_command_args(command):

command = command.strip()
for command_name in all_commands:
# for command that is paritaly input, like `command in`, we should
# for command that is partially input, like `command in`, we should
# match with `command info`, otherwise, `command in` will result in
# `command` with `args` is ('in') which is an invalid case.
normalized_input_command = " ".join(command.split()).upper()
Expand Down
17 changes: 9 additions & 8 deletions iredis/completers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from typing import Iterable
from datetime import datetime, timezone

import pendulum
from dateutil.relativedelta import relativedelta
from prompt_toolkit.completion import (
CompleteEvent,
Completer,
Expand Down Expand Up @@ -102,31 +103,31 @@ def _completion_humanize_time(self, document: Document) -> Iterable[Completion]:
if not text.isnumeric():
return
current = int(text)
now = pendulum.now()
now = datetime.now()
for unit, minimum in self.when_lower_than.items():
if current <= minimum:
if self.future_time:
dt = now.add(**{f"{unit}s": current})
dt = now + relativedelta(**{f"{unit}s": current})
offset_text = "later"
else:
dt = now.subtract(**{f"{unit}s": current})
dt = now - relativedelta(**{f"{unit}s": current})
offset_text = "ago"

meta = f"{text} {unit}{'s' if current > 1 else ''} {offset_text} ({dt.format('YYYY-MM-DD HH:mm:ss')})"
meta = f"{text} {unit}{'s' if current > 1 else ''} {offset_text} ({dt.strftime('%Y-%m-%d %H:%M:%S')})"
yield Completion(
str(dt.int_timestamp * self.factor),
str(int(dt.timestamp()) * self.factor),
start_position=-len(document.text_before_cursor),
display_meta=meta,
)

def _completion_formatted_time(self, document: Document) -> Iterable[Completion]:
text = document.text
try:
dt = pendulum.parse(text)
dt = datetime.fromisoformat(text).replace(tzinfo=timezone.utc)
except Exception:
return
yield Completion(
str(dt.int_timestamp * self.factor),
str(int(dt.timestamp()) * self.factor),
start_position=-len(document.text_before_cursor),
display_meta=str(dt),
)
Expand Down
69 changes: 19 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
# "Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.12",
"Topic :: Database",
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
Expand All @@ -36,11 +36,11 @@ Pygments = "^2"
mistune = "^3.0"
configobj = "^5.0"
click = "^8.0"
pendulum = "^2.1.0"
# wcwidth 0.2.x uses pkg_resources which is not supported by PyOxidizer
wcwidth = "0.1.9"
packaging = "^23.0"
redis = "^5.0.0"
python-dateutil = "^2.8.2"

[tool.poetry.dev-dependencies]
pytest = "^7.2"
Expand All @@ -49,6 +49,9 @@ pexpect = "^4.7"
[tool.poetry.scripts]
iredis = 'iredis.entry:main'

[tool.poetry.group.dev.dependencies]
freezegun = "^1.4.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
21 changes: 9 additions & 12 deletions tests/unittests/test_completers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock

import pendulum
from freezegun import freeze_time
from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit.completion import Completion

Expand Down Expand Up @@ -180,9 +180,8 @@ def test_group_completer():
]


@patch("iredis.completers.pendulum.now")
def test_timestamp_completer_humanize_time_completion(fake_now):
fake_now.return_value = pendulum.from_timestamp(1578487013)
@freeze_time("2020-01-08 12:36:53")
def test_timestamp_completer_humanize_time_completion():
c = TimestampCompleter(is_milliseconds=True, future_time=False)

fake_document = MagicMock()
Expand Down Expand Up @@ -260,9 +259,8 @@ def test_timestamp_completer_humanize_time_completion(fake_now):
]


@patch("iredis.completers.pendulum.now")
def test_timestamp_completer_humanize_time_completion_seconds(fake_now):
fake_now.return_value = pendulum.from_timestamp(1578487013)
@freeze_time("2020-01-08 12:36:53")
def test_timestamp_completer_humanize_time_completion_seconds():
c = TimestampCompleter(is_milliseconds=False, future_time=False)

fake_document = MagicMock()
Expand Down Expand Up @@ -297,9 +295,8 @@ def test_timestamp_completer_humanize_time_completion_seconds(fake_now):
]


@patch("iredis.completers.pendulum.now")
def test_timestamp_completer_humanize_time_completion_seconds_future_time(fake_now):
fake_now.return_value = pendulum.from_timestamp(1578487013)
@freeze_time("2020-01-08 12:36:53")
def test_timestamp_completer_humanize_time_completion_seconds_future_time():
c = TimestampCompleter(is_milliseconds=False, future_time=True)

fake_document = MagicMock()
Expand Down Expand Up @@ -350,7 +347,7 @@ def test_timestamp_completer_datetime_format_time_completion():
text="1581033600000",
start_position=-10,
display=FormattedText([("", "1581033600000")]),
display_meta="2020-02-07T00:00:00+00:00",
display_meta="2020-02-07 00:00:00+00:00",
)
]

Expand Down
Loading