Compare commits

..

17 Commits

Author SHA1 Message Date
dependabot[bot]
433b4958dd Bump aiohttp from 3.5.4 to 3.7.4
Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.5.4 to 3.7.4.
- [Release notes](https://github.com/aio-libs/aiohttp/releases)
- [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst)
- [Commits](https://github.com/aio-libs/aiohttp/compare/v3.5.4...v3.7.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-09 08:52:23 +00:00
Miron Moderau
46cda7d61a Make GitLab CI use requirements-dev.txt for tests 2021-09-08 16:27:20 +02:00
Miron Moderau
f0f6210c3e Split requirements-dev.txt from requirements.txt
All pytest and types requirements are moved.
Also, the pip bug comment is made more explanatory.
2021-09-08 15:33:18 +02:00
Miron Moderau
468dfcc60d Add types-certifi to Requirements.txt
Required after mypy update.
2021-09-08 12:17:14 +02:00
Miron Moderau
8f91f705ee Remove LoggedInElsewhere error type
This error is obsolete. It was never used by most plugins and Galaxy
does not handle it in any specific way.
2021-09-08 11:33:16 +02:00
Mieszko Banczerowski
46588c321e PLINT-711 Enhancement for logging plugin responses 2021-05-04 13:42:03 +02:00
Mieszko Bańczerowski
947c578121 Increment version 2021-04-20 13:26:30 +02:00
Mieszko Banczerowski
aba9b0ed6b PLINT-575 set galaxy package logging level to INFO 2021-04-20 11:45:48 +02:00
Albert Suralinski
f0d65a72ff PLINT-139 added default values for optional UserInfo dataclass parameters 2020-12-03 10:02:25 +01:00
Mieszko Bańczerowski
96cb48fcaf Increment version 2020-09-18 11:01:55 +02:00
Mieszko Banczerowski
17b0542fdf GPI-1232 Synchronous importer for local sizes 2020-09-16 13:33:17 +02:00
Mieszko Banczerowski
0cf447bdcf Increment vesion 2020-06-24 16:04:20 +02:00
Mieszko Banczerowski
259702e0de GPI-1396 Add issue templates and external links 2020-06-23 11:18:08 +02:00
mbanczerowski
b96c55397e Fix typo in PLATFORM_IDs.md (#161) 2020-06-23 10:56:16 +02:00
Mieszko Banczerowski
f82cab2770 GPI-1399: Update get_local_size docs 2020-06-22 11:12:12 +02:00
Robert Korulczyk
1e7c284035 Fix typo 2020-06-19 22:19:45 +02:00
Mieszko Banczerowski
0c49ee315e Updates missing ids to PLATFORM_ID.md 2020-06-18 17:31:16 +02:00
16 changed files with 106 additions and 45 deletions

11
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
blank_issues_enabled: true
contact_links:
- name: GOG GALAXY 2.0 issue
url: https://mantis2.gog.com/
about: Report issues related to GOG GALAXY 2.0, official integrations or the whole ecosystem
- name: Platform ID request
url: https://github.com/gogcom/galaxy-integrations-python-api/issues/160
about: Report missing platform id
- name: Community integrations
url: https://github.com/Mixaill/awesome-gog-galaxy
about: Find integrations and their maintainers, request new integrations or report issues related to unofficial integrations.

View File

@@ -0,0 +1,14 @@
---
name: API issue
about: Report a bug or problem with current API architecture
---
**Problem**
<!-- Describe the problem you faced. -->
**Solution**
<!-- Describe the solution you'd like. -->
**Alternatives**
<!-- Optionally describe possible alternatives or current workarounds if any. -->

View File

@@ -7,7 +7,7 @@ stages:
test_package:
stage: test
script:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pytest
except:
- tags

View File

@@ -80,3 +80,12 @@ Platform ID list for GOG Galaxy 2.0 Integrations
| nds | Nintendo DS |
| 3ds | Nintendo 3DS |
| pathofexile | Path of Exile |
| twitch | Twitch |
| minecraft | Minecraft |
| gamesessions | GameSessions |
| nuuvem | Nuuvem |
| fxstore | FX Store |
| indiegala | IndieGala |
| playfire | Playfire |
| oculus | Oculus |
| rockstar | Rockstar |

7
requirements-dev.txt Normal file
View File

@@ -0,0 +1,7 @@
-r requirements.txt
pytest==5.2.2
pytest-asyncio==0.10.0
pytest-mock==1.10.3
pytest-mypy==0.4.1
pytest-flakes==4.0.0
types-certifi==2020.4.0

View File

@@ -1,10 +1,7 @@
-e .
pytest==5.2.2
pytest-asyncio==0.10.0
pytest-mock==1.10.3
pytest-mypy==0.4.1
pytest-flakes==4.0.0
# because of pip bug https://github.com/pypa/pip/issues/4780
aiohttp==3.5.4
# Copied from setup.py because of a pip bug
# see https://github.com/pypa/pip/issues/4780
aiohttp==3.7.4
certifi==2019.3.9
psutil==5.6.6; sys_platform == 'darwin'
# End of copy from setup.py

View File

@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name="galaxy.plugin.api",
version="0.65.1",
version="0.68",
description="GOG Galaxy Integrations Python API",
author='Galaxy team',
author_email='galaxy@gog.com',

View File

@@ -1 +1,6 @@
__path__: str = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
import logging
logging.getLogger(__name__).setLevel(logging.INFO)
__path__: str = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore

View File

@@ -34,10 +34,6 @@ class NetworkError(ApplicationError):
def __init__(self, data=None):
super().__init__(101, "Network error", data)
class LoggedInElsewhere(ApplicationError):
def __init__(self, data=None):
super().__init__(102, "Logged in elsewhere", data)
class ProtocolError(ApplicationError):
def __init__(self, data=None):
super().__init__(103, "Protocol error", data)

View File

@@ -87,3 +87,16 @@ class CollectionImporter(Importer):
self._notification_failure(id_, UnknownError())
finally:
self._notification_partially_finished(id_)
class SynchroneousImporter(Importer):
async def _import_elements(self, ids_, context_):
try:
for id_ in ids_:
await self._import_element(id_, context_)
self._notification_finished()
self._complete()
except asyncio.CancelledError:
logger.debug("Importing %s cancelled", self._name)
finally:
self._import_in_progress = False

View File

@@ -299,14 +299,11 @@ class Connection():
except TypeError:
raise InvalidRequest()
def _send(self, data, sensitive=True):
def _send(self, data, log_level=logging.DEBUG):
try:
line = self._encoder.encode(data)
logger.log(log_level, "Sending data: %s", line)
data = (line + "\n").encode("utf-8")
if sensitive:
logger.debug("Sending %d bytes of data", len(data))
else:
logging.debug("Sending data: %s", line)
self._writer.write(data)
except TypeError as error:
logger.error(str(error))
@@ -317,7 +314,7 @@ class Connection():
"id": request_id,
"result": result
}
self._send(response, sensitive=False)
self._send(response, logging.INFO)
def _send_error(self, request_id, error):
response = {
@@ -325,8 +322,7 @@ class Connection():
"id": request_id,
"error": error.json()
}
self._send(response, sensitive=False)
self._send(response, logging.ERROR)
def _send_request(self, request_id, method, params):
request = {
@@ -335,7 +331,7 @@ class Connection():
"id": request_id,
"params": params
}
self._send(request, sensitive=True)
self._send(request, logging.NOTSET)
def _send_notification(self, method, params):
notification = {
@@ -343,7 +339,7 @@ class Connection():
"method": method,
"params": params
}
self._send(notification, sensitive=True)
self._send(notification, logging.NOTSET)
@staticmethod
def _log_request(request, sensitive_params):

View File

@@ -13,7 +13,7 @@ from galaxy.api.types import (
Subscription, SubscriptionGame
)
from galaxy.task_manager import TaskManager
from galaxy.api.importer import Importer, CollectionImporter
from galaxy.api.importer import Importer, CollectionImporter, SynchroneousImporter
logger = logging.getLogger(__name__)
@@ -104,7 +104,7 @@ class Plugin:
self._user_presence_import_finished,
self.user_presence_import_complete
)
self._local_size_importer = Importer(
self._local_size_importer = SynchroneousImporter(
self._external_task_manager,
"local size",
self.get_local_size,
@@ -292,7 +292,7 @@ class Plugin:
await self._external_task_manager.wait()
await self._internal_task_manager.wait()
await self._connection.wait_closed()
logger.debug("Plugin closed")
logger.info("Plugin closed")
def create_task(self, coro, description):
"""Wrapper around asyncio.create_task - takes care of canceling tasks on shutdown"""
@@ -1027,10 +1027,9 @@ class Plugin:
It is preferable to avoid iterating over local game files when overriding this method.
If possible, please use a more efficient way of game size retrieval.
:param game_id: the id of the installed game
:param context: the value returned from :meth:`prepare_local_size_context`
:return: game size (in bytes) or `None` if game size cannot be determined;
'0' if the game is not installed, or if it is not present locally (e.g. installed
on another machine and accessible via remote connection, playable via web browser etc.)
:return: the size of the game on a user-owned storage device (in bytes) or `None` if the size cannot be determined
"""
raise NotImplementedError()

View File

@@ -166,8 +166,8 @@ class UserInfo:
"""
user_id: str
user_name: str
avatar_url: Optional[str]
profile_url: Optional[str]
avatar_url: Optional[str] = None
profile_url: Optional[str] = None
@dataclass

View File

@@ -2,8 +2,16 @@ import pytest
from galaxy.api.types import Authentication
from galaxy.api.errors import (
UnknownError, InvalidCredentials, NetworkError, LoggedInElsewhere, ProtocolError,
BackendNotAvailable, BackendTimeout, BackendError, TemporaryBlocked, Banned, AccessDenied
UnknownError,
BackendNotAvailable,
BackendTimeout,
BackendError,
InvalidCredentials,
NetworkError,
ProtocolError,
TemporaryBlocked,
Banned,
AccessDenied,
)
from galaxy.unittest.mock import async_return_value, skip_loop
@@ -42,7 +50,6 @@ async def test_success(plugin, read, write):
pytest.param(BackendError, 4, "Backend error", id="backend_error"),
pytest.param(InvalidCredentials, 100, "Invalid credentials", id="invalid_credentials"),
pytest.param(NetworkError, 101, "Network error", id="network_error"),
pytest.param(LoggedInElsewhere, 102, "Logged in elsewhere", id="logged_elsewhere"),
pytest.param(ProtocolError, 103, "Protocol error", id="protocol_error"),
pytest.param(TemporaryBlocked, 104, "Temporary blocked", id="temporary_blocked"),
pytest.param(Banned, 105, "Banned", id="banned"),

View File

@@ -18,7 +18,9 @@ async def test_get_friends_success(plugin, read, write):
read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
plugin.get_friends.return_value = async_return_value([
UserInfo("3", "Jan", "https://avatar.url/u3", None),
UserInfo("5", "Ola", None, "https://profile.url/u5")
UserInfo("5", "Ola", None, "https://profile.url/u5"),
UserInfo("6", "Ola2", None),
UserInfo("7", "Ola3"),
])
await plugin.run()
plugin.get_friends.assert_called_with()
@@ -30,7 +32,9 @@ async def test_get_friends_success(plugin, read, write):
"result": {
"friend_info_list": [
{"user_id": "3", "user_name": "Jan", "avatar_url": "https://avatar.url/u3"},
{"user_id": "5", "user_name": "Ola", "profile_url": "https://profile.url/u5"}
{"user_id": "5", "user_name": "Ola", "profile_url": "https://profile.url/u5"},
{"user_id": "6", "user_name": "Ola2"},
{"user_id": "7", "user_name": "Ola3"},
]
}
}

View File

@@ -19,7 +19,7 @@ async def test_get_local_size_success(plugin, read, write):
}
read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
plugin.get_local_size.side_effect = [
async_return_value(100000000000),
async_return_value(100000000000, 1),
async_return_value(None),
async_return_value(3333333)
]
@@ -89,12 +89,15 @@ async def test_get_local_size_error(exception, code, message, plugin, read, writ
plugin.get_local_size.assert_called()
plugin.local_size_import_complete.assert_called_once_with()
assert get_messages(write) == [
{
"jsonrpc": "2.0",
"id": request_id,
"result": None
},
direct_response = {
"jsonrpc": "2.0",
"id": request_id,
"result": None
}
responses = get_messages(write)
assert direct_response in responses
responses.remove(direct_response)
assert responses == [
{
"jsonrpc": "2.0",
"method": "local_size_import_failure",
@@ -145,6 +148,7 @@ async def test_prepare_get_local_size_context_error(plugin, read, write):
@pytest.mark.asyncio
async def test_import_already_in_progress_error(plugin, read, write):
plugin.prepare_local_size_context.return_value = async_return_value(None)
plugin.get_local_size.return_value = async_return_value(100, 5)
requests = [
{
"jsonrpc": "2.0",
@@ -185,4 +189,3 @@ async def test_import_already_in_progress_error(plugin, read, write):
"message": "Import already in progress"
}
} in responses