Skip to content

Commit

Permalink
Merge branch '1.4.x' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
takos22 committed Feb 21, 2024
2 parents 517c9c9 + 3848d51 commit a4f585f
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
21 changes: 21 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.9"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# We recommend specifying your dependencies to enable reproducible builds:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
25 changes: 24 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ The format is based on
`Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`__, and this project
adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`__.

Version 1.4.3 (2024-02-21)
--------------------------

Changed
*******

- Every `datetime.date <https://docs.python.org/library/datetime.html#datetime.date>`__ is now timezone aware, using the CodinGame
timezone (UTC).
- `ClashOfCode.creation_time <https://codingame.readthedocs.io/en/latest/api.html#codingame.ClashOfCode.creation_time>`__ can be ``None`` because of an API change
by CodinGame.

Fixed
*****

- `KeyError <https://docs.python.org/library/exceptions.html#KeyError>`__ was raised when using `Client.get_clash_of_code <https://codingame.readthedocs.io/en/latest/api.html#codingame.Client.get_clash_of_code>`__ because
of an API change by CodinGame.

Removed
*******

- Removed support for python 3.7 as it has reached its end of life. For more
information, see `PEP 537 <https://peps.python.org/pep-0537/#lifespan>`__.

Version 1.4.2 (2023-04-14)
--------------------------

Expand Down Expand Up @@ -66,7 +89,7 @@ Changed
Removed
*******

- Removed `Notification._raw`.
- Removed ``Notification._raw``.

Version 1.2.4 (2022-06-17)
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Pythonic wrapper for the undocumented `CodinGame <https://www.codingame.com/>`_
Installation
------------

**Python 3.7 or higher is required.**
**Python 3.8 or higher is required.**

Install ``codingame`` with pip:

Expand Down
4 changes: 2 additions & 2 deletions codingame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"VersionInfo", major=int, minor=int, micro=int, releaselevel=str, serial=int
)

version_info = VersionInfo(major=1, minor=4, micro=2, releaselevel="", serial=0)
version_info = VersionInfo(major=1, minor=4, micro=3, releaselevel="", serial=0)

__title__ = "codingame"
__author__ = "takos22"
__version__ = "1.4.2"
__version__ = "1.4.3"

from .clash_of_code import ClashOfCode, Player
from .client import Client
Expand Down
11 changes: 6 additions & 5 deletions codingame/clash_of_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class ClashOfCode(BaseObject):
mode: Optional :class:`str`
The mode of the Clash of Code.
creation_time: :class:`~datetime.datetime`
creation_time: Optional :class:`~datetime.datetime`
Creation time of the Clash of Code.
Doesn't always exist.
start_time: :class:`~datetime.datetime`
Start time of the Clash of Code. If the Clash of Code hasn't started
Expand Down Expand Up @@ -88,7 +89,7 @@ class ClashOfCode(BaseObject):
started: bool
finished: bool
mode: Optional[Mode]
creation_time: datetime
creation_time: Optional[datetime]
start_time: datetime
end_time: Optional[datetime]
time_before_start: timedelta
Expand Down Expand Up @@ -125,7 +126,7 @@ def _set_data(self, data: ClashOfCodeDict):
f"https://www.codingame.com/clashofcode/clash/{self.public_handle}",
)

self._setattr("public", data["publicClash"])
self._setattr("public", data.get("type", "PUBLIC") == "PUBLIC")
self._setattr("min_players", data["nbPlayersMin"])
self._setattr("max_players", data["nbPlayersMax"])
self._setattr("modes", data.get("modes"))
Expand All @@ -135,8 +136,8 @@ def _set_data(self, data: ClashOfCodeDict):
self._setattr("finished", data["finished"])
self._setattr("mode", data.get("mode"))

self._setattr("creation_time", to_datetime(data["creationTime"]))
self._setattr("start_time", to_datetime(data.get("startTime")))
self._setattr("creation_time", to_datetime(data.get("creationTime")))
self._setattr("start_time", to_datetime(data.get("startTimestamp")))
self._setattr("end_time", to_datetime(data.get("endTime")))

