Skip to content

Commit

Permalink
refactor: custom async loops based on platform
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiro committed Apr 22, 2023
1 parent 093c17e commit 0adb265
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 2 additions & 3 deletions poetry.lock

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

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "spotify-to-musi"
description = "Transfer Spotify playlists to Musi."
version = "2.0.0rc3"
version = "2.0.0rc4"
readme = "README.md"
license = "MIT"
authors = ["Hexiro <[email protected]>"]
Expand Down Expand Up @@ -34,6 +34,7 @@ pyfy = "^2.2.0"
sanic = "^23.3.0"
async-cache = "^1.1.1"
typing-extensions = {version = "^4.5.0", python = "<3.11"}
uvloop = {version = "^0.17.0", platform = "linux"}

[tool.poetry.scripts]
spotify-to-musi = "spotify_to_musi.__main__:cli"
Expand Down
9 changes: 9 additions & 0 deletions spotify_to_musi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import asyncio
import functools
import sys
import typing as t

import pyfy.excs
Expand All @@ -25,6 +26,14 @@ def async_cmd(func: t.Callable) -> t.Callable:

@functools.wraps(func)
def wrapper(*args: t.Any, **kwargs: t.Any) -> t.Any:
if sys.platform == "win32":
# Set the policy to prevent "Event loop is closed" error on Windows - https://github.com/encode/httpx/issues/914
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
elif sys.platform == "linux":
import uvloop

uvloop.install()

return asyncio.run(func(*args, **kwargs))

return wrapper
Expand Down

0 comments on commit 0adb265

Please sign in to comment.