Skip to content

Commit

Permalink
chore: maintenance in preparation for v2 (#150)
Browse files Browse the repository at this point in the history
* chore: update pre-commit hooks

* fix: makefile branch check platform agnostic

* fix: platform agnostic shell variables; feat: add dry release
  • Loading branch information
NiceAesth committed Jul 18, 2023
1 parent 314aa67 commit 14b3eb6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 39 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.9.0
hooks:
- id: pyupgrade
args: [--py37-plus, --keep-runtime-typing]
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.9.0
rev: v3.10.0
hooks:
- id: reorder-python-imports
args: [--py37-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
rev: v3.0.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.15.0
hooks:
- id: blacken-docs
- repo: https://github.com/hadialqattan/pycln
Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ shell:
poetry shell

release:
@if [ "$(CURRENT_BRANCH)" != "master" ]; then echo "Not on master branch"; exit 1; fi
@poetry version $(ver)
$(if $(filter $(CURRENT_BRANCH),master),,$(error ERR: Not on master branch))
$(eval VERSION := $(shell poetry version $(ver) -s))
@git add pyproject.toml
@git commit -m "v$$(poetry version -s)"
@git tag v$$(poetry version -s)
@git commit -m "v$(VERSION)"
@git tag v$(VERSION)
@git push
@git push --tags
@poetry version

release-dry:
$(if $(filter $(CURRENT_BRANCH),master),,$(warning WARN: Not on master branch))
$(eval VERSION := $(shell poetry version $(ver) -s --dry-run))
@echo "Dry run: git add pyproject.toml"
@echo "Dry run: git tag v$(VERSION)"
@echo "Dry run: git push"
@echo "Dry run: git push --tags"
@echo "Run `make release ver=$(ver)` to release"

lint:
poetry run pre-commit run --all-files
Expand Down
18 changes: 14 additions & 4 deletions aiosu/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ async def __aexit__(
await self.close()

async def _request(
self, request_type: ClientRequestType, *args: Any, **kwargs: Any
self,
request_type: ClientRequestType,
*args: Any,
**kwargs: Any,
) -> Any:
if self._session is None:
self._session = aiohttp.ClientSession()
Expand Down Expand Up @@ -167,7 +170,10 @@ async def get_user(self, user_query: Union[str, int], **kwargs: Any) -> User:
return User._from_api_v1(json[0])

async def __get_type_scores(
self, user_query: Union[str, int], request_type: str, **kwargs: Any
self,
user_query: Union[str, int],
request_type: str,
**kwargs: Any,
) -> list[Score]:
r"""INTERNAL: Get a user's scores by type
Expand Down Expand Up @@ -215,7 +221,9 @@ async def __get_type_scores(
return from_list(score_conv, json)

async def get_user_recents(
self, user_query: Union[str, int], **kwargs: Any
self,
user_query: Union[str, int],
**kwargs: Any,
) -> list[Score]:
r"""Get a user's recent scores.
Expand All @@ -242,7 +250,9 @@ async def get_user_recents(
return await self.__get_type_scores(user_query, "recent", limit=limit, **kwargs)

async def get_user_bests(
self, user_query: Union[str, int], **kwargs: Any
self,
user_query: Union[str, int],
**kwargs: Any,
) -> list[Score]:
r"""Get a user's best scores.
Expand Down
111 changes: 85 additions & 26 deletions aiosu/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ def _refresh_guest_data(self) -> dict[str, Union[str, int]]:
}

async def _request(
self, request_type: ClientRequestType, *args: Any, **kwargs: Any
self,
request_type: ClientRequestType,
*args: Any,
**kwargs: Any,
) -> Any:
await self._prepare_token()

Expand Down Expand Up @@ -509,7 +512,9 @@ async def get_changelog_build(self, stream: str, build: str) -> Build:

@prepare_token
async def lookup_changelog_build(
self, changelog_query: Union[str, int], **kwargs: Any
self,
changelog_query: Union[str, int],
**kwargs: Any,
) -> Build:
r"""Looks up a build from the changelog.
Expand Down Expand Up @@ -573,7 +578,9 @@ async def get_news_listing(self, **kwargs: Any) -> NewsListing:

@prepare_token
async def get_news_post(
self, news_query: Union[str, int], **kwargs: Any
self,
news_query: Union[str, int],
**kwargs: Any,
) -> NewsPost:
r"""Gets a news post.
Expand Down Expand Up @@ -835,7 +842,10 @@ async def get_user_kudosu(self, user_id: int, **kwargs: Any) -> list[KudosuHisto
@check_token
@requires_scope(Scopes.PUBLIC)
async def __get_type_scores(
self, user_id: int, request_type: str, **kwargs: Any
self,
user_id: int,
request_type: str,
**kwargs: Any,
) -> list[Union[Score, LazerScore]]:
r"""INTERNAL: Get a user's scores by type
Expand Down Expand Up @@ -887,7 +897,9 @@ async def __get_type_scores(
return from_list(Score.parse_obj, json)

async def get_user_recents(
self, user_id: int, **kwargs: Any
self,
user_id: int,
**kwargs: Any,
) -> list[Union[Score, LazerScore]]:
r"""Get a user's recent scores.
Expand Down Expand Up @@ -915,7 +927,9 @@ async def get_user_recents(
return await self.__get_type_scores(user_id, "recent", **kwargs)

async def get_user_bests(
self, user_id: int, **kwargs: Any
self,
user_id: int,
**kwargs: Any,
) -> list[Union[Score, LazerScore]]:
r"""Get a user's top scores.
Expand All @@ -941,7 +955,9 @@ async def get_user_bests(
return await self.__get_type_scores(user_id, "best", **kwargs)

async def get_user_firsts(
self, user_id: int, **kwargs: Any
self,
user_id: int,
**kwargs: Any,
) -> list[Union[Score, LazerScore]]:
r"""Get a user's first place scores.
Expand All @@ -967,7 +983,9 @@ async def get_user_firsts(
return await self.__get_type_scores(user_id, "firsts", **kwargs)

async def get_user_pinned(
self, user_id: int, **kwargs: Any
self,
user_id: int,
**kwargs: Any,
) -> list[Union[Score, LazerScore]]:
r"""Get a user's pinned scores.
Expand Down Expand Up @@ -996,7 +1014,10 @@ async def get_user_pinned(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_user_beatmap_scores(
self, user_id: int, beatmap_id: int, **kwargs: Any
self,
user_id: int,
beatmap_id: int,
**kwargs: Any,
) -> list[Score]:
r"""Get a user's scores on a specific beatmap.
Expand Down Expand Up @@ -1027,7 +1048,10 @@ async def get_user_beatmap_scores(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_user_beatmaps(
self, user_id: int, type: UserBeatmapType, **kwargs: Any
self,
user_id: int,
type: UserBeatmapType,
**kwargs: Any,
) -> list[Beatmapset]:
r"""Get a user's beatmaps.
Expand Down Expand Up @@ -1059,7 +1083,9 @@ async def get_user_beatmaps(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_user_most_played(
self, user_id: int, **kwargs: Any
self,
user_id: int,
**kwargs: Any,
) -> list[BeatmapUserPlaycount]:
r"""Get a user's most played beatmaps.
Expand Down Expand Up @@ -1089,7 +1115,9 @@ async def get_user_most_played(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_user_recent_activity(
self, user_id: int, **kwargs: Any
self,
user_id: int,
**kwargs: Any,
) -> list[Event]:
r"""Get a user's recent activity.
Expand Down Expand Up @@ -1217,7 +1245,9 @@ async def lookup_beatmap(self, **kwargs: Any) -> Beatmap:
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_beatmap_attributes(
self, beatmap_id: int, **kwargs: Any
self,
beatmap_id: int,
**kwargs: Any,
) -> BeatmapDifficultyAttributes:
r"""Gets difficulty attributes for a beatmap.
Expand Down Expand Up @@ -1360,7 +1390,8 @@ async def get_beatmapset_events(self, **kwargs: Any) -> list[BeatmapsetEvent]:
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_beatmapset_discussions(
self, **kwargs: Any
self,
**kwargs: Any,
) -> BeatmapsetDiscussionResponse:
r"""Get beatmapset discussions.
Expand Down Expand Up @@ -1419,7 +1450,8 @@ async def get_beatmapset_discussions(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_beatmapset_discussion_posts(
self, **kwargs: Any
self,
**kwargs: Any,
) -> BeatmapsetDiscussionPostResponse:
r"""Get beatmapset discussion posts.
Expand Down Expand Up @@ -1469,7 +1501,8 @@ async def get_beatmapset_discussion_posts(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_beatmapset_discussion_votes(
self, **kwargs: Any
self,
**kwargs: Any,
) -> BeatmapsetDiscussionVoteResponse:
r"""Get beatmapset discussion votes.
Expand Down Expand Up @@ -1568,7 +1601,10 @@ async def get_score_replay(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_rankings(
self, mode: Gamemode, type: RankingType, **kwargs: Any
self,
mode: Gamemode,
type: RankingType,
**kwargs: Any,
) -> Rankings:
r"""Get rankings.
Expand Down Expand Up @@ -1672,7 +1708,11 @@ async def get_forum_topic(self, topic_id: int, **kwargs: Any) -> ForumTopicRespo
@requires_scope(Scopes.FORUM_WRITE)
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def create_forum_topic(
self, forum_id: int, title: str, content: str, **kwargs: Any
self,
forum_id: int,
title: str,
content: str,
**kwargs: Any,
) -> ForumCreateTopicResponse:
r"""Creates a forum topic.
Expand Down Expand Up @@ -1900,7 +1940,9 @@ async def get_channels(self) -> list[ChatChannel]:
@requires_scope(Scopes.LAZER)
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def get_channel_messages(
self, channel_id: int, **kwargs: Any
self,
channel_id: int,
**kwargs: Any,
) -> list[ChatMessage]:
r"""Gets channel messages.
Expand Down Expand Up @@ -1938,7 +1980,9 @@ async def get_channel_messages(
@requires_scope(Scopes.CHAT_WRITE)
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def create_chat_channel(
self, type: ChatChannelTypes, **kwargs: Any
self,
type: ChatChannelTypes,
**kwargs: Any,
) -> ChatChannel:
r"""Creates a chat channel.
Expand Down Expand Up @@ -2071,7 +2115,11 @@ async def send_message(
@requires_scope(Scopes.CHAT_WRITE)
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def send_private_message(
self, user_id: int, message: str, is_action: bool, **kwargs: Any
self,
user_id: int,
message: str,
is_action: bool,
**kwargs: Any,
) -> ChatMessageCreateResponse:
r"""Sends a message to a user.
Expand Down Expand Up @@ -2106,7 +2154,8 @@ async def send_private_message(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_multiplayer_matches(
self, **kwargs: Any
self,
**kwargs: Any,
) -> MultiplayerMatchesResponse:
r"""Gets the multiplayer matches.
Expand Down Expand Up @@ -2144,7 +2193,9 @@ async def get_multiplayer_matches(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_multiplayer_match(
self, match_id: int, **kwargs: Any
self,
match_id: int,
**kwargs: Any,
) -> MultiplayerMatchResponse:
r"""Gets a multiplayer match.
Expand Down Expand Up @@ -2241,7 +2292,9 @@ async def get_multiplayer_room(self, room_id: int) -> MultiplayerRoom:
@requires_scope(Scopes.PUBLIC)
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def get_multiplayer_leaderboard(
self, room_id: int, **kwargs: Any
self,
room_id: int,
**kwargs: Any,
) -> MultiplayerLeaderboardResponse:
r"""Gets the multiplayer leaderboard for a room.
Expand Down Expand Up @@ -2272,7 +2325,10 @@ async def get_multiplayer_leaderboard(
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_multiplayer_scores(
self, room_id: int, playlist_id: int, **kwargs: Any
self,
room_id: int,
playlist_id: int,
**kwargs: Any,
) -> MultiplayerScoresResponse:
r"""Gets the multiplayer scores for a room.
Expand Down Expand Up @@ -2309,7 +2365,10 @@ async def get_multiplayer_scores(
if resp.cursor_string:
kwargs["cursor_string"] = resp.cursor_string
resp.next = partial(
self.get_multiplayer_scores, room_id, playlist_id, **kwargs
self.get_multiplayer_scores,
room_id,
playlist_id,
**kwargs,
)
return resp

Expand Down

0 comments on commit 14b3eb6

Please sign in to comment.