self._setattr(
Expand Down
7 changes: 1 addition & 6 deletions codingame/types/clash_of_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
Typings for the `ClashOfCode/` endpoints of the CodinGame API.
"""

from typing import List, Optional

try:
from typing import Literal, TypedDict
except ImportError:
from typing_extensions import Literal, TypedDict
from typing import List, Literal, Optional, TypedDict

from .codingamer import PartialCodinGamer

Expand Down
7 changes: 1 addition & 6 deletions codingame/types/codingamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
Typings for the `CodinGamer/` endpoints of the CodinGame API.
"""

from typing import Dict, List, Optional

try:
from typing import Literal, TypedDict
except ImportError:
from typing_extensions import Literal, TypedDict
from typing import Dict, List, Literal, Optional, TypedDict

__all__ = (
"PartialCodinGamer",
Expand Down
6 changes: 3 additions & 3 deletions codingame/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import typing
from datetime import datetime
from datetime import datetime, timezone

from .exceptions import LoginRequired

Expand Down Expand Up @@ -103,8 +103,8 @@ def validate_leaderboard_group(group: str, logged_in: bool) -> str:

def to_datetime(data: typing.Optional[typing.Union[int, str]]) -> datetime:
if isinstance(data, int):
return datetime.utcfromtimestamp(data / 1000.0)
elif isinstance(data, str):
return datetime.fromtimestamp(data / 1000.0, timezone.utc)
elif isinstance(data, str): # pragma: no cover
try:
return datetime.strptime(data, DT_FORMAT_1)
except ValueError:
Expand Down
19 changes: 9 additions & 10 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
autoflake~=1.4
autoflake~=2.3
black~=22.6
doc8~=0.9
flake8~=3.9
importlib-metadata~=4.13
isort~=5.8
pytest~=6.2
doc8~=1.1
flake8~=7.0
isort~=5.13
pytest~=7.4
pytest-asyncio~=0.16.0
pytest-cov~=2.12
pytest-cov~=4.1
pytest-mock~=3.6
python-dotenv~=0.17.1
requests
twine
python-dotenv~=1.0
setuptools~=69.1
twine~=5.0
25 changes: 24 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ The format is based on
`Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`__, and this project
adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`__.

Version 1.4.3 (2024-02-21)
--------------------------

Changed
*******

- Every :class:`datetime.datetime` is now timezone aware, using the CodinGame
timezone (UTC).
- :attr:`ClashOfCode.creation_time` can be ``None`` because of an API change
by CodinGame.

Fixed
*****

- :exc:`KeyError` was raised when using :meth:`Client.get_clash_of_code` because
of an API change by CodinGame.

Removed
*******

- Removed support for python 3.7 as it has reached its end of life. For more
information, see `PEP 537 <https://peps.python.org/pep-0537/#lifespan>`__.

Version 1.4.2 (2023-04-14)
--------------------------

Expand Down Expand Up @@ -68,7 +91,7 @@ Changed
Removed
*******

- Removed `Notification._raw`.
- Removed ``Notification._raw``.

Version 1.2.4 (2022-06-17)
--------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# requirements for building the docs
sphinx~=3.1
furo<=2021.06.18.beta36 # sphinx==3 compatibility
sphinx~=5.0
furo
sphinx-inline-tabs
sphinx-copybutton
sphinx-notfound-page
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is the documentation for the ``codingame`` module.
Prerequisites
-------------

**Python 3.7 or higher is required.**
**Python 3.8 or higher is required.**


.. _installing:
Expand Down
8 changes: 4 additions & 4 deletions scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ folders="codingame tests examples docs setup.py"
set -x

# put every import on one line for autoflake remove unused imports
isort $folders --force-single-line-imports
python3 -m isort $folders --force-single-line-imports
# remove unused imports and variables
autoflake $folders --remove-all-unused-imports --recursive --remove-unused-variables --in-place --exclude=__init__.py
python3 -m autoflake $folders --remove-all-unused-imports --recursive --remove-unused-variables --in-place --exclude=__init__.py
# resort imports
isort $folders
python3 -m isort $folders

# format code
black $folders --line-length 80
python3 -m black $folders --line-length 80
4 changes: 2 additions & 2 deletions scripts/full-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
set -e
set -x

pytest --only-mocked --overwrite-environ
pytest --no-mocking --cov-append
python3 -m pytest --only-mocked --overwrite-environ
python3 -m pytest --no-mocking --cov-append
8 changes: 4 additions & 4 deletions scripts/lint-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ folders="codingame tests examples docs setup.py"
set -x

# stop the build if there are Python syntax errors or undefined names
flake8 $folders --count --select=E9,F63,F7,F82 --show-source --statistics
python3 -m flake8 $folders --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings
flake8 $folders --count --exit-zero --statistics
python3 -m flake8 $folders --count --exit-zero --statistics

# check formatting with black
black $folders --check --line-length 80
python3 -m black $folders --check --line-length 80

# check import ordering with isort
isort $folders --check-only
python3 -m isort $folders --check-only
4 changes: 2 additions & 2 deletions scripts/lint-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ folders="docs"
set -x

# check the docs with doc8
doc8 $folders --quiet
python3 -m doc8 $folders --quiet

# check package build for README.rst
rm -rf dist
python3 setup.py --quiet sdist
twine check dist/*
python3 -m twine check dist/*
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ if [ "$full" = true ]; then
./scripts/full-test.sh
else
set -x
pytest
python3 -m pytest
fi
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_requirements(filename: str = "requirements.txt") -> typing.List[str]:
author="takos22",
author_email="takos2210@gmail.com",
packages=get_packages("codingame"),
python_requires=">=3.7",
python_requires=">=3.8",
install_requires=get_requirements(),
extras_require=extra_requires,
project_urls={
Expand All @@ -76,9 +76,10 @@ def get_requirements(filename: str = "requirements.txt") -> typing.List[str]:
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"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",
],
)
4 changes: 2 additions & 2 deletions tests/async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async def test_client_mark_notifications_as_seen(
mock_http(
auth_client._state.http,
"mark_notifications_as_seen",
int(datetime.datetime.utcnow().timestamp() * 1000),
int(datetime.datetime.now(datetime.timezone.utc).timestamp() * 1000),
)
seen_date = await auth_client.mark_notifications_as_seen(
[notification, notification.id]
Expand All @@ -394,7 +394,7 @@ async def test_client_mark_notifications_as_seen(
assert notification.seen
assert notification.seen_date == seen_date
assert notification.seen_date.timestamp() == pytest.approx(
datetime.datetime.utcnow().timestamp(), abs=10_000
datetime.datetime.now(datetime.timezone.utc).timestamp(), abs=10_000
) # 10 seconds should be enough


Expand Down
8 changes: 4 additions & 4 deletions tests/async/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ async def test_client_notification_mark_as_seen(
mock_http(
auth_client._state.http,
"mark_notifications_as_seen",
int(datetime.datetime.utcnow().timestamp() * 1000),
int(datetime.datetime.now(datetime.timezone.utc).timestamp() * 1000),
)
seen_date = await notification.mark_as_seen()

assert notification.seen
assert notification.seen_date == seen_date
assert notification.seen_date.timestamp() == pytest.approx(
datetime.datetime.utcnow().timestamp(), abs=10_000
datetime.datetime.now(datetime.timezone.utc).timestamp(), abs=10_000
) # 10 seconds should be enough


Expand All @@ -47,12 +47,12 @@ async def test_client_notification_mark_as_read(
mock_http(
auth_client._state.http,
"mark_notifications_as_read",
int(datetime.datetime.utcnow().timestamp() * 1000),
int(datetime.datetime.now(datetime.timezone.utc).timestamp() * 1000),
)
read_date = await notification.mark_as_read()

assert notification.read
assert notification.read_date == read_date
assert notification.read_date.timestamp() == pytest.approx(
datetime.datetime.utcnow().timestamp(), abs=10_000
datetime.datetime.now(datetime.timezone.utc).timestamp(), abs=10_000
) # 10 seconds should be enough
Loading

0 comments on commit a4f585f

Please sign in to comment.