Skip to content

Commit

Permalink
Updated instances of 'Tribler Experimental' (#8224)
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink authored Oct 17, 2024
2 parents 5b5283d + 6ebe2a8 commit 0fdd382
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/tribler/core/content_discovery/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import uuid
from binascii import hexlify, unhexlify
from importlib.metadata import PackageNotFoundError, version
from itertools import count
from typing import TYPE_CHECKING, Any, Callable, Sequence

Expand Down Expand Up @@ -254,7 +255,11 @@ async def on_version_request(self, peer: Peer, _: VersionRequest) -> None:
"""
Callback for when our Tribler version and Operating System is requested.
"""
version_response = VersionResponse("Tribler Experimental", sys.platform)
try:
v = version("tribler")
except PackageNotFoundError:
v = "git"
version_response = VersionResponse(f"Tribler {v}", sys.platform)
self.ez_send(peer, version_response)

@lazy_wrapper(VersionResponse)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import base64
import json
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

import libtorrent as lt
Expand Down Expand Up @@ -114,7 +115,11 @@ async def create_torrent(self, request: Request) -> RESTResponse:
if parameters.get("export_dir"):
export_dir = Path(parameters["export_dir"])

params["created by"] = "Tribler version: Tribler Experimental"
try:
v = version("tribler")
except PackageNotFoundError:
v = "git"
params["created by"] = f"Tribler version: {v}"
params["nodes"] = False
params["httpseeds"] = False
params["encoding"] = False
Expand Down
7 changes: 6 additions & 1 deletion src/tribler/core/restapi/events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from asyncio import CancelledError, Event, Future, Queue
from contextlib import suppress
from importlib.metadata import PackageNotFoundError, version
from traceback import format_exception
from typing import TYPE_CHECKING, TypedDict

Expand Down Expand Up @@ -103,9 +104,13 @@ def initial_message(self) -> MessageDict:
"""
Create the initial message to announce to the GUI.
"""
try:
v = version("tribler")
except PackageNotFoundError:
v = "git"
return {
"topic": Notification.events_start.value.name,
"kwargs": {"public_key": self.public_key or "", "version": "Tribler Experimental"}
"kwargs": {"public_key": self.public_key or "", "version": v}
}

def error_message(self, reported_error: Exception) -> MessageDict:
Expand Down
7 changes: 6 additions & 1 deletion src/tribler/core/restapi/rest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback
from asyncio.base_events import Server
from functools import wraps
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path
from typing import TYPE_CHECKING, Awaitable, Callable, Generic, TypeVar, cast

Expand Down Expand Up @@ -210,13 +211,17 @@ async def start(self) -> None:
Starts the HTTP API with the listen port as specified in the session configuration.
"""
self._logger.info("Starting RESTManager...")
try:
v = version("tribler")
except PackageNotFoundError:
v = "git"

# Not using setup_aiohttp_apispec here, as we need access to the APISpec to set the security scheme
aiohttp_apispec = AiohttpApiSpec(
url="/docs/swagger.json",
app=self.root_endpoint.app,
title="Tribler REST API documentation",
version="Tribler Experimental",
version=f"Tribler {v}",
swagger_path="/docs"
)
if self.config.get("api/key"):
Expand Down
18 changes: 16 additions & 2 deletions src/tribler/test_unit/core/content_discovery/test_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from binascii import hexlify
from typing import TYPE_CHECKING, cast
from unittest import skipIf
from unittest.mock import AsyncMock, Mock
from unittest.mock import AsyncMock, Mock, patch

from ipv8.messaging.payload import IntroductionRequestPayload, NewIntroductionRequestPayload
from ipv8.test.base import TestBase
from ipv8.test.mocking.endpoint import MockEndpointListener

import tribler
from tribler.core.content_discovery.community import ContentDiscoveryCommunity, ContentDiscoverySettings
from tribler.core.content_discovery.payload import (
PopularTorrentsRequest,
Expand Down Expand Up @@ -205,7 +206,20 @@ async def test_request_for_version(self) -> None:
message, = received

self.assertEqual(sys.platform, message.platform)
self.assertEqual("Tribler Experimental", message.version)
self.assertEqual("Tribler git", message.version)

async def test_request_for_version_build(self) -> None:
"""
Test if a build version request is responded to.
"""
with patch.dict(tribler.core.content_discovery.community.__dict__, {"version": lambda _: "1.2.3"}), \
self.assertReceivedBy(0, [VersionResponse]) as received:
self.overlay(0).ez_send(self.peer(1), VersionRequest())
await self.deliver_messages()
message, = received

self.assertEqual(sys.platform, message.platform)
self.assertEqual("Tribler 1.2.3", message.version)

def test_search_for_tags_no_db(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/test_unit/core/restapi/test_events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def test_establish_connection(self) -> None:

self.assertEqual(200, response.status)
self.assertEqual((b'event: events_start\n'
b'data: {"public_key": "", "version": "Tribler Experimental"}'
b'data: {"public_key": "", "version": "git"}'
b'\n\n'), request.payload_writer.captured[0])

async def test_establish_connection_with_error(self) -> None:
Expand Down

0 comments on commit 0fdd382

Please sign in to comment.