diff --git a/.flake8 b/.flake8 index a36f40f6b51..61918163491 100644 --- a/.flake8 +++ b/.flake8 @@ -2,4 +2,4 @@ max-line-length = 120 select=E901,E999,F821,F822,F823,I100,I101,I201,I202,T001,T002,T003,T004 ignore=E203,W503,C0330 -application-import-names=tribler_core,tribler_gui,tribler_common,run_tribler,experiment +application-import-names=tribler_core,tribler_gui,run_tribler,experiment diff --git a/.isort.cfg b/.isort.cfg index 0b2a78b7a51..942e609db3c 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -9,5 +9,5 @@ combine_as_imports=True force_sort_within_sections=True line_length=120 known_future_library=future -known_first_party=tribler_core,tribler_gui,tribler_common,run_tribler +known_first_party=tribler_core,tribler_gui,run_tribler known_third_party=pony,twisted,six,anydex,ipv8,libtorrent,lz4,PyQt5,zope,aiohttp,psutil,configobj,ipv8_service,asynctest,numpy,networkx,async_timeout,cherrypy,nose,validate,check_os,matplotlib,pyqtgraph,_socket,aiohttp_apispec,marshmallow,PIL,anyio,freezegun,yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6877d4b3df6..db7b840aa0a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,8 +21,7 @@ repos: files: | (?x)( ^src/tribler-gui/| - ^src/tribler-core/tribler_core/modules/metadata_store/| - ^src/tribler-common + ^src/tribler-core/tribler_core/modules/metadata_store/ ) types: [file, python] @@ -45,8 +44,7 @@ repos: files: | (?x)( ^src/tribler-gui/| - ^src/tribler-core/| - ^src/tribler-common + ^src/tribler-core/ ) types: [file, python] diff --git a/Dockerfile b/Dockerfile index 9372ed2606c..c85304eb8d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,6 @@ RUN mkdir /requirements COPY ./src/pyipv8/requirements.txt /requirements/pyipv8-requirements.txt RUN pip3 install -r /requirements/pyipv8-requirements.txt -COPY ./src/tribler-common/tribler_common/requirements.txt /requirements/common-requirements.txt -RUN pip3 install -r /requirements/common-requirements.txt - COPY ./src/tribler-core/tribler_core/requirements.txt /requirements/core-requirements.txt RUN pip3 install -r /requirements/core-requirements.txt diff --git a/build/systemd/anontunnel_helper@.service b/build/systemd/anontunnel_helper@.service index 97fba0507c3..91917d98b30 100644 --- a/build/systemd/anontunnel_helper@.service +++ b/build/systemd/anontunnel_helper@.service @@ -13,7 +13,7 @@ Environment=HOME=/var/lib/tunnel_helper/%I Environment=HELPER_INDEX=%I Environment=HELPER_BASE=35000 Environment=EXTRA_TUNNEL_ARGS=-- -Environment=PYTHONPATH=./src/pyipv8:./src/anydex:./src/tribler-common:./src/tribler-core +Environment=PYTHONPATH=./src/pyipv8:./src/anydex:./src/tribler-core WorkingDirectory=/opt/tribler ExecStartPre=/bin/mkdir -p ${HOME} diff --git a/build/systemd/bandwidth-crawler.service b/build/systemd/bandwidth-crawler.service index 18a70b3dc25..8da6eb7ab38 100644 --- a/build/systemd/bandwidth-crawler.service +++ b/build/systemd/bandwidth-crawler.service @@ -7,7 +7,7 @@ Type=simple User=crawler Group=crawler Restart=always -Environment=PYTHONPATH=./src/pyipv8:./src/tribler-common:./src/tribler-core +Environment=PYTHONPATH=./src/pyipv8:./src/tribler-core WorkingDirectory=/opt/tribler ExecStart=/usr/bin/python3 src/tribler-core/run_bandwidth_crawler.py --statedir /var/lib/crawler $EXTRA_CRAWLER_ARGS diff --git a/doc/conf.py b/doc/conf.py index 994d90f5645..30999975f6c 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -25,7 +25,6 @@ tribler_components = [ os.path.join(root_dir, "src", "pyipv8"), os.path.join(root_dir, "src", "anydex"), - os.path.join(root_dir, "src", "tribler-common"), os.path.join(root_dir, "src", "tribler-core"), os.path.join(root_dir, "src", "tribler-gui"), os.path.join(root_dir, "doc"), @@ -33,11 +32,10 @@ for component in tribler_components: sys.path.append(str(component)) -from tribler_common.dependencies import Scope, get_dependencies -from tribler_common.patch_import import patch_import +from tribler_core.utilities.dependencies import Scope, get_dependencies +from tribler_core.utilities.patch_import import patch_import -modules_to_mock = set(get_dependencies(scope=Scope.core)) | \ - set(get_dependencies(scope=Scope.common)) | {'libtorrent', 'validate'} +modules_to_mock = set(get_dependencies(scope=Scope.core)) | {'libtorrent', 'validate'} with patch_import(modules=modules_to_mock): from tribler_core.components.restapi.rest.root_endpoint import RootEndpoint diff --git a/experiment/popularity_community/README.md b/experiment/popularity_community/README.md index 80c8663e6ed..22df31fbcb5 100644 --- a/experiment/popularity_community/README.md +++ b/experiment/popularity_community/README.md @@ -36,7 +36,7 @@ time_in_sec,total,alive ### Usage ``` -export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-common,tribler-core} | tr " " :` +export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-core} | tr " " :` python3 initial_filling.py [-i ] [-t ] [-f ] ``` @@ -79,7 +79,7 @@ Where: ### Usage ``` -export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-common,tribler-core} | tr " " :` +export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-core} | tr " " :` python3 crawl_torrents.py [-t ] [-f ] [-v] [--peers_count_csv=] @@ -160,7 +160,7 @@ Where: ### Usage ``` -export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-common,tribler-core} | tr " " :` +export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-core} | tr " " :` python3 analyze_crawled_data.py [-d ] [-f ] [-l ] [-v] diff --git a/experiment/popularity_community/analyze_crawled_data.py b/experiment/popularity_community/analyze_crawled_data.py index a6d1169684a..29186267530 100644 --- a/experiment/popularity_community/analyze_crawled_data.py +++ b/experiment/popularity_community/analyze_crawled_data.py @@ -24,7 +24,7 @@ ### Usage ``` -export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-common,tribler-core} | tr " " :` +export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-core} | tr " " :` python3 analyze_crawled_data.py [-d ] [-f ] [-l ] [-v] diff --git a/experiment/popularity_community/crawl_torrents.py b/experiment/popularity_community/crawl_torrents.py index 30516ea476f..c1d4b5d0e9e 100644 --- a/experiment/popularity_community/crawl_torrents.py +++ b/experiment/popularity_community/crawl_torrents.py @@ -1,7 +1,7 @@ """This script crawl first 100 torrens from random nodes in the network. ``` -export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-common,tribler-core} | tr " " :` +export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../../src/{pyipv8,tribler-core} | tr " " :` python3 crawl_torrents.py [-t ] [-f ] [-v] [--peers_count_csv=] diff --git a/pyproject.toml b/pyproject.toml index e8282ddd387..551e4e4db26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.black] line-length = 120 skip-string-normalization = true -include = '(src/tribler-gui|src/tribler-common|src/tribler-core/tribler_core/modules/metadata_store)/.*\.pyi?$' +include = '(src/tribler-core/tribler_core/modules/metadata_store)/.*\.pyi?$' exclude = ''' /( diff --git a/src/README.md b/src/README.md index 8618c2bb770..383d629b6a6 100644 --- a/src/README.md +++ b/src/README.md @@ -21,17 +21,15 @@ from` requirements.txt`. Export to PYTHONPATH the following directories: -* tribler-common * tribler-core * tribler-gui Shortcut for macOS: ```shell script -export PYTHONPATH=${PYTHONPATH}:`echo {pyipv8,tribler-common,tribler-core,tribler-gui} | tr " " :` +export PYTHONPATH=${PYTHONPATH}:`echo {pyipv8,tribler-core,tribler-gui} | tr " " :` ``` Execute: ``` python3 -m pytest tribler-core -python3 -m pytest tribler-common python3 -m pytest tribler-gui --guitests ``` \ No newline at end of file diff --git a/src/requirements.txt b/src/requirements.txt index 8eaabc13b1a..1bd5ff73f12 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,3 +1 @@ --r tribler-core/tribler_core/requirements.txt -r tribler-gui/tribler_gui/requirements.txt --r tribler-common/tribler_common/requirements.txt \ No newline at end of file diff --git a/src/run_tests.bat b/src/run_tests.bat index f939f559aa5..b754d844391 100644 --- a/src/run_tests.bat +++ b/src/run_tests.bat @@ -1,2 +1,2 @@ -set PYTHONPATH=%~dp0tribler-core;%~dp0tribler-common +set PYTHONPATH=%~dp0tribler-core pytest %~dp0tribler-core %* diff --git a/src/run_tests.sh b/src/run_tests.sh index 51b38823d66..9ee008258ff 100755 --- a/src/run_tests.sh +++ b/src/run_tests.sh @@ -4,5 +4,5 @@ script_path() { } SRC_DIR="$(dirname "$(script_path "$0")")/src" -export PYTHONPATH=$SRC_DIR/tribler-core:$SRC_DIR/tribler-common +export PYTHONPATH=$SRC_DIR/tribler-core pytest $SRC_DIR/tribler-core "$@" diff --git a/src/run_tribler.bat b/src/run_tribler.bat index dc943bcca01..21a8d148ae2 100644 --- a/src/run_tribler.bat +++ b/src/run_tribler.bat @@ -1,2 +1,2 @@ -set PYTHONPATH=%~dp0tribler-core;%~dp0tribler-common;%~dp0tribler-gui;%~dp0pyipv8;%~dp0anydex +set PYTHONPATH=%~dp0tribler-core;%~dp0tribler-gui;%~dp0pyipv8;%~dp0anydex python run_tribler.py diff --git a/src/run_tribler.py b/src/run_tribler.py index d32ac06e170..1222740e011 100644 --- a/src/run_tribler.py +++ b/src/run_tribler.py @@ -8,10 +8,9 @@ import os import sys -from tribler_common.sentry_reporter.sentry_reporter import SentryStrategy -from tribler_common.sentry_reporter.sentry_scrubber import SentryScrubber - from tribler_core.components.reporter.exception_handler import default_core_exception_handler +from tribler_core.sentry_reporter.sentry_reporter import SentryStrategy +from tribler_core.sentry_reporter.sentry_scrubber import SentryScrubber logger = logging.getLogger(__name__) @@ -67,7 +66,7 @@ def init_boot_logger(): logger.info(f'Run Tribler: {parsed_args}') # Get root state directory (e.g. from environment variable or from system default) - from tribler_common.osutils import get_root_state_directory + from tribler_core.utilities.osutils import get_root_state_directory root_state_dir = get_root_state_directory() logger.info(f'Root state dir: {root_state_dir}') diff --git a/src/seedbox/README.md b/src/seedbox/README.md index b44136862bb..ec4146e99ff 100644 --- a/src/seedbox/README.md +++ b/src/seedbox/README.md @@ -19,7 +19,7 @@ The seedbox consists of two parts: ``` 1. Add necessary folders to `PYTHONPATH` (below the bash example) ```shell - export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../{pyipv8,tribler-common,tribler-core} | tr " " :` + export PYTHONPATH=${PYTHONPATH}:`echo ../.. ../{pyipv8,tribler-core} | tr " " :` ``` ## Torrent seeding diff --git a/src/tribler-common/tribler_common/__init__.py b/src/tribler-common/tribler_common/__init__.py deleted file mode 100644 index 6929c53f672..00000000000 --- a/src/tribler-common/tribler_common/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -This module contains code that is shared between the Tribler core and GUI. -""" diff --git a/src/tribler-common/tribler_common/requirements.txt b/src/tribler-common/tribler_common/requirements.txt deleted file mode 100644 index 675694e9a34..00000000000 --- a/src/tribler-common/tribler_common/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -Faker==9.8.2 -sentry-sdk==1.5.0 \ No newline at end of file diff --git a/src/tribler-common/tribler_common/tests/test_utils.py b/src/tribler-common/tribler_common/tests/test_utils.py deleted file mode 100644 index 319ca9c0dd6..00000000000 --- a/src/tribler-common/tribler_common/tests/test_utils.py +++ /dev/null @@ -1,114 +0,0 @@ -from unittest.mock import MagicMock, patch - -from tribler_common.patch_import import patch_import -from tribler_common.utilities import Query, extract_tags, parse_query, show_system_popup, to_fts_query - -# pylint: disable=import-outside-toplevel, import-error -# fmt: off - - -def test_to_fts_query(): - assert to_fts_query(None) is None - assert to_fts_query('') is None - assert to_fts_query(' ') is None - assert to_fts_query(' abc') == '"abc"*' - assert to_fts_query('abc def') == '"abc" "def"*' - assert to_fts_query('[abc, def]: xyz?!') == '"abc" "def" "xyz"*' - - -def test_extract_tags(): - assert extract_tags('') == (set(), '') - assert extract_tags('text') == (set(), 'text') - assert extract_tags('#') == (set(), '#') - assert extract_tags('# ') == (set(), '# ') - assert extract_tags('#t ') == (set(), '#t ') - assert extract_tags('#' + 't' * 51) == (set(), '#' + 't' * 51) - assert extract_tags('####') == (set(), '####') - - assert extract_tags('#tag') == ({'tag'}, '') - assert extract_tags('#Tag') == ({'tag'}, '') - assert extract_tags('a #tag in the middle') == ({'tag'}, 'a in the middle') - assert extract_tags('at the end of the query #tag') == ({'tag'}, 'at the end of the query ') - assert extract_tags('multiple tags: #tag1 #tag2#tag3') == ({'tag1', 'tag2', 'tag3'}, 'multiple tags: ') - assert extract_tags('#tag_with_underscores #tag-with-dashes') == ({'tag_with_underscores', 'tag-with-dashes'}, ' ') - - -def test_parse_query(): - assert parse_query('') == Query(original_query='') - - actual = parse_query('#tag1 #tag2') - expected = Query(original_query='#tag1 #tag2', tags={'tag1', 'tag2'}, fts_text='') - assert actual == expected - - actual = parse_query('query without tags') - expected = Query(original_query='query without tags', - tags=set(), - fts_text='query without tags') - assert actual == expected - - actual = parse_query('query with #tag1 and #tag2') - expected = Query(original_query='query with #tag1 and #tag2', - tags={'tag1', 'tag2'}, - fts_text='query with and') - assert actual == expected - - -@patch_import(modules=['win32api'], MessageBox=MagicMock()) -@patch('platform.system', new=MagicMock(return_value='Windows')) -@patch('tribler_common.utilities.print', new=MagicMock) -def test_show_system_popup_win(): - # in this test "double mocking techniques" has been applied - # there are different mocks that will work depending on the target machine's OS - # - # In case of *nix machine, "@patch_import(modules=['win32api'], MessageBox=MagicMock())" will work. - # In case of win machine, "with patch('win32api.MessageBox'):" will work. - # - # No matter what kind of Mock was used, the line "win32api.MessageBox.assert_called_once()" should work. - # - # This approach also applies to the test functions below. - - import win32api - - with patch('win32api.MessageBox'): # this patch starts to work only in case win32api exists on the target machine - show_system_popup('title', 'text') - win32api.MessageBox.assert_called_once_with(0, 'text', 'title') - - -@patch_import(modules=['subprocess'], Popen=MagicMock()) -@patch('platform.system', new=MagicMock(return_value='Linux')) -@patch('tribler_common.utilities.print', new=MagicMock) -def test_show_system_popup_linux(): - import subprocess - - with patch('subprocess.Popen'): - show_system_popup('title', 'text') - subprocess.Popen.assert_called_once_with(['xmessage', '-center', 'text']) - - -@patch_import(modules=['subprocess'], Popen=MagicMock()) -@patch('platform.system', new=MagicMock(return_value='Darwin')) -@patch('tribler_common.utilities.print', new=MagicMock) -def test_show_system_popup_darwin(): - import subprocess - - with patch('subprocess.Popen'): - show_system_popup('title', 'text') - subprocess.Popen.assert_called_once_with(['/usr/bin/osascript', '-e', 'text']) - - -@patch('platform.system', new=MagicMock(return_value='Unknown')) -@patch('tribler_common.utilities.print') -def test_show_system_popup_unknown(mocked_print): - show_system_popup('title', 'text') - mocked_print.assert_called_with('cannot create native pop-up for system Unknown') - - -@patch_import(modules=['subprocess'], Popen=MagicMock(side_effect=ValueError)) -@patch('platform.system', new=MagicMock(return_value='Darwin')) -@patch('tribler_common.utilities.print') -def test_show_system_popup_exception(mocked_print): - with patch('subprocess.Popen', new=MagicMock(side_effect=ValueError)): - show_system_popup('title', 'text') - last_call_args = mocked_print.call_args_list[-1] - last_argument = last_call_args.args[0] - assert last_argument.startswith('Error while') diff --git a/src/tribler-common/tribler_common/utilities.py b/src/tribler-common/tribler_common/utilities.py deleted file mode 100644 index 06cc0968bbe..00000000000 --- a/src/tribler-common/tribler_common/utilities.py +++ /dev/null @@ -1,105 +0,0 @@ -import itertools -import platform -import re -import sys -from dataclasses import dataclass, field -from typing import Set, Tuple - - -def is_frozen(): - """ - Return whether we are running in a frozen environment - """ - try: - # PyInstaller creates a temp folder and stores path in _MEIPASS - sys._MEIPASS - except Exception: - return False - return True - - -fts_query_re = re.compile(r'\w+', re.UNICODE) -tags_re = re.compile(r'#[^\s^#]{3,50}(?=[#\s]|$)') - - -@dataclass -class Query: - original_query: str - tags: Set[str] = field(default_factory=set) - fts_text: str = '' - - -def parse_query(query: str) -> Query: - """ - The query structure: - query = [tag1][tag2] text - ^ ^ - tags fts query - """ - if not query: - return Query(original_query=query) - - tags, remaining_text = extract_tags(query) - return Query(original_query=query, tags=tags, fts_text=remaining_text.strip()) - - -def extract_tags(text: str) -> Tuple[Set[str], str]: - if not text: - return set(), '' - - tags = set() - positions = [0] - - for m in tags_re.finditer(text): - tag = m.group(0)[1:] - tags.add(tag.lower()) - positions.extend(itertools.chain.from_iterable(m.regs)) - positions.append(len(text)) - - remaining_text = ''.join(text[positions[i] : positions[i + 1]] for i in range(0, len(positions) - 1, 2)) - return tags, remaining_text - - -def to_fts_query(text): - if not text: - return None - - words = [f'"{w}"' for w in fts_query_re.findall(text) if w] - if not words: - return None - - return ' '.join(words) + '*' - - -def show_system_popup(title, text): - """ - Create a native pop-up without any third party dependency. - - :param title: the pop-up title - :param text: the pop-up body - """ - sep = "*" * 80 - - # pylint: disable=import-outside-toplevel, import-error, broad-except - print('\n'.join([sep, title, sep, text, sep]), file=sys.stderr) # noqa: T001 - system = platform.system() - try: - if system == 'Windows': - import win32api - - win32api.MessageBox(0, text, title) - elif system == 'Linux': - import subprocess - - subprocess.Popen(['xmessage', '-center', text]) - elif system == 'Darwin': - import subprocess - - subprocess.Popen(['/usr/bin/osascript', '-e', text]) - else: - print(f'cannot create native pop-up for system {system}') # noqa: T001 - except Exception as exception: - # Use base Exception, because code above can raise many - # non-obvious types of exceptions: - # (SubprocessError, ImportError, win32api.error, FileNotFoundError) - print(f'Error while showing a message box: {exception}') # noqa: T001 diff --git a/src/tribler-core/run_tribler_headless.py b/src/tribler-core/run_tribler_headless.py index 8ef18a2de2f..5e8abaff1cc 100644 --- a/src/tribler-core/run_tribler_headless.py +++ b/src/tribler-core/run_tribler_headless.py @@ -11,12 +11,11 @@ from datetime import date from socket import inet_aton -from tribler_common.osutils import get_appstate_dir, get_root_state_directory -from tribler_common.process_checker import ProcessChecker - from tribler_core.config.tribler_config import TriblerConfig from tribler_core.start_core import Session +from tribler_core.utilities.osutils import get_appstate_dir, get_root_state_directory from tribler_core.utilities.path_util import Path +from tribler_core.utilities.process_checker import ProcessChecker class IPPortAction(argparse.Action): diff --git a/src/tribler-core/run_tribler_upgrader.py b/src/tribler-core/run_tribler_upgrader.py index e88dd30de99..d75b29b2678 100755 --- a/src/tribler-core/run_tribler_upgrader.py +++ b/src/tribler-core/run_tribler_upgrader.py @@ -2,13 +2,12 @@ import signal import sys -from tribler_common.logger import load_logger_config -from tribler_common.version_manager import VersionHistory - from tribler_core.components.key.key_component import KeyComponent from tribler_core.config.tribler_config import TriblerConfig +from tribler_core.logger.logger import load_logger_config from tribler_core.start_core import CONFIG_FILE_NAME from tribler_core.upgrade.upgrade import TriblerUpgrader +from tribler_core.upgrade.version_manager import VersionHistory from tribler_core.utilities.path_util import Path logger = logging.getLogger(__name__) diff --git a/src/tribler-core/run_tunnel_helper.py b/src/tribler-core/run_tunnel_helper.py index e5905e15190..5870525e6b6 100644 --- a/src/tribler-core/run_tunnel_helper.py +++ b/src/tribler-core/run_tunnel_helper.py @@ -13,9 +13,6 @@ from ipv8.taskmanager import TaskManager -from tribler_common.osutils import get_root_state_directory -from tribler_common.simpledefs import NTFY - from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler_core.components.base import Session from tribler_core.components.ipv8.ipv8_component import Ipv8Component @@ -25,7 +22,9 @@ from tribler_core.components.socks_servers.socks_servers_component import SocksServersComponent from tribler_core.components.tunnel.tunnel_component import TunnelsComponent from tribler_core.config.tribler_config import TriblerConfig +from tribler_core.utilities.osutils import get_root_state_directory from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import NTFY logger = logging.getLogger(__name__) diff --git a/src/tribler-core/tribler_core/check_os.py b/src/tribler-core/tribler_core/check_os.py index 6a72b91797e..03ca5d0934d 100644 --- a/src/tribler-core/tribler_core/check_os.py +++ b/src/tribler-core/tribler_core/check_os.py @@ -7,8 +7,8 @@ import psutil -from tribler_common.process_checker import ProcessChecker -from tribler_common.utilities import show_system_popup +from tribler_core.utilities.process_checker import ProcessChecker +from tribler_core.utilities.utilities import show_system_popup FORCE_RESTART_MESSAGE = "An existing Tribler core process (PID:%s) is already running. \n\n" \ "Do you want to stop the process and do a clean restart instead?" diff --git a/src/tribler-core/tribler_core/components/bandwidth_accounting/bandwidth_accounting_component.py b/src/tribler-core/tribler_core/components/bandwidth_accounting/bandwidth_accounting_component.py index 88b7afc302a..c67daeff9c1 100644 --- a/src/tribler-core/tribler_core/components/bandwidth_accounting/bandwidth_accounting_component.py +++ b/src/tribler-core/tribler_core/components/bandwidth_accounting/bandwidth_accounting_component.py @@ -1,5 +1,3 @@ -from tribler_common.simpledefs import STATEDIR_DB_DIR - from tribler_core.components.bandwidth_accounting.community.bandwidth_accounting_community import ( BandwidthAccountingCommunity, BandwidthAccountingTestnetCommunity, @@ -7,6 +5,7 @@ from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase from tribler_core.components.base import Component from tribler_core.components.ipv8.ipv8_component import Ipv8Component +from tribler_core.utilities.simpledefs import STATEDIR_DB_DIR class BandwidthAccountingComponent(Component): diff --git a/src/tribler-core/tribler_core/components/base.py b/src/tribler-core/tribler_core/components/base.py index 7904bef8410..500bf578bb4 100644 --- a/src/tribler-core/tribler_core/components/base.py +++ b/src/tribler-core/tribler_core/components/base.py @@ -9,13 +9,12 @@ from pathlib import Path from typing import Dict, List, Optional, Set, Type, TypeVar, Union -from tribler_common.network_utils import default_network_utils -from tribler_common.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_DB_DIR - from tribler_core.config.tribler_config import TriblerConfig from tribler_core.notifier import Notifier from tribler_core.utilities.crypto_patcher import patch_crypto_be_discovery from tribler_core.utilities.install_dir import get_lib_path +from tribler_core.utilities.network_utils import default_network_utils +from tribler_core.utilities.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_DB_DIR class SessionError(Exception): diff --git a/src/tribler-core/tribler_core/components/gigachannel/community/gigachannel_community.py b/src/tribler-core/tribler_core/components/gigachannel/community/gigachannel_community.py index 59795bc4b02..3bda0ea2ba2 100644 --- a/src/tribler-core/tribler_core/components/gigachannel/community/gigachannel_community.py +++ b/src/tribler-core/tribler_core/components/gigachannel/community/gigachannel_community.py @@ -10,13 +10,12 @@ from pony.orm import db_session -from tribler_common.simpledefs import CHANNELS_VIEW_UUID, NTFY - from tribler_core.components.ipv8.discovery_booster import DiscoveryBooster from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT from tribler_core.components.metadata_store.remote_query_community.payload_checker import ObjState from tribler_core.components.metadata_store.remote_query_community.remote_query_community import RemoteQueryCommunity from tribler_core.components.metadata_store.utils import NoChannelSourcesException +from tribler_core.utilities.simpledefs import CHANNELS_VIEW_UUID, NTFY from tribler_core.utilities.unicode import hexlify minimal_blob_size = 200 diff --git a/src/tribler-core/tribler_core/components/gigachannel/community/settings.py b/src/tribler-core/tribler_core/components/gigachannel/community/settings.py index 5fec4b2753c..d33306c4f74 100644 --- a/src/tribler-core/tribler_core/components/gigachannel/community/settings.py +++ b/src/tribler-core/tribler_core/components/gigachannel/community/settings.py @@ -1,7 +1,7 @@ from pydantic import Field -from tribler_common.simpledefs import STATEDIR_CHANNELS_DIR from tribler_core.config.tribler_config_section import TriblerConfigSection +from tribler_core.utilities.simpledefs import STATEDIR_CHANNELS_DIR class ChantSettings(TriblerConfigSection): diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py b/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py index a69ccdb4dd3..7af32ce037b 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/gigachannel_manager.py @@ -6,8 +6,6 @@ from pony.orm import db_session -from tribler_common.simpledefs import DLSTATUS_SEEDING, NTFY - from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.libtorrent.torrentdef import TorrentDef @@ -15,6 +13,7 @@ from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT from tribler_core.components.metadata_store.db.store import MetadataStore from tribler_core.notifier import Notifier +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING, NTFY from tribler_core.utilities.unicode import hexlify PROCESS_CHANNEL_DIR = 1 diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py index 6c8f7ca0193..1392e25e368 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py @@ -10,13 +10,12 @@ import pytest -from tribler_common.simpledefs import DLSTATUS_SEEDING - from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.tests.tools.base_test import MockObject from tribler_core.tests.tools.common import TORRENT_UBUNTU_FILE +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING from tribler_core.utilities.utilities import random_infohash update_metainfo = None diff --git a/src/tribler-core/tribler_core/components/ipv8/settings.py b/src/tribler-core/tribler_core/components/ipv8/settings.py index 8b5f3ab83b9..391c594ea5b 100644 --- a/src/tribler-core/tribler_core/components/ipv8/settings.py +++ b/src/tribler-core/tribler_core/components/ipv8/settings.py @@ -2,9 +2,8 @@ from pydantic import validator -from tribler_common.network_utils import NetworkUtils from tribler_core.config.tribler_config_section import TriblerConfigSection - +from tribler_core.utilities.network_utils import NetworkUtils # pylint: disable=no-self-argument diff --git a/src/tribler-core/tribler_core/components/key/settings.py b/src/tribler-core/tribler_core/components/key/settings.py index 80e235ea3c6..89d056399f1 100644 --- a/src/tribler-core/tribler_core/components/key/settings.py +++ b/src/tribler-core/tribler_core/components/key/settings.py @@ -2,7 +2,6 @@ from tribler_core.config.tribler_config_section import TriblerConfigSection - # pylint: disable=no-self-argument diff --git a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py index 1b2b9e11d5c..0f93225371d 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download.py @@ -12,9 +12,6 @@ from ipv8.taskmanager import TaskManager, task from ipv8.util import int2byte, succeed -from tribler_common.osutils import fix_filebasename -from tribler_common.simpledefs import DLSTATUS_SEEDING, DLSTATUS_STOPPED, DOWNLOAD, NTFY - from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.components.libtorrent.download_manager.download_state import DownloadState from tribler_core.components.libtorrent.download_manager.stream import Stream @@ -24,7 +21,9 @@ from tribler_core.components.libtorrent.utils.torrent_utils import check_handle, get_info_from_handle, require_handle from tribler_core.exceptions import SaveResumeDataError from tribler_core.notifier import Notifier +from tribler_core.utilities.osutils import fix_filebasename from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING, DLSTATUS_STOPPED, DOWNLOAD, NTFY from tribler_core.utilities.unicode import ensure_unicode, hexlify from tribler_core.utilities.utilities import bdecode_compat diff --git a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py index 61a71e4d827..95bce2fbcb1 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_config.py @@ -4,11 +4,10 @@ from validate import Validator -from tribler_common.osutils import get_home_dir - from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.exceptions import InvalidConfigException from tribler_core.utilities.install_dir import get_lib_path +from tribler_core.utilities.osutils import get_home_dir from tribler_core.utilities.path_util import Path from tribler_core.utilities.utilities import bdecode_compat diff --git a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py index 4dfad6740b3..7df1260d117 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_manager.py @@ -15,17 +15,6 @@ from ipv8.taskmanager import TaskManager, task -from tribler_common.network_utils import default_network_utils -from tribler_common.rest_utils import ( - FILE_SCHEME, - HTTPS_SCHEME, - HTTP_SCHEME, - MAGNET_SCHEME, - scheme_from_uri, - uri_to_path, -) -from tribler_common.simpledefs import DLSTATUS_SEEDING, MAX_LIBTORRENT_RATE_LIMIT, NTFY, STATEDIR_CHECKPOINT_DIR - from tribler_core.components.libtorrent.download_manager.dht_health_manager import DHTHealthManager from tribler_core.components.libtorrent.download_manager.download import Download from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig @@ -35,7 +24,17 @@ from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.notifier import Notifier from tribler_core.utilities import path_util +from tribler_core.utilities.network_utils import default_network_utils from tribler_core.utilities.path_util import Path +from tribler_core.utilities.rest_utils import ( + FILE_SCHEME, + HTTPS_SCHEME, + HTTP_SCHEME, + MAGNET_SCHEME, + scheme_from_uri, + uri_to_path, +) +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING, MAX_LIBTORRENT_RATE_LIMIT, NTFY, STATEDIR_CHECKPOINT_DIR from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import bdecode_compat, has_bep33_support, parse_magnetlink from tribler_core.version import version_id diff --git a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_state.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_state.py index 89cdcb94bcf..64d0f299922 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_state.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/download_state.py @@ -5,7 +5,7 @@ """ import logging -from tribler_common.simpledefs import ( +from tribler_core.utilities.simpledefs import ( DLSTATUS_ALLOCATING_DISKSPACE, DLSTATUS_DOWNLOADING, DLSTATUS_HASHCHECKING, diff --git a/src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py b/src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py index 48fe8413b95..8184bf680d1 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py +++ b/src/tribler-core/tribler_core/components/libtorrent/download_manager/stream.py @@ -20,9 +20,8 @@ import logging from asyncio import sleep -from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING - from tribler_core.components.libtorrent.utils.torrent_utils import check_vod, get_info_from_handle +from tribler_core.utilities.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING # Header and footer sizes are necessary for video client to detect file codecs and muxer metadata. # Without below pieces are ready, streamer should not start diff --git a/src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py b/src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py index 3b85e65cea1..208959df623 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py +++ b/src/tribler-core/tribler_core/components/libtorrent/libtorrent_component.py @@ -1,9 +1,8 @@ -from tribler_common.rest_utils import path_to_uri - from tribler_core.components.base import Component from tribler_core.components.key.key_component import KeyComponent from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.socks_servers.socks_servers_component import SocksServersComponent +from tribler_core.utilities.rest_utils import path_to_uri class LibtorrentComponent(Component): diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py index 2bbc7ee284d..a24fe29b893 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/downloads_endpoint.py @@ -12,15 +12,6 @@ from marshmallow.fields import Boolean, Float, Integer, List, String -from tribler_common.simpledefs import ( - DLSTATUS_CIRCUITS, - DLSTATUS_EXIT_NODES, - DLSTATUS_STOPPED, - DOWNLOAD, - UPLOAD, - dlstatus_strings, -) - from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.libtorrent.download_manager.stream import STREAM_PAUSE_TIME, StreamChunk @@ -35,6 +26,14 @@ ) from tribler_core.components.restapi.rest.util import return_handled_exception from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import ( + DLSTATUS_CIRCUITS, + DLSTATUS_EXIT_NODES, + DLSTATUS_STOPPED, + DOWNLOAD, + UPLOAD, + dlstatus_strings, +) from tribler_core.utilities.unicode import ensure_unicode, hexlify from tribler_core.utilities.utilities import froze_it diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py index 5e814595a06..e728c6de6e1 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_downloads_endpoint.py @@ -8,14 +8,18 @@ import pytest -from tribler_common.rest_utils import HTTP_SCHEME, path_to_uri -from tribler_common.simpledefs import DLSTATUS_CIRCUITS, DLSTATUS_DOWNLOADING, DLSTATUS_EXIT_NODES, DLSTATUS_STOPPED - from tribler_core.components.libtorrent.download_manager.download_state import DownloadState from tribler_core.components.libtorrent.restapi.downloads_endpoint import DownloadsEndpoint, get_extended_status from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.restapi.rest.rest_manager import error_middleware from tribler_core.tests.tools.common import TESTS_DATA_DIR +from tribler_core.utilities.rest_utils import HTTP_SCHEME, path_to_uri +from tribler_core.utilities.simpledefs import ( + DLSTATUS_CIRCUITS, + DLSTATUS_DOWNLOADING, + DLSTATUS_EXIT_NODES, + DLSTATUS_STOPPED, +) from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py index 0a74430d847..ac81693195a 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py @@ -10,9 +10,6 @@ import pytest -from tribler_common.rest_utils import path_to_uri -from tribler_common.simpledefs import NTFY - from tribler_core.components.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint from tribler_core.components.libtorrent.settings import LibtorrentSettings from tribler_core.components.libtorrent.torrentdef import TorrentDef @@ -20,6 +17,8 @@ from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.restapi.rest.rest_manager import error_middleware from tribler_core.tests.tools.common import TESTS_DATA_DIR, TESTS_DIR, TORRENT_UBUNTU_FILE, UBUNTU_1504_INFOHASH +from tribler_core.utilities.rest_utils import path_to_uri +from tribler_core.utilities.simpledefs import NTFY from tribler_core.utilities.unicode import hexlify SAMPLE_CHANNEL_FILES_DIR = TESTS_DIR / "data" / "sample_channel" diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py index d568e9d22b8..c06f1ef8497 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py @@ -10,16 +10,6 @@ from marshmallow.fields import String -from tribler_common.rest_utils import ( - FILE_SCHEME, - HTTPS_SCHEME, - HTTP_SCHEME, - MAGNET_SCHEME, - scheme_from_uri, - uri_to_path, -) -from tribler_common.simpledefs import NTFY - from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt @@ -30,6 +20,15 @@ RESTEndpoint, RESTResponse, ) +from tribler_core.utilities.rest_utils import ( + FILE_SCHEME, + HTTPS_SCHEME, + HTTP_SCHEME, + MAGNET_SCHEME, + scheme_from_uri, + uri_to_path, +) +from tribler_core.utilities.simpledefs import NTFY from tribler_core.utilities.unicode import hexlify, recursive_unicode from tribler_core.utilities.utilities import bdecode_compat, froze_it, parse_magnetlink diff --git a/src/tribler-core/tribler_core/components/libtorrent/settings.py b/src/tribler-core/tribler_core/components/libtorrent/settings.py index 4ec3ade28e2..86d01154664 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/settings.py +++ b/src/tribler-core/tribler_core/components/libtorrent/settings.py @@ -3,11 +3,11 @@ from pydantic import validator -from tribler_common.network_utils import NetworkUtils +from tribler_core.components.libtorrent.download_manager.download_config import get_default_dest_dir +from tribler_core.config.tribler_config_section import TriblerConfigSection +from tribler_core.utilities.network_utils import NetworkUtils # pylint: disable=no-self-argument -from tribler_core.config.tribler_config_section import TriblerConfigSection -from tribler_core.components.libtorrent.download_manager.download_config import get_default_dest_dir @validator('port', 'anon_listen_port') diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py index 21086bd0684..08fd2382446 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py @@ -2,10 +2,9 @@ import pytest -from tribler_common.rest_utils import path_to_uri -from tribler_common.simpledefs import DLSTATUS_DOWNLOADING - from tribler_core.tests.tools.common import TORRENT_UBUNTU_FILE +from tribler_core.utilities.rest_utils import path_to_uri +from tribler_core.utilities.simpledefs import DLSTATUS_DOWNLOADING @pytest.mark.asyncio diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py index b104e53186a..e034f43fe1d 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_manager.py @@ -7,13 +7,12 @@ import pytest -from tribler_common.simpledefs import DLSTATUS_SEEDING - from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.libtorrent.settings import LibtorrentSettings from tribler_core.components.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo from tribler_core.tests.tools.common import TESTS_DATA_DIR, TORRENT_UBUNTU_FILE from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py index 245564e5ed7..82c1fdd4d6b 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_state.py @@ -2,9 +2,8 @@ import pytest -from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DOWNLOAD, UPLOAD - from tribler_core.components.libtorrent.download_manager.download_state import DownloadState +from tribler_core.utilities.simpledefs import DLSTATUS_DOWNLOADING, DOWNLOAD, UPLOAD @pytest.fixture diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py index ad1a838e3f1..97d9c8fd249 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_libtorrent_settings.py @@ -1,8 +1,7 @@ import pytest -from tribler_common.network_utils import NetworkUtils - from tribler_core.components.libtorrent.settings import DownloadDefaultsSettings, LibtorrentSettings, SeedingMode +from tribler_core.utilities.network_utils import NetworkUtils @pytest.mark.asyncio diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py index 6d50a471d95..f9b0d673214 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_seeding.py @@ -5,10 +5,9 @@ """ import pytest -from tribler_common.simpledefs import DLSTATUS_SEEDING - from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.tests.tools.common import TESTS_DATA_DIR +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING @pytest.mark.asyncio diff --git a/src/tribler-core/tribler_core/components/libtorrent/torrentdef.py b/src/tribler-core/tribler_core/components/libtorrent/torrentdef.py index 96cdd927fe1..5535447bbd9 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/torrentdef.py +++ b/src/tribler-core/tribler_core/components/libtorrent/torrentdef.py @@ -6,12 +6,11 @@ import aiohttp -from tribler_common.simpledefs import INFOHASH_LENGTH - -from tribler_core.utilities import maketorrent, path_util from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt -from tribler_core.utilities.path_util import Path from tribler_core.components.libtorrent.utils.torrent_utils import create_torrent_file +from tribler_core.utilities import maketorrent, path_util +from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import INFOHASH_LENGTH from tribler_core.utilities.unicode import ensure_unicode from tribler_core.utilities.utilities import bdecode_compat, is_valid_url, parse_magnetlink diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py index 24e8dcacff3..34f84752e43 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py @@ -7,8 +7,6 @@ from pony import orm from pony.orm import db_session, raw_sql, select -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt from tribler_core.components.metadata_store.db.orm_bindings.channel_node import ( CHANNEL_DESCRIPTION_FLAG, @@ -27,6 +25,7 @@ HealthItemsPayload, ) from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import random_infohash diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py index 4c61929a118..6b7e3716aa2 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/collection_node.py @@ -4,8 +4,6 @@ from pony import orm from pony.orm import db_session, select -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import chunks from tribler_core.components.metadata_store.db.orm_bindings.channel_node import ( @@ -24,9 +22,9 @@ COLLECTION_NODE, CollectionNodePayload, ) +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_core.utilities.utilities import random_infohash - # pylint: disable=too-many-statements diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/store.py b/src/tribler-core/tribler_core/components/metadata_store/db/store.py index ae015cd7627..6704bb62eaa 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/store.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/store.py @@ -11,8 +11,6 @@ from pony import orm from pony.orm import db_session, desc, left_join, raw_sql, select -from tribler_common.simpledefs import NTFY - from tribler_core.components.metadata_store.db.orm_bindings import ( binary_node, channel_description, @@ -50,6 +48,7 @@ from tribler_core.exceptions import InvalidSignatureException from tribler_core.utilities.path_util import Path from tribler_core.utilities.pony_utils import get_or_create +from tribler_core.utilities.simpledefs import NTFY from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import MEMORY_DB diff --git a/src/tribler-core/tribler_core/components/metadata_store/metadata_store_component.py b/src/tribler-core/tribler_core/components/metadata_store/metadata_store_component.py index 1b317b80d14..141f6f2fa08 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/metadata_store_component.py +++ b/src/tribler-core/tribler_core/components/metadata_store/metadata_store_component.py @@ -1,9 +1,8 @@ -from tribler_common.simpledefs import NTFY, STATEDIR_DB_DIR - from tribler_core.components.base import Component from tribler_core.components.key.key_component import KeyComponent from tribler_core.components.metadata_store.db.store import MetadataStore from tribler_core.components.tag.rules.tag_rules_processor import TagRulesProcessor +from tribler_core.utilities.simpledefs import NTFY, STATEDIR_DB_DIR class MetadataStoreComponent(Component): diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py index fa8fae53f73..f2ad41f0f74 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/channels_endpoint.py @@ -15,8 +15,6 @@ from pony.orm import db_session -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.gigachannel.community.gigachannel_community import GigaChannelCommunity from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager @@ -28,6 +26,7 @@ from tribler_core.components.metadata_store.utils import NoChannelSourcesException, RequestTimeoutException from tribler_core.components.restapi.rest.rest_endpoint import HTTP_BAD_REQUEST, HTTP_NOT_FOUND, RESTResponse from tribler_core.components.restapi.rest.schema import HandledErrorSchema +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import froze_it, is_infohash, parse_magnetlink diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py index 4d85220605a..8dc4e1a0dfd 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py @@ -12,8 +12,6 @@ import pytest -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.gigachannel.community.gigachannel_community import NoChannelSourcesException from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.category_filter.family_filter import default_xxx_filter @@ -24,6 +22,7 @@ from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.restapi.rest.rest_manager import error_middleware from tribler_core.tests.tools.common import TORRENT_UBUNTU_FILE +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import random_infohash diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py index db237832b20..c915d97cc54 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py @@ -7,12 +7,11 @@ import pytest -from tribler_common.utilities import to_fts_query - from tribler_core.components.metadata_store.restapi.search_endpoint import SearchEndpoint from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.tag.db.tag_db import TagDatabase -from tribler_core.utilities.utilities import random_infohash +from tribler_core.utilities.utilities import random_infohash, to_fts_query + # pylint: disable=unused-argument, redefined-outer-name diff --git a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py index 8a731c80ce1..280c925b4c8 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py +++ b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_download.py @@ -6,8 +6,6 @@ import pytest -from tribler_common.simpledefs import DLSTATUS_SEEDING - from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager @@ -15,6 +13,7 @@ from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.serialization import ChannelMetadataPayload from tribler_core.tests.tools.common import TESTS_DATA_DIR +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING CHANNEL_DIR = TESTS_DATA_DIR / 'sample_channel' CHANNEL_TORRENT = CHANNEL_DIR / 'channel.torrent' diff --git a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py index 5468b2d049a..38103f601c4 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py +++ b/src/tribler-core/tribler_core/components/metadata_store/tests/test_channel_metadata.py @@ -13,8 +13,6 @@ import pytest -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import ( CHANNEL_DIR_NAME_LENGTH, @@ -30,9 +28,9 @@ ) from tribler_core.components.metadata_store.db.store import HealthItemsPayload from tribler_core.tests.tools.common import TESTS_DATA_DIR, TORRENT_UBUNTU_FILE +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_core.utilities.utilities import random_infohash - # pylint: disable=protected-access diff --git a/src/tribler-core/tribler_core/components/metadata_store/utils.py b/src/tribler-core/tribler_core/components/metadata_store/utils.py index 4ad5a8b48fb..f2d7589a2fe 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/utils.py +++ b/src/tribler-core/tribler_core/components/metadata_store/utils.py @@ -7,11 +7,10 @@ from pony.orm import db_session -from tribler_common.tag_constants import MIN_TAG_LENGTH - from tribler_core.components.metadata_store.db.store import MetadataStore from tribler_core.components.tag.community.tag_payload import TagOperation from tribler_core.components.tag.db.tag_db import TagDatabase, TagOperationEnum +from tribler_core.components.tag.tag_constants import MIN_TAG_LENGTH from tribler_core.tests.tools.common import PNG_FILE from tribler_core.utilities.utilities import random_infohash diff --git a/src/tribler-core/tribler_core/components/payout/payout_component.py b/src/tribler-core/tribler_core/components/payout/payout_component.py index a9709973577..854ad8335aa 100644 --- a/src/tribler-core/tribler_core/components/payout/payout_component.py +++ b/src/tribler-core/tribler_core/components/payout/payout_component.py @@ -1,10 +1,9 @@ -from tribler_common.simpledefs import NTFY - from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler_core.components.base import Component from tribler_core.components.ipv8.ipv8_component import Ipv8Component -from tribler_core.components.reporter.reporter_component import ReporterComponent from tribler_core.components.payout.payout_manager import PayoutManager +from tribler_core.components.reporter.reporter_component import ReporterComponent +from tribler_core.utilities.simpledefs import NTFY INFINITE = -1 diff --git a/src/tribler-core/tribler_core/components/reporter/exception_handler.py b/src/tribler-core/tribler_core/components/reporter/exception_handler.py index 580f9863f37..a87383b0bfd 100644 --- a/src/tribler-core/tribler_core/components/reporter/exception_handler.py +++ b/src/tribler-core/tribler_core/components/reporter/exception_handler.py @@ -7,10 +7,9 @@ from traceback import print_exception from typing import Callable, Optional -from tribler_common.reported_error import ReportedError -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter - from tribler_core.components.base import ComponentStartupException +from tribler_core.components.reporter.reported_error import ReportedError +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter # There are some errors that we are ignoring. IGNORED_ERRORS_BY_CODE = { diff --git a/src/tribler-common/tribler_common/reported_error.py b/src/tribler-core/tribler_core/components/reporter/reported_error.py similarity index 100% rename from src/tribler-common/tribler_common/reported_error.py rename to src/tribler-core/tribler_core/components/reporter/reported_error.py diff --git a/src/tribler-core/tribler_core/components/reporter/tests/test_exception_handler.py b/src/tribler-core/tribler_core/components/reporter/tests/test_exception_handler.py index 438deaf4870..f5ce0c79bae 100644 --- a/src/tribler-core/tribler_core/components/reporter/tests/test_exception_handler.py +++ b/src/tribler-core/tribler_core/components/reporter/tests/test_exception_handler.py @@ -3,10 +3,9 @@ import pytest -from tribler_common.sentry_reporter import sentry_reporter -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter - from tribler_core.components.reporter.exception_handler import CoreExceptionHandler +from tribler_core.sentry_reporter import sentry_reporter +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter # pylint: disable=protected-access, redefined-outer-name # fmt: off diff --git a/src/tribler-core/tribler_core/components/resource_monitor/implementation/core.py b/src/tribler-core/tribler_core/components/resource_monitor/implementation/core.py index c4e22746d5c..48e0f0bae5b 100644 --- a/src/tribler-core/tribler_core/components/resource_monitor/implementation/core.py +++ b/src/tribler-core/tribler_core/components/resource_monitor/implementation/core.py @@ -6,12 +6,11 @@ import psutil -from tribler_common.simpledefs import NTFY - from tribler_core.components.resource_monitor.implementation.base import ResourceMonitor from tribler_core.components.resource_monitor.implementation.profiler import YappiProfiler from tribler_core.components.resource_monitor.settings import ResourceMonitorSettings from tribler_core.notifier import Notifier +from tribler_core.utilities.simpledefs import NTFY FREE_DISK_THRESHOLD = 100 * (1024 * 1024) # 100MB DEFAULT_RESOURCE_FILENAME = "resources.log" diff --git a/src/tribler-core/tribler_core/components/resource_monitor/implementation/tests/test_resource_monitor.py b/src/tribler-core/tribler_core/components/resource_monitor/implementation/tests/test_resource_monitor.py index 658ce7ec68a..86f4901c9d5 100644 --- a/src/tribler-core/tribler_core/components/resource_monitor/implementation/tests/test_resource_monitor.py +++ b/src/tribler-core/tribler_core/components/resource_monitor/implementation/tests/test_resource_monitor.py @@ -6,10 +6,9 @@ import pytest -from tribler_common.simpledefs import NTFY - from tribler_core.components.resource_monitor.implementation.core import CoreResourceMonitor from tribler_core.components.resource_monitor.settings import ResourceMonitorSettings +from tribler_core.utilities.simpledefs import NTFY @pytest.fixture(name="resource_monitor") diff --git a/src/tribler-core/tribler_core/components/restapi/rest/debug_endpoint.py b/src/tribler-core/tribler_core/components/restapi/rest/debug_endpoint.py index 0d1b2c07405..064f033618f 100644 --- a/src/tribler-core/tribler_core/components/restapi/rest/debug_endpoint.py +++ b/src/tribler-core/tribler_core/components/restapi/rest/debug_endpoint.py @@ -15,11 +15,10 @@ import psutil -from tribler_common.osutils import get_root_state_directory - from tribler_core.components.resource_monitor.implementation.base import ResourceMonitor from tribler_core.components.restapi.rest.rest_endpoint import RESTEndpoint, RESTResponse from tribler_core.utilities.instrumentation import WatchDog +from tribler_core.utilities.osutils import get_root_state_directory from tribler_core.utilities.path_util import Path HAS_MELIAE = True diff --git a/src/tribler-core/tribler_core/components/restapi/rest/events_endpoint.py b/src/tribler-core/tribler_core/components/restapi/rest/events_endpoint.py index 68e2b0f5844..bc118a03a07 100644 --- a/src/tribler-core/tribler_core/components/restapi/rest/events_endpoint.py +++ b/src/tribler-core/tribler_core/components/restapi/rest/events_endpoint.py @@ -14,12 +14,11 @@ from marshmallow.fields import Dict, String -from tribler_common.reported_error import ReportedError -from tribler_common.simpledefs import NTFY - +from tribler_core.components.reporter.reported_error import ReportedError from tribler_core.components.restapi.rest.rest_endpoint import RESTEndpoint, RESTStreamResponse from tribler_core.components.restapi.rest.util import fix_unicode_dict from tribler_core.notifier import Notifier +from tribler_core.utilities.simpledefs import NTFY from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import froze_it from tribler_core.version import version_id diff --git a/src/tribler-core/tribler_core/components/restapi/rest/settings_endpoint.py b/src/tribler-core/tribler_core/components/restapi/rest/settings_endpoint.py index f091c02fb89..d25c35205a7 100644 --- a/src/tribler-core/tribler_core/components/restapi/rest/settings_endpoint.py +++ b/src/tribler-core/tribler_core/components/restapi/rest/settings_endpoint.py @@ -6,11 +6,10 @@ from marshmallow.fields import Boolean -from tribler_common.network_utils import default_network_utils - from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.restapi.rest.rest_endpoint import RESTEndpoint, RESTResponse from tribler_core.config.tribler_config import TriblerConfig +from tribler_core.utilities.network_utils import default_network_utils from tribler_core.utilities.utilities import froze_it diff --git a/src/tribler-core/tribler_core/components/restapi/rest/tests/test_events_endpoint.py b/src/tribler-core/tribler_core/components/restapi/rest/tests/test_events_endpoint.py index 3d6407407a0..1b6e30024cf 100644 --- a/src/tribler-core/tribler_core/components/restapi/rest/tests/test_events_endpoint.py +++ b/src/tribler-core/tribler_core/components/restapi/rest/tests/test_events_endpoint.py @@ -9,15 +9,14 @@ import pytest -from tribler_common.reported_error import ReportedError -from tribler_common.simpledefs import NTFY - +from tribler_core.components.reporter.reported_error import ReportedError from tribler_core.components.restapi.rest.events_endpoint import EventsEndpoint from tribler_core.components.restapi.rest.rest_endpoint import RESTStreamResponse from tribler_core.components.restapi.rest.rest_manager import ApiKeyMiddleware, RESTManager, error_middleware from tribler_core.components.restapi.rest.root_endpoint import RootEndpoint from tribler_core.config.tribler_config import TriblerConfig from tribler_core.notifier import Notifier +from tribler_core.utilities.simpledefs import NTFY from tribler_core.version import version_id messages_to_wait_for = set() diff --git a/src/tribler-core/tribler_core/components/restapi/rest/tests/test_settings_endpoint.py b/src/tribler-core/tribler_core/components/restapi/rest/tests/test_settings_endpoint.py index 5bb0a3fbdaf..e9ee64102a3 100644 --- a/src/tribler-core/tribler_core/components/restapi/rest/tests/test_settings_endpoint.py +++ b/src/tribler-core/tribler_core/components/restapi/rest/tests/test_settings_endpoint.py @@ -3,13 +3,12 @@ import pytest -from tribler_common.simpledefs import MAX_LIBTORRENT_RATE_LIMIT - from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.restapi.rest.rest_manager import error_middleware from tribler_core.components.restapi.rest.settings_endpoint import SettingsEndpoint from tribler_core.config.tribler_config import TriblerConfig +from tribler_core.utilities.simpledefs import MAX_LIBTORRENT_RATE_LIMIT @pytest.fixture diff --git a/src/tribler-core/tribler_core/components/restapi/restapi_component.py b/src/tribler-core/tribler_core/components/restapi/restapi_component.py index 2542d396c41..1a5289564b6 100644 --- a/src/tribler-core/tribler_core/components/restapi/restapi_component.py +++ b/src/tribler-core/tribler_core/components/restapi/restapi_component.py @@ -3,8 +3,6 @@ from ipv8.REST.root_endpoint import RootEndpoint as IPV8RootEndpoint -from tribler_common.reported_error import ReportedError - from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler_core.components.bandwidth_accounting.restapi.bandwidth_endpoint import BandwidthEndpoint from tribler_core.components.base import Component, NoneComponent @@ -23,6 +21,7 @@ from tribler_core.components.metadata_store.restapi.remote_query_endpoint import RemoteQueryEndpoint from tribler_core.components.metadata_store.restapi.search_endpoint import SearchEndpoint from tribler_core.components.reporter.exception_handler import CoreExceptionHandler, default_core_exception_handler +from tribler_core.components.reporter.reported_error import ReportedError from tribler_core.components.reporter.reporter_component import ReporterComponent from tribler_core.components.resource_monitor.resource_monitor_component import ResourceMonitorComponent from tribler_core.components.restapi.rest.debug_endpoint import DebugEndpoint diff --git a/src/tribler-core/tribler_core/components/restapi/tests/test_restapi_component.py b/src/tribler-core/tribler_core/components/restapi/tests/test_restapi_component.py index f9d35e3123f..d2ce95dc342 100644 --- a/src/tribler-core/tribler_core/components/restapi/tests/test_restapi_component.py +++ b/src/tribler-core/tribler_core/components/restapi/tests/test_restapi_component.py @@ -2,8 +2,6 @@ import pytest -from tribler_common.reported_error import ReportedError - from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler_core.components.base import NoneComponent, Session from tribler_core.components.gigachannel.gigachannel_component import GigaChannelComponent @@ -11,6 +9,7 @@ from tribler_core.components.key.key_component import KeyComponent from tribler_core.components.libtorrent.libtorrent_component import LibtorrentComponent from tribler_core.components.metadata_store.metadata_store_component import MetadataStoreComponent +from tribler_core.components.reporter.reported_error import ReportedError from tribler_core.components.resource_monitor.resource_monitor_component import ResourceMonitorComponent from tribler_core.components.restapi.rest.rest_endpoint import RESTEndpoint from tribler_core.components.restapi.restapi_component import RESTComponent diff --git a/src/tribler-core/tribler_core/components/socks_servers/socks_servers_component.py b/src/tribler-core/tribler_core/components/socks_servers/socks_servers_component.py index a33a3b2a47b..0fc1562f134 100644 --- a/src/tribler-core/tribler_core/components/socks_servers/socks_servers_component.py +++ b/src/tribler-core/tribler_core/components/socks_servers/socks_servers_component.py @@ -1,10 +1,9 @@ from typing import List -from tribler_common.network_utils import default_network_utils - from tribler_core.components.base import Component from tribler_core.components.reporter.reporter_component import ReporterComponent from tribler_core.components.socks_servers.socks5.server import Socks5Server +from tribler_core.utilities.network_utils import default_network_utils NUM_SOCKS_PROXIES = 5 diff --git a/src/tribler-core/tribler_core/components/tag/community/tag_validator.py b/src/tribler-core/tribler_core/components/tag/community/tag_validator.py index 8f1049f8d40..4bd49bf05bb 100644 --- a/src/tribler-core/tribler_core/components/tag/community/tag_validator.py +++ b/src/tribler-core/tribler_core/components/tag/community/tag_validator.py @@ -1,6 +1,5 @@ -from tribler_common.tag_constants import MAX_TAG_LENGTH, MIN_TAG_LENGTH - from tribler_core.components.tag.community.tag_payload import TagOperationEnum +from tribler_core.components.tag.tag_constants import MAX_TAG_LENGTH, MIN_TAG_LENGTH def validate_tag(tag: str): diff --git a/src/tribler-core/tribler_core/components/tag/restapi/tags_endpoint.py b/src/tribler-core/tribler_core/components/tag/restapi/tags_endpoint.py index 727a449a874..52a06b7717b 100644 --- a/src/tribler-core/tribler_core/components/tag/restapi/tags_endpoint.py +++ b/src/tribler-core/tribler_core/components/tag/restapi/tags_endpoint.py @@ -12,13 +12,12 @@ from pony.orm import db_session -from tribler_common.tag_constants import MAX_TAG_LENGTH, MIN_TAG_LENGTH - from tribler_core.components.restapi.rest.rest_endpoint import HTTP_BAD_REQUEST, RESTEndpoint, RESTResponse from tribler_core.components.restapi.rest.schema import HandledErrorSchema from tribler_core.components.tag.community.tag_community import TagCommunity from tribler_core.components.tag.community.tag_payload import TagOperation from tribler_core.components.tag.db.tag_db import TagDatabase, TagOperationEnum +from tribler_core.components.tag.tag_constants import MAX_TAG_LENGTH, MIN_TAG_LENGTH from tribler_core.utilities.utilities import froze_it diff --git a/src/tribler-core/tribler_core/components/tag/tag_component.py b/src/tribler-core/tribler_core/components/tag/tag_component.py index 07898e33e85..919a42c6d01 100644 --- a/src/tribler-core/tribler_core/components/tag/tag_component.py +++ b/src/tribler-core/tribler_core/components/tag/tag_component.py @@ -1,5 +1,3 @@ -from tribler_common.simpledefs import STATEDIR_DB_DIR - import tribler_core.components.metadata_store.metadata_store_component as metadata_store_component from tribler_core.components.base import Component from tribler_core.components.ipv8.ipv8_component import Ipv8Component @@ -8,6 +6,7 @@ from tribler_core.components.tag.community.tag_community import TagCommunity from tribler_core.components.tag.db.tag_db import TagDatabase from tribler_core.components.tag.rules.tag_rules_processor import TagRulesProcessor +from tribler_core.utilities.simpledefs import STATEDIR_DB_DIR class TagComponent(Component): diff --git a/src/tribler-common/tribler_common/tag_constants.py b/src/tribler-core/tribler_core/components/tag/tag_constants.py similarity index 100% rename from src/tribler-common/tribler_common/tag_constants.py rename to src/tribler-core/tribler_core/components/tag/tag_constants.py diff --git a/src/tribler-core/tribler_core/components/torrent_checker/torrent_checker/torrent_checker.py b/src/tribler-core/tribler_core/components/torrent_checker/torrent_checker/torrent_checker.py index a5545099eb1..2d61f1ac026 100644 --- a/src/tribler-core/tribler_core/components/torrent_checker/torrent_checker/torrent_checker.py +++ b/src/tribler-core/tribler_core/components/torrent_checker/torrent_checker/torrent_checker.py @@ -9,8 +9,6 @@ from pony.orm import db_session, desc, select -from tribler_common.simpledefs import NTFY - from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.metadata_store.db.serialization import REGULAR_TORRENT from tribler_core.components.metadata_store.db.store import MetadataStore @@ -23,6 +21,7 @@ from tribler_core.components.torrent_checker.torrent_checker.tracker_manager import MAX_TRACKER_FAILURES, TrackerManager from tribler_core.config.tribler_config import TriblerConfig from tribler_core.notifier import Notifier +from tribler_core.utilities.simpledefs import NTFY from tribler_core.utilities.tracker_utils import MalformedTrackerURLException from tribler_core.utilities.unicode import hexlify from tribler_core.utilities.utilities import has_bep33_support, is_valid_url diff --git a/src/tribler-core/tribler_core/components/tunnel/community/tunnel_community.py b/src/tribler-core/tribler_core/components/tunnel/community/tunnel_community.py index 55c472b80ff..06840de0a71 100644 --- a/src/tribler-core/tribler_core/components/tunnel/community/tunnel_community.py +++ b/src/tribler-core/tribler_core/components/tunnel/community/tunnel_community.py @@ -32,8 +32,6 @@ from ipv8.types import Address from ipv8.util import succeed -from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_METADATA, DLSTATUS_SEEDING, DLSTATUS_STOPPED, NTFY - from tribler_core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData from tribler_core.components.socks_servers.socks5.server import Socks5Server from tribler_core.components.tunnel.community.caches import BalanceRequestCache, HTTPRequestCache @@ -49,6 +47,13 @@ RelayBalanceResponsePayload, ) from tribler_core.utilities.bencodecheck import is_bencoded +from tribler_core.utilities.simpledefs import ( + DLSTATUS_DOWNLOADING, + DLSTATUS_METADATA, + DLSTATUS_SEEDING, + DLSTATUS_STOPPED, + NTFY, +) from tribler_core.utilities.unicode import hexlify DESTROY_REASON_BALANCE = 65535 diff --git a/src/tribler-core/tribler_core/components/tunnel/settings.py b/src/tribler-core/tribler_core/components/tunnel/settings.py index 594ec7095a5..0a869f777f3 100644 --- a/src/tribler-core/tribler_core/components/tunnel/settings.py +++ b/src/tribler-core/tribler_core/components/tunnel/settings.py @@ -1,4 +1,3 @@ - from pydantic import Field from tribler_core.config.tribler_config_section import TriblerConfigSection diff --git a/src/tribler-core/tribler_core/components/tunnel/tests/test_full_session/test_tunnel_community.py b/src/tribler-core/tribler_core/components/tunnel/tests/test_full_session/test_tunnel_community.py index 2fedd7a0b2f..d3875660165 100644 --- a/src/tribler-core/tribler_core/components/tunnel/tests/test_full_session/test_tunnel_community.py +++ b/src/tribler-core/tribler_core/components/tunnel/tests/test_full_session/test_tunnel_community.py @@ -9,7 +9,7 @@ from asynctest import Mock -from ipv8.messaging.anonymization.tunnel import CIRCUIT_TYPE_IP_SEEDER, PEER_FLAG_EXIT_BT +from ipv8.messaging.anonymization.tunnel import PEER_FLAG_EXIT_BT from ipv8.peer import Peer from ipv8.test.messaging.anonymization import test_community from ipv8.test.messaging.anonymization.mock import MockDHTProvider @@ -18,8 +18,6 @@ import pytest -from tribler_common.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING, dlstatus_strings - # Pylint does not agree with the way pytest handles fixtures. # pylint: disable=W0613,W0621 from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig @@ -31,7 +29,7 @@ from tribler_core.components.tunnel.community.tunnel_community import TriblerTunnelCommunity from tribler_core.components.tunnel.settings import TunnelCommunitySettings from tribler_core.tests.tools.common import TESTS_DATA_DIR -from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING, dlstatus_strings def crash_on_error(): diff --git a/src/tribler-core/tribler_core/components/tunnel/tests/test_triblertunnel_community.py b/src/tribler-core/tribler_core/components/tunnel/tests/test_triblertunnel_community.py index c3e9ccd286e..aa61b5de97f 100644 --- a/src/tribler-core/tribler_core/components/tunnel/tests/test_triblertunnel_community.py +++ b/src/tribler-core/tribler_core/components/tunnel/tests/test_triblertunnel_community.py @@ -19,17 +19,17 @@ from ipv8.test.mocking.ipv8 import MockIPv8 from ipv8.util import succeed -from tribler_common.network_utils import NetworkUtils - -from tribler_core.components.bandwidth_accounting.community.bandwidth_accounting_community \ - import BandwidthAccountingCommunity +from tribler_core.components.bandwidth_accounting.community.bandwidth_accounting_community import ( + BandwidthAccountingCommunity, +) from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase from tribler_core.components.bandwidth_accounting.settings import BandwidthAccountingSettings -from tribler_core.components.tunnel.community.tunnel_community import PEER_FLAG_EXIT_HTTP, TriblerTunnelCommunity from tribler_core.components.tunnel.community.payload import BandwidthTransactionPayload +from tribler_core.components.tunnel.community.tunnel_community import PEER_FLAG_EXIT_HTTP, TriblerTunnelCommunity from tribler_core.components.tunnel.settings import TunnelCommunitySettings from tribler_core.tests.tools.base_test import MockObject from tribler_core.tests.tools.tracker.http_tracker import HTTPTracker +from tribler_core.utilities.network_utils import NetworkUtils from tribler_core.utilities.path_util import Path from tribler_core.utilities.utilities import MEMORY_DB diff --git a/src/tribler-core/tribler_core/components/tunnel/tests/test_tunnel_settings.py b/src/tribler-core/tribler_core/components/tunnel/tests/test_tunnel_settings.py index 318ba15bbf0..8dcf98e9955 100644 --- a/src/tribler-core/tribler_core/components/tunnel/tests/test_tunnel_settings.py +++ b/src/tribler-core/tribler_core/components/tunnel/tests/test_tunnel_settings.py @@ -1,7 +1,7 @@ import pytest -from tribler_common.network_utils import NetworkUtils from tribler_core.components.ipv8.settings import Ipv8Settings +from tribler_core.utilities.network_utils import NetworkUtils @pytest.mark.asyncio diff --git a/src/tribler-core/tribler_core/components/version_check/versioncheck_manager.py b/src/tribler-core/tribler_core/components/version_check/versioncheck_manager.py index 7a8e350a98a..e68c7a992f7 100644 --- a/src/tribler-core/tribler_core/components/version_check/versioncheck_manager.py +++ b/src/tribler-core/tribler_core/components/version_check/versioncheck_manager.py @@ -6,9 +6,8 @@ from ipv8.taskmanager import TaskManager -from tribler_common.simpledefs import NTFY - from tribler_core.notifier import Notifier +from tribler_core.utilities.simpledefs import NTFY from tribler_core.version import version_id VERSION_CHECK_URLS = [f'https://release.tribler.org/releases/latest?current={version_id}', # Tribler Release API diff --git a/src/tribler-core/tribler_core/components/watch_folder/settings.py b/src/tribler-core/tribler_core/components/watch_folder/settings.py index 2b875b62121..c9fcb30b3f7 100644 --- a/src/tribler-core/tribler_core/components/watch_folder/settings.py +++ b/src/tribler-core/tribler_core/components/watch_folder/settings.py @@ -1,6 +1,5 @@ from tribler_core.config.tribler_config_section import TriblerConfigSection - # pylint: disable=no-self-argument diff --git a/src/tribler-core/tribler_core/components/watch_folder/watch_folder.py b/src/tribler-core/tribler_core/components/watch_folder/watch_folder.py index ed69c4902f0..890d80da31a 100644 --- a/src/tribler-core/tribler_core/components/watch_folder/watch_folder.py +++ b/src/tribler-core/tribler_core/components/watch_folder/watch_folder.py @@ -4,12 +4,11 @@ from ipv8.taskmanager import TaskManager -from tribler_common.simpledefs import NTFY - from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.notifier import Notifier from tribler_core.utilities import path_util +from tribler_core.utilities.simpledefs import NTFY WATCH_FOLDER_CHECK_INTERVAL = 10 diff --git a/src/tribler-core/tribler_core/conftest.py b/src/tribler-core/tribler_core/conftest.py index a4329f76c09..ae10944d862 100644 --- a/src/tribler-core/tribler_core/conftest.py +++ b/src/tribler-core/tribler_core/conftest.py @@ -11,9 +11,6 @@ import pytest -from tribler_common.network_utils import default_network_utils -from tribler_common.simpledefs import DLSTATUS_SEEDING - from tribler_core.components.libtorrent.download_manager.download import Download from tribler_core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager @@ -24,6 +21,8 @@ from tribler_core.config.tribler_config import TriblerConfig from tribler_core.tests.tools.common import TESTS_DATA_DIR, TESTS_DIR from tribler_core.tests.tools.tracker.udp_tracker import UDPTracker +from tribler_core.utilities.network_utils import default_network_utils +from tribler_core.utilities.simpledefs import DLSTATUS_SEEDING from tribler_core.utilities.unicode import hexlify diff --git a/src/tribler-common/tribler_common/tests/__init__.py b/src/tribler-core/tribler_core/logger/__init__.py similarity index 100% rename from src/tribler-common/tribler_common/tests/__init__.py rename to src/tribler-core/tribler_core/logger/__init__.py diff --git a/src/tribler-common/tribler_common/logger.py b/src/tribler-core/tribler_core/logger/logger.py similarity index 93% rename from src/tribler-common/tribler_common/logger.py rename to src/tribler-core/tribler_core/logger/logger.py index 3fd86b12a53..417f50b9d99 100644 --- a/src/tribler-common/tribler_common/logger.py +++ b/src/tribler-core/tribler_core/logger/logger.py @@ -11,7 +11,7 @@ logger = logging.getLogger(__name__) -# note: this class is used by src/tribler-common/tribler_common/logger.yaml +# note: this class is used by logger.yaml class StdoutFilter(logging.Filter): def filter(self, record): return record.levelno < logging.ERROR @@ -30,7 +30,7 @@ def get_logger_config_path(): if not hasattr(sys, '_MEIPASS'): dirname = Path(__file__).absolute().parent else: - dirname = Path(getattr(sys, '_MEIPASS'), "tribler_source", "tribler_common") + dirname = Path(getattr(sys, '_MEIPASS')) / "tribler_source/tribler_core/logger" return dirname / LOG_CONFIG_FILENAME diff --git a/src/tribler-common/tribler_common/logger.yaml b/src/tribler-core/tribler_core/logger/logger.yaml similarity index 89% rename from src/tribler-common/tribler_common/logger.yaml rename to src/tribler-core/tribler_core/logger/logger.yaml index a7b0a2078bd..53acc5a2321 100644 --- a/src/tribler-common/tribler_common/logger.yaml +++ b/src/tribler-core/tribler_core/logger/logger.yaml @@ -4,7 +4,7 @@ version: 1 disable_existing_loggers: false filters: stdout_filter: - () : tribler_common.logger.StdoutFilter + () : tribler_core.logger.logger.StdoutFilter # Logging formatter formatters: @@ -50,13 +50,13 @@ handlers: level: INFO formatter: standard filters: [stdout_filter] - stream: ext://tribler_common.logger_streams.stdout_wrapper + stream: ext://tribler_core.logger.logger_streams.stdout_wrapper stderr_handler: class: logging.StreamHandler level: ERROR formatter: error - stream: ext://tribler_common.logger_streams.stderr_wrapper + stream: ext://tribler_core.logger.logger_streams.stderr_wrapper # Root Logger Configuration root: diff --git a/src/tribler-common/tribler_common/logger_streams.py b/src/tribler-core/tribler_core/logger/logger_streams.py similarity index 100% rename from src/tribler-common/tribler_common/logger_streams.py rename to src/tribler-core/tribler_core/logger/logger_streams.py diff --git a/src/tribler-core/tribler_core/logger/tests/__init__.py b/src/tribler-core/tribler_core/logger/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-common/tribler_common/tests/test_logger.py b/src/tribler-core/tribler_core/logger/tests/test_logger.py similarity index 91% rename from src/tribler-common/tribler_common/tests/test_logger.py rename to src/tribler-core/tribler_core/logger/tests/test_logger.py index 3ece58cfb9a..1141de7df10 100644 --- a/src/tribler-common/tribler_common/tests/test_logger.py +++ b/src/tribler-core/tribler_core/logger/tests/test_logger.py @@ -2,11 +2,11 @@ from io import BytesIO, TextIOWrapper from unittest.mock import MagicMock, Mock, call, patch -from tribler_common.logger import get_logger_config_path, setup_logging -from tribler_common.logger_streams import StreamWrapper +from tribler_core.logger.logger import get_logger_config_path, setup_logging +from tribler_core.logger.logger_streams import StreamWrapper -@patch('tribler_common.logger.__file__', '/a/b/c/logger.py') +@patch('tribler_core.logger.logger.__file__', '/a/b/c/logger.py') def test_get_logger_config_path(): config_path = get_logger_config_path() # take the last part of the path to ignore a drive name on Windows @@ -14,10 +14,10 @@ def test_get_logger_config_path(): with patch('sys._MEIPASS', '/x/y/z/', create=True): config_path = get_logger_config_path() - assert config_path.parts[-6:] == ('x', 'y', 'z', 'tribler_source', 'tribler_common', 'logger.yaml') + assert config_path.parts[-7:] == ('x', 'y', 'z', 'tribler_source', 'tribler_core', 'logger', 'logger.yaml') -@patch('tribler_common.logger.logger') +@patch('tribler_core.logger.logger.logger') @patch('sys.stdout') @patch('sys.stderr') @patch('builtins.print') @@ -38,7 +38,7 @@ def test_setup_logging_no_config(basic_config: Mock, print_: Mock, stderr: Mock, @patch('yaml.safe_load') @patch('logging.config.dictConfig') -@patch('tribler_common.logger.logger') +@patch('tribler_core.logger.logger.logger') def test_setup_logging(logger: Mock, dict_config: Mock, yaml_safe_load: Mock): log_dir = MagicMock() log_dir.__str__.return_value = '' @@ -66,7 +66,7 @@ def test_setup_logging(logger: Mock, dict_config: Mock, yaml_safe_load: Mock): ) -@patch('tribler_common.logger.logger') +@patch('tribler_core.logger.logger.logger') @patch('sys.stdout') @patch('sys.stderr') @patch('builtins.print') diff --git a/src/tribler-core/tribler_core/requirements.txt b/src/tribler-core/tribler_core/requirements.txt index f043d25a03e..3d40ff40b9d 100644 --- a/src/tribler-core/tribler_core/requirements.txt +++ b/src/tribler-core/tribler_core/requirements.txt @@ -21,3 +21,5 @@ sentry-sdk==1.5.0 service-identity==21.1.0 yappi==1.3.3 yarl==1.7.2 # keep this dependency higher than 1.6.3. See: https://github.com/aio-libs/yarl/issues/517 +Faker==9.8.2 +sentry-sdk==1.5.0 \ No newline at end of file diff --git a/src/tribler-core/tribler_core/sentry_reporter/__init__.py b/src/tribler-core/tribler_core/sentry_reporter/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-common/tribler_common/sentry_reporter/sentry_reporter.py b/src/tribler-core/tribler_core/sentry_reporter/sentry_reporter.py similarity index 99% rename from src/tribler-common/tribler_common/sentry_reporter/sentry_reporter.py rename to src/tribler-core/tribler_core/sentry_reporter/sentry_reporter.py index 659fe937ef5..ee0de527f64 100644 --- a/src/tribler-common/tribler_common/sentry_reporter/sentry_reporter.py +++ b/src/tribler-core/tribler_core/sentry_reporter/sentry_reporter.py @@ -13,7 +13,7 @@ from sentry_sdk.integrations.logging import LoggingIntegration, ignore_logger from sentry_sdk.integrations.threading import ThreadingIntegration -from tribler_common.sentry_reporter.sentry_tools import ( +from tribler_core.sentry_reporter.sentry_tools import ( delete_item, extract_dict, get_first_item, @@ -244,7 +244,6 @@ def get_confirmation(self, exception): Args: exception: exception to be sent. """ - # Prevent importing PyQt globally in tribler-common module. # pylint: disable=import-outside-toplevel try: from PyQt5.QtWidgets import QApplication, QMessageBox diff --git a/src/tribler-common/tribler_common/sentry_reporter/sentry_scrubber.py b/src/tribler-core/tribler_core/sentry_reporter/sentry_scrubber.py similarity index 97% rename from src/tribler-common/tribler_common/sentry_reporter/sentry_scrubber.py rename to src/tribler-core/tribler_core/sentry_reporter/sentry_scrubber.py index 03eeb36671f..417da4b7149 100644 --- a/src/tribler-common/tribler_common/sentry_reporter/sentry_scrubber.py +++ b/src/tribler-core/tribler_core/sentry_reporter/sentry_scrubber.py @@ -1,11 +1,11 @@ import re -from tribler_common.sentry_reporter.sentry_reporter import ( +from tribler_core.sentry_reporter.sentry_reporter import ( BREADCRUMBS, RELEASE, VALUES, ) -from tribler_common.sentry_reporter.sentry_tools import delete_item, distinct_by, format_version, modify_value +from tribler_core.sentry_reporter.sentry_tools import delete_item, distinct_by, format_version, modify_value class SentryScrubber: diff --git a/src/tribler-common/tribler_common/sentry_reporter/sentry_tools.py b/src/tribler-core/tribler_core/sentry_reporter/sentry_tools.py similarity index 100% rename from src/tribler-common/tribler_common/sentry_reporter/sentry_tools.py rename to src/tribler-core/tribler_core/sentry_reporter/sentry_tools.py diff --git a/src/tribler-core/tribler_core/sentry_reporter/tests/__init__.py b/src/tribler-core/tribler_core/sentry_reporter/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_reporter.py b/src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_reporter.py similarity index 95% rename from src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_reporter.py rename to src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_reporter.py index 0ff6c3785dd..0f38aa69331 100644 --- a/src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_reporter.py +++ b/src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_reporter.py @@ -2,8 +2,8 @@ import pytest -from tribler_common.patch_import import patch_import -from tribler_common.sentry_reporter.sentry_reporter import ( +from tribler_core.utilities.patch_import import patch_import +from tribler_core.sentry_reporter.sentry_reporter import ( EXCEPTION, OS_ENVIRON, PLATFORM_DETAILS, @@ -12,7 +12,7 @@ VALUES, this_sentry_strategy, ) -from tribler_common.sentry_reporter.sentry_scrubber import SentryScrubber +from tribler_core.sentry_reporter.sentry_scrubber import SentryScrubber # fmt: off # pylint: disable=redefined-outer-name, protected-access @@ -23,7 +23,7 @@ def sentry_reporter(): return SentryReporter() -@patch('tribler_common.sentry_reporter.sentry_reporter.sentry_sdk.init') +@patch('tribler_core.sentry_reporter.sentry_reporter.sentry_sdk.init') def test_init(mocked_init: Mock, sentry_reporter: SentryReporter): # test that `init` method set all necessary variables and calls `sentry_sdk.init()` sentry_reporter.init(sentry_url='url', release_version='release', scrubber=SentryScrubber(), @@ -33,14 +33,14 @@ def test_init(mocked_init: Mock, sentry_reporter: SentryReporter): mocked_init.assert_called_once() -@patch('tribler_common.sentry_reporter.sentry_reporter.ignore_logger') +@patch('tribler_core.sentry_reporter.sentry_reporter.ignore_logger') def test_ignore_logger(mocked_ignore_logger: Mock, sentry_reporter: SentryReporter): # test that `ignore_logger` calls `ignore_logger` from sentry_sdk sentry_reporter.ignore_logger('logger name') mocked_ignore_logger.assert_called_with('logger name') -@patch('tribler_common.sentry_reporter.sentry_reporter.sentry_sdk.add_breadcrumb') +@patch('tribler_core.sentry_reporter.sentry_reporter.sentry_sdk.add_breadcrumb') def test_add_breadcrumb(mocked_add_breadcrumb: Mock, sentry_reporter: SentryReporter): # test that `add_breadcrumb` passes all necessary arguments to `sentry_sdk` assert sentry_reporter.add_breadcrumb('message', 'category', 'level', named_arg='some') @@ -64,7 +64,7 @@ def test_get_confirmation_no_qt(sentry_reporter: SentryReporter): assert not sentry_reporter.get_confirmation(Exception('test')) -@patch('tribler_common.sentry_reporter.sentry_reporter.sentry_sdk.capture_exception') +@patch('tribler_core.sentry_reporter.sentry_reporter.sentry_sdk.capture_exception') def test_capture_exception(mocked_capture_exception: Mock, sentry_reporter: SentryReporter): # test that `capture_exception` passes an exception to `sentry_sdk` exception = Exception('test') @@ -72,7 +72,7 @@ def test_capture_exception(mocked_capture_exception: Mock, sentry_reporter: Sent mocked_capture_exception.assert_called_with(exception) -@patch('tribler_common.sentry_reporter.sentry_reporter.sentry_sdk.capture_exception') +@patch('tribler_core.sentry_reporter.sentry_reporter.sentry_sdk.capture_exception') def test_event_from_exception(mocked_capture_exception: Mock, sentry_reporter: SentryReporter): # test that `event_from_exception` returns '{}' in case of an empty exception assert sentry_reporter.event_from_exception(None) == {} diff --git a/src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_scrubber.py b/src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_scrubber.py similarity index 98% rename from src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_scrubber.py rename to src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_scrubber.py index 5b4499a3890..9aaf69ed291 100644 --- a/src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_scrubber.py +++ b/src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_scrubber.py @@ -1,6 +1,6 @@ import pytest -from tribler_common.sentry_reporter.sentry_reporter import ( +from tribler_core.sentry_reporter.sentry_reporter import ( BREADCRUMBS, CONTEXTS, EXTRA, @@ -11,7 +11,7 @@ SYSINFO, SYS_ARGV, ) -from tribler_common.sentry_reporter.sentry_scrubber import SentryScrubber +from tribler_core.sentry_reporter.sentry_scrubber import SentryScrubber @pytest.fixture(name="scrubber") # this workaround implemented only for pylint diff --git a/src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_tools.py b/src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_tools.py similarity index 98% rename from src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_tools.py rename to src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_tools.py index eaffb67ee58..fc2db6b9f6b 100644 --- a/src/tribler-common/tribler_common/sentry_reporter/tests/test_sentry_tools.py +++ b/src/tribler-core/tribler_core/sentry_reporter/tests/test_sentry_tools.py @@ -1,4 +1,4 @@ -from tribler_common.sentry_reporter.sentry_tools import ( +from tribler_core.sentry_reporter.sentry_tools import ( delete_item, distinct_by, extract_dict, diff --git a/src/tribler-core/tribler_core/start_core.py b/src/tribler-core/tribler_core/start_core.py index 6215e37bf07..acdb057d269 100644 --- a/src/tribler-core/tribler_core/start_core.py +++ b/src/tribler-core/tribler_core/start_core.py @@ -6,12 +6,6 @@ import sys from typing import List -from tribler_common.logger import load_logger_config -from tribler_common.process_checker import ProcessChecker -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter, SentryStrategy -from tribler_common.simpledefs import NTFY -from tribler_common.version_manager import VersionHistory - from tribler_core.check_os import ( check_and_enable_code_tracing, set_process_priority, @@ -38,6 +32,11 @@ from tribler_core.components.version_check.version_check_component import VersionCheckComponent from tribler_core.components.watch_folder.watch_folder_component import WatchFolderComponent from tribler_core.config.tribler_config import TriblerConfig +from tribler_core.logger.logger import load_logger_config +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter, SentryStrategy +from tribler_core.upgrade.version_manager import VersionHistory +from tribler_core.utilities.process_checker import ProcessChecker +from tribler_core.utilities.simpledefs import NTFY logger = logging.getLogger(__name__) CONFIG_FILE_NAME = 'triblerd.conf' diff --git a/src/tribler-core/tribler_core/tests/test_check_os.py b/src/tribler-core/tribler_core/tests/test_check_os.py index 4d7c15b8a67..9752b4a390d 100644 --- a/src/tribler-core/tribler_core/tests/test_check_os.py +++ b/src/tribler-core/tribler_core/tests/test_check_os.py @@ -5,9 +5,8 @@ import pytest -from tribler_common.patch_import import patch_import - from tribler_core.check_os import enable_fault_handler, error_and_exit, should_kill_other_tribler_instances +from tribler_core.utilities.patch_import import patch_import # pylint: disable=import-outside-toplevel # fmt: off diff --git a/src/tribler-core/tribler_core/tests/test_start_core.py b/src/tribler-core/tribler_core/tests/test_start_core.py index 1e5a20b6674..c1f21920285 100644 --- a/src/tribler-core/tribler_core/tests/test_start_core.py +++ b/src/tribler-core/tribler_core/tests/test_start_core.py @@ -7,7 +7,7 @@ # fmt: off -@patch('tribler_common.logger.load_logger_config', new=MagicMock()) +@patch('tribler_core.logger.logger.load_logger_config', new=MagicMock()) @patch('tribler_core.start_core.set_process_priority', new=MagicMock()) @patch('tribler_core.start_core.check_and_enable_code_tracing', new=MagicMock()) @patch('asyncio.get_event_loop', new=MagicMock()) diff --git a/src/tribler-core/tribler_core/tests/test_utilities.py b/src/tribler-core/tribler_core/tests/test_utilities.py deleted file mode 100644 index 333f81cfbcf..00000000000 --- a/src/tribler-core/tribler_core/tests/test_utilities.py +++ /dev/null @@ -1,47 +0,0 @@ -import logging - -from tribler_common.logger import load_logger_config - -from tribler_core.utilities.tracker_utils import add_url_params -from tribler_core.utilities.utilities import parse_magnetlink - - -def test_parse_magnetlink_valid(): - result = parse_magnetlink("magnet:?xt=urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1&xl=10826029&dn=mediawiki-1.15.1" - ".tar.gz&xt=urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY&xt=urn:btih:QHQXPY" - "WMACKDWKP47RRVIV7VOURXFE5Q&tr=http%3A%2F%2Ftracker.example.org%2Fannounce.php%3Fuk" - "%3D1111111111%26&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawi" - "ki-1.15.1.tar.gz&xs=http%3A%2F%2Fcache.example.org%2FXRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K" - "5&xs=dchub://example.org") - assert result == ('mediawiki-1.15.1.tar.gz', b'\x81\xe1w\xe2\xcc\x00\x94;)\xfc\xfccTW\xf5u#r\x93\xb0', - ['http://tracker.example.org/announce.php?uk=1111111111&']) - - -def test_parse_magnetlink_nomagnet(): - result = parse_magnetlink("http://") - assert result == (None, None, []) - - -def test_add_url_param_some_present(): - url = 'http://stackoverflow.com/test?answers=true' - new_params = {'answers': False, 'data': ['some', 'values']} - result = add_url_params(url, new_params) - assert "data=values" in result - assert "answers=false" in result - - -def test_add_url_param_clean(): - url = 'http://stackoverflow.com/test' - new_params = {'data': ['some', 'values']} - result = add_url_params(url, new_params) - assert "data=some" in result - assert "data=values" in result - - -def test_load_logger(tmpdir): - """ - Test loading the Tribler logger configuration. - """ - logger_count = len(logging.root.manager.loggerDict) - load_logger_config('test', tmpdir) - assert len(logging.root.manager.loggerDict) >= logger_count diff --git a/src/tribler-core/tribler_core/tests/tools/common.py b/src/tribler-core/tribler_core/tests/tools/common.py index 13e9f074d8f..e44da6b2c71 100644 --- a/src/tribler-core/tribler_core/tests/tools/common.py +++ b/src/tribler-core/tribler_core/tests/tools/common.py @@ -1,17 +1,14 @@ import binascii -import tribler_common - from tribler_core.utilities.path_util import Path UBUNTU_1504_INFOHASH = binascii.unhexlify('FC8A15A2FAF2734DBB1DC5F7AFDC5C9BEAEB1F59') TESTS_DIR = Path(__file__).parent TESTS_DATA_DIR = TESTS_DIR / "data" -COMMON_DATA_DIR = Path(tribler_common.__file__).parent / "data" TORRENT_UBUNTU_FILE = TESTS_DATA_DIR / "ubuntu-15.04-desktop-amd64.iso.torrent" TORRENT_VIDEO_FILE = TESTS_DATA_DIR / "Night.Of.The.Living.Dead_1080p_archive.torrent" -TORRENT_WITH_DIRS = COMMON_DATA_DIR / "multi_entries.torrent" +TORRENT_WITH_DIRS = TESTS_DATA_DIR / "multi_entries.torrent" PNG_FILE = TESTS_DATA_DIR / "ubuntu-logo14.png" diff --git a/src/tribler-common/tribler_common/data/multi_entries.torrent b/src/tribler-core/tribler_core/tests/tools/data/multi_entries.torrent similarity index 100% rename from src/tribler-common/tribler_common/data/multi_entries.torrent rename to src/tribler-core/tribler_core/tests/tools/data/multi_entries.torrent diff --git a/src/tribler-core/tribler_core/upgrade/tests/test_version_manager.py b/src/tribler-core/tribler_core/upgrade/tests/test_version_manager.py index 4d339b01d54..91b85386475 100644 --- a/src/tribler-core/tribler_core/upgrade/tests/test_version_manager.py +++ b/src/tribler-core/tribler_core/upgrade/tests/test_version_manager.py @@ -6,17 +6,16 @@ import pytest -from tribler_common.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_CHECKPOINT_DIR, STATEDIR_DB_DIR -from tribler_common.version_manager import ( +import tribler_core.version +from tribler_core.tests.tools.common import TESTS_DATA_DIR +from tribler_core.upgrade.version_manager import ( TriblerVersion, VERSION_HISTORY_FILENAME, VersionError, VersionHistory, remove_state_dirs, ) - -import tribler_core.version -from tribler_core.tests.tools.common import TESTS_DATA_DIR +from tribler_core.utilities.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_CHECKPOINT_DIR, STATEDIR_DB_DIR DUMMY_STATE_DIR = TESTS_DATA_DIR / "state_dir_dummy" diff --git a/src/tribler-core/tribler_core/upgrade/upgrade.py b/src/tribler-core/tribler_core/upgrade/upgrade.py index da7074e9adb..a2b3f974a27 100644 --- a/src/tribler-core/tribler_core/upgrade/upgrade.py +++ b/src/tribler-core/tribler_core/upgrade/upgrade.py @@ -9,8 +9,6 @@ from pony.orm import db_session, delete -from tribler_common.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_DB_DIR - from tribler_core.components.bandwidth_accounting.db.database import BandwidthDatabase from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import CHANNEL_DIR_NAME_LENGTH from tribler_core.components.metadata_store.db.store import ( @@ -24,6 +22,7 @@ from tribler_core.upgrade.db8_to_db10 import PonyToPonyMigration, get_db_version from tribler_core.utilities.configparser import CallbackConfigParser from tribler_core.utilities.path_util import Path +from tribler_core.utilities.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_DB_DIR # pylint: disable=protected-access diff --git a/src/tribler-common/tribler_common/version_manager.py b/src/tribler-core/tribler_core/upgrade/version_manager.py similarity index 99% rename from src/tribler-common/tribler_common/version_manager.py rename to src/tribler-core/tribler_core/upgrade/version_manager.py index e251c6a3785..5ec1ac3cf00 100644 --- a/src/tribler-common/tribler_common/version_manager.py +++ b/src/tribler-core/tribler_core/upgrade/version_manager.py @@ -11,7 +11,7 @@ from pathlib import Path from typing import Dict, List, Optional, Tuple -from tribler_common.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_CHECKPOINT_DIR, STATEDIR_DB_DIR +from tribler_core.utilities.simpledefs import STATEDIR_CHANNELS_DIR, STATEDIR_CHECKPOINT_DIR, STATEDIR_DB_DIR import tribler_core.version diff --git a/src/tribler-core/tribler_core/utilities/crypto_patcher.py b/src/tribler-core/tribler_core/utilities/crypto_patcher.py index b8ca53235a1..950f8cf0005 100644 --- a/src/tribler-core/tribler_core/utilities/crypto_patcher.py +++ b/src/tribler-core/tribler_core/utilities/crypto_patcher.py @@ -1,6 +1,6 @@ import sys -from tribler_core.utilities.install_dir import is_frozen +from tribler_core.utilities.utilities import is_frozen def patch_crypto_be_discovery(): diff --git a/src/tribler-common/tribler_common/dependencies.py b/src/tribler-core/tribler_core/utilities/dependencies.py similarity index 90% rename from src/tribler-common/tribler_common/dependencies.py rename to src/tribler-core/tribler_core/utilities/dependencies.py index 6b7a2418687..da5b5b5af88 100644 --- a/src/tribler-common/tribler_common/dependencies.py +++ b/src/tribler-core/tribler_core/utilities/dependencies.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__name__) -Scope = Enum('Scope', 'core gui common') +Scope = Enum('Scope', 'core gui') # Exceptional pip packages where the name does not match with actual import. package_to_import_mapping = { @@ -33,9 +33,6 @@ def _get_path_to_requirements_txt() -> Optional[Path]: if scope == Scope.gui: import tribler_gui return Path(tribler_gui.__file__).parent / requirements_txt - if scope == Scope.common: - import tribler_common - return Path(tribler_common.__file__).parent / requirements_txt raise AttributeError(f'Scope is {scope} but should be in {[s for s in Scope]}') # pylint: disable=unnecessary-comprehension return _get_pip_dependencies(_get_path_to_requirements_txt()) diff --git a/src/tribler-core/tribler_core/utilities/install_dir.py b/src/tribler-core/tribler_core/utilities/install_dir.py index fe0c9013e4c..c235a4da111 100644 --- a/src/tribler-core/tribler_core/utilities/install_dir.py +++ b/src/tribler-core/tribler_core/utilities/install_dir.py @@ -5,10 +5,9 @@ """ import sys -from tribler_common.utilities import is_frozen - import tribler_core from tribler_core.utilities.path_util import Path +from tribler_core.utilities.utilities import is_frozen def get_base_path(): diff --git a/src/tribler-common/tribler_common/network_utils.py b/src/tribler-core/tribler_core/utilities/network_utils.py similarity index 100% rename from src/tribler-common/tribler_common/network_utils.py rename to src/tribler-core/tribler_core/utilities/network_utils.py diff --git a/src/tribler-common/tribler_common/osutils.py b/src/tribler-core/tribler_core/utilities/osutils.py similarity index 100% rename from src/tribler-common/tribler_common/osutils.py rename to src/tribler-core/tribler_core/utilities/osutils.py diff --git a/src/tribler-common/tribler_common/patch_import.py b/src/tribler-core/tribler_core/utilities/patch_import.py similarity index 100% rename from src/tribler-common/tribler_common/patch_import.py rename to src/tribler-core/tribler_core/utilities/patch_import.py diff --git a/src/tribler-common/tribler_common/process_checker.py b/src/tribler-core/tribler_core/utilities/process_checker.py similarity index 100% rename from src/tribler-common/tribler_common/process_checker.py rename to src/tribler-core/tribler_core/utilities/process_checker.py diff --git a/src/tribler-common/tribler_common/rest_utils.py b/src/tribler-core/tribler_core/utilities/rest_utils.py similarity index 100% rename from src/tribler-common/tribler_common/rest_utils.py rename to src/tribler-core/tribler_core/utilities/rest_utils.py diff --git a/src/tribler-common/tribler_common/simpledefs.py b/src/tribler-core/tribler_core/utilities/simpledefs.py similarity index 100% rename from src/tribler-common/tribler_common/simpledefs.py rename to src/tribler-core/tribler_core/utilities/simpledefs.py diff --git a/src/tribler-core/tribler_core/utilities/tests/__init__.py b/src/tribler-core/tribler_core/utilities/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler-common/tribler_common/tests/test_dependencies.py b/src/tribler-core/tribler_core/utilities/tests/test_dependencies.py similarity index 92% rename from src/tribler-common/tribler_common/tests/test_dependencies.py rename to src/tribler-core/tribler_core/utilities/tests/test_dependencies.py index 0e5e14d1596..5e2309b727c 100644 --- a/src/tribler-common/tribler_common/tests/test_dependencies.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_dependencies.py @@ -1,6 +1,6 @@ import pytest -from tribler_common.dependencies import ( +from tribler_core.utilities.dependencies import ( Scope, _extract_libraries_from_requirements, _get_pip_dependencies, @@ -37,7 +37,6 @@ async def test_get_dependencies(): # assert that in each scope dependencies are exist assert list(get_dependencies(Scope.gui)) assert list(get_dependencies(Scope.core)) - assert list(get_dependencies(Scope.common)) async def test_get_dependencies_wrong_scope(): diff --git a/src/tribler-common/tribler_common/tests/test_network_utils.py b/src/tribler-core/tribler_core/utilities/tests/test_network_utils.py similarity index 95% rename from src/tribler-common/tribler_common/tests/test_network_utils.py rename to src/tribler-core/tribler_core/utilities/tests/test_network_utils.py index cdf7ac23bae..b7cacbc2b16 100644 --- a/src/tribler-common/tribler_common/tests/test_network_utils.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_network_utils.py @@ -1,6 +1,6 @@ import pytest -from tribler_common.network_utils import FreePortNotFoundError, NetworkUtils +from tribler_core.utilities.network_utils import FreePortNotFoundError, NetworkUtils # fmt: off diff --git a/src/tribler-common/tribler_common/tests/test_osutils.py b/src/tribler-core/tribler_core/utilities/tests/test_osutils.py similarity index 98% rename from src/tribler-common/tribler_common/tests/test_osutils.py rename to src/tribler-core/tribler_core/utilities/tests/test_osutils.py index f632d31dbe5..3e9a310ce86 100644 --- a/src/tribler-common/tribler_common/tests/test_osutils.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_osutils.py @@ -2,7 +2,7 @@ import sys from pathlib import Path -from tribler_common.osutils import ( +from tribler_core.utilities.osutils import ( dir_copy, fix_filebasename, get_appstate_dir, diff --git a/src/tribler-common/tribler_common/tests/test_patch_import.py b/src/tribler-core/tribler_core/utilities/tests/test_patch_import.py similarity index 96% rename from src/tribler-common/tribler_common/tests/test_patch_import.py rename to src/tribler-core/tribler_core/utilities/tests/test_patch_import.py index 15fe619ef02..290ddbcb2c8 100644 --- a/src/tribler-common/tribler_common/tests/test_patch_import.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_patch_import.py @@ -2,7 +2,7 @@ import pytest -from tribler_common.patch_import import patch_import +from tribler_core.utilities.patch_import import patch_import pytestmark = pytest.mark.asyncio diff --git a/src/tribler-common/tribler_common/tests/test_process_checker.py b/src/tribler-core/tribler_core/utilities/tests/test_process_checker.py similarity index 97% rename from src/tribler-common/tribler_common/tests/test_process_checker.py rename to src/tribler-core/tribler_core/utilities/tests/test_process_checker.py index 465b5cdc951..3b767c4134b 100644 --- a/src/tribler-common/tribler_common/tests/test_process_checker.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_process_checker.py @@ -5,7 +5,7 @@ import pytest -from tribler_common.process_checker import LOCK_FILE_NAME, ProcessChecker +from tribler_core.utilities.process_checker import LOCK_FILE_NAME, ProcessChecker @pytest.fixture diff --git a/src/tribler-common/tribler_common/tests/test_rest_utils.py b/src/tribler-core/tribler_core/utilities/tests/test_rest_utils.py similarity index 93% rename from src/tribler-common/tribler_common/tests/test_rest_utils.py rename to src/tribler-core/tribler_core/utilities/tests/test_rest_utils.py index e20e2d2cc90..dc5b305193d 100644 --- a/src/tribler-common/tribler_common/tests/test_rest_utils.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_rest_utils.py @@ -2,7 +2,7 @@ import pytest -from tribler_common.rest_utils import path_to_uri, scheme_from_uri, uri_is_valid_file, uri_to_path +from tribler_core.utilities.rest_utils import path_to_uri, scheme_from_uri, uri_is_valid_file, uri_to_path NIX_PATHS = [ ('/path/to/file', 'file:///path/to/file'), diff --git a/src/tribler-core/tribler_core/utilities/tests/test_utilities.py b/src/tribler-core/tribler_core/utilities/tests/test_utilities.py new file mode 100644 index 00000000000..26b39c50605 --- /dev/null +++ b/src/tribler-core/tribler_core/utilities/tests/test_utilities.py @@ -0,0 +1,260 @@ +import logging +from unittest.mock import MagicMock, patch + +from aiohttp import ClientSession + +import pytest + +from tribler_core.logger.logger import load_logger_config +from tribler_core.utilities.patch_import import patch_import +from tribler_core.utilities.tracker_utils import add_url_params +from tribler_core.utilities.utilities import ( + Query, + extract_tags, + is_channel_public_key, + is_infohash, + is_simple_match_query, + is_valid_url, + parse_magnetlink, + parse_query, + random_infohash, + show_system_popup, + to_fts_query, +) + +# pylint: disable=import-outside-toplevel, import-error +# fmt: off + +def test_parse_magnetlink_lowercase(): + """ + Test if a lowercase magnet link can be parsed + """ + _, hashed, _ = parse_magnetlink('magnet:?xt=urn:btih:apctqfwnowubxzoidazgaj2ba6fs6juc') + + assert hashed == b"\x03\xc58\x16\xcdu\xa8\x1b\xe5\xc8\x182`'A\x07\x8b/&\x82" + + +def test_parse_magnetlink_uppercase(): + """ + Test if an uppercase magnet link can be parsed + """ + _, hashed, _ = parse_magnetlink('magnet:?xt=urn:btih:APCTQFWNOWUBXZOIDAZGAJ2BA6FS6JUC') + + assert hashed == b"\x03\xc58\x16\xcdu\xa8\x1b\xe5\xc8\x182`'A\x07\x8b/&\x82" + + +def test_valid_url(): + """ Test if the URL is valid """ + test_url = "http://anno nce.torrentsmd.com:8080/announce" + assert not is_valid_url(test_url) + + test_url2 = "http://announce.torrentsmd.com:8080/announce " + assert is_valid_url(test_url2) + + test_url3 = "http://localhost:1920/announce" + assert is_valid_url(test_url3) + + test_url4 = "udp://localhost:1264" + assert is_valid_url(test_url4) + + +@pytest.mark.asyncio +async def test_http_get_with_redirect(magnet_redirect_server): + """ + Test if http_get is working properly if url redirects to a magnet link. + """ + # Setup a redirect server which redirects to a magnet link + magnet_link = "magnet:?xt=urn:btih:DC4B96CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" + + test_url = "http://localhost:%d" % magnet_redirect_server + async with ClientSession() as session: + response = await session.get(test_url, allow_redirects=False) + assert response.headers['Location'] == magnet_link + + +def test_simple_search_query(): + query = '"\xc1ubuntu"* AND "debian"*' + assert is_simple_match_query(query) + + query = '""* AND "Petersburg"*' + assert not is_simple_match_query(query) + + query2 = '"\xc1ubuntu"* OR "debian"*' + assert not is_simple_match_query(query2) + + +def test_is_infohash(): + hex_40 = "DC4B96CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" + assert is_infohash(hex_40) + + hex_not_40 = "DC4B96CF85A85CEEDB8ADC4B96CF85" + assert not is_infohash(hex_not_40) + + not_hex = "APPLE6CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" + assert not is_infohash(not_hex) + + +def test_is_channel_public_key(): + hex_128 = "224b20c30b90d0fc7b2cf844f3d651de4481e21c7cdbbff258fa737d117d2c4ac7536de5cc93f4e9d5" \ + "1012a1ae0c46e9a05505bd017f0ecb78d8eec4506e848a" + assert is_channel_public_key(hex_128) + + hex_not_128 = "DC4B96CF85A85CEEDB8ADC4B96CF85" + assert not is_channel_public_key(hex_not_128) + + not_hex = "APPLE6CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" + assert not is_channel_public_key(not_hex) + + +def test_random_infohash(): + test_infohash = random_infohash() + assert isinstance(test_infohash, bytes) + assert len(test_infohash) == 20 + + +def test_to_fts_query(): + assert to_fts_query(None) is None + assert to_fts_query('') is None + assert to_fts_query(' ') is None + assert to_fts_query(' abc') == '"abc"*' + assert to_fts_query('abc def') == '"abc" "def"*' + assert to_fts_query('[abc, def]: xyz?!') == '"abc" "def" "xyz"*' + + +def test_extract_tags(): + assert extract_tags('') == (set(), '') + assert extract_tags('text') == (set(), 'text') + assert extract_tags('#') == (set(), '#') + assert extract_tags('# ') == (set(), '# ') + assert extract_tags('#t ') == (set(), '#t ') + assert extract_tags('#' + 't' * 51) == (set(), '#' + 't' * 51) + assert extract_tags('####') == (set(), '####') + + assert extract_tags('#tag') == ({'tag'}, '') + assert extract_tags('#Tag') == ({'tag'}, '') + assert extract_tags('a #tag in the middle') == ({'tag'}, 'a in the middle') + assert extract_tags('at the end of the query #tag') == ({'tag'}, 'at the end of the query ') + assert extract_tags('multiple tags: #tag1 #tag2#tag3') == ({'tag1', 'tag2', 'tag3'}, 'multiple tags: ') + assert extract_tags('#tag_with_underscores #tag-with-dashes') == ({'tag_with_underscores', 'tag-with-dashes'}, ' ') + + +def test_parse_query(): + assert parse_query('') == Query(original_query='') + + actual = parse_query('#tag1 #tag2') + expected = Query(original_query='#tag1 #tag2', tags={'tag1', 'tag2'}, fts_text='') + assert actual == expected + + actual = parse_query('query without tags') + expected = Query(original_query='query without tags', + tags=set(), + fts_text='query without tags') + assert actual == expected + + actual = parse_query('query with #tag1 and #tag2') + expected = Query(original_query='query with #tag1 and #tag2', + tags={'tag1', 'tag2'}, + fts_text='query with and') + assert actual == expected + + +@patch_import(modules=['win32api'], MessageBox=MagicMock()) +@patch('platform.system', new=MagicMock(return_value='Windows')) +@patch('tribler_core.utilities.utilities.print', new=MagicMock) +def test_show_system_popup_win(): + # in this test "double mocking techniques" has been applied + # there are different mocks that will work depending on the target machine's OS + # + # In case of *nix machine, "@patch_import(modules=['win32api'], MessageBox=MagicMock())" will work. + # In case of win machine, "with patch('win32api.MessageBox'):" will work. + # + # No matter what kind of Mock was used, the line "win32api.MessageBox.assert_called_once()" should work. + # + # This approach also applies to the test functions below. + + import win32api + + with patch('win32api.MessageBox'): # this patch starts to work only in case win32api exists on the target machine + show_system_popup('title', 'text') + win32api.MessageBox.assert_called_once_with(0, 'text', 'title') + + +@patch_import(modules=['subprocess'], Popen=MagicMock()) +@patch('platform.system', new=MagicMock(return_value='Linux')) +@patch('tribler_core.utilities.utilities.print', new=MagicMock) +def test_show_system_popup_linux(): + import subprocess + + with patch('subprocess.Popen'): + show_system_popup('title', 'text') + subprocess.Popen.assert_called_once_with(['xmessage', '-center', 'text']) + + +@patch_import(modules=['subprocess'], Popen=MagicMock()) +@patch('platform.system', new=MagicMock(return_value='Darwin')) +@patch('tribler_core.utilities.print', new=MagicMock) +def test_show_system_popup_darwin(): + import subprocess + + with patch('subprocess.Popen'): + show_system_popup('title', 'text') + subprocess.Popen.assert_called_once_with(['/usr/bin/osascript', '-e', 'text']) + + +@patch('platform.system', new=MagicMock(return_value='Unknown')) +@patch('tribler_core.utilities.utilities.print') +def test_show_system_popup_unknown(mocked_print): + show_system_popup('title', 'text') + mocked_print.assert_called_with('cannot create native pop-up for system Unknown') + + +@patch_import(modules=['subprocess'], Popen=MagicMock(side_effect=ValueError)) +@patch('platform.system', new=MagicMock(return_value='Darwin')) +@patch('tribler_core.utilities.utilities.print') +def test_show_system_popup_exception(mocked_print): + with patch('subprocess.Popen', new=MagicMock(side_effect=ValueError)): + show_system_popup('title', 'text') + last_call_args = mocked_print.call_args_list[-1] + last_argument = last_call_args.args[0] + assert last_argument.startswith('Error while') + + +def test_parse_magnetlink_valid(): + result = parse_magnetlink("magnet:?xt=urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1&xl=10826029&dn=mediawiki-1.15.1" + ".tar.gz&xt=urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY&xt=urn:btih:QHQXPY" + "WMACKDWKP47RRVIV7VOURXFE5Q&tr=http%3A%2F%2Ftracker.example.org%2Fannounce.php%3Fuk" + "%3D1111111111%26&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawi" + "ki-1.15.1.tar.gz&xs=http%3A%2F%2Fcache.example.org%2FXRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K" + "5&xs=dchub://example.org") + assert result == ('mediawiki-1.15.1.tar.gz', b'\x81\xe1w\xe2\xcc\x00\x94;)\xfc\xfccTW\xf5u#r\x93\xb0', + ['http://tracker.example.org/announce.php?uk=1111111111&']) + + +def test_parse_magnetlink_nomagnet(): + result = parse_magnetlink("http://") + assert result == (None, None, []) + + +def test_add_url_param_some_present(): + url = 'http://stackoverflow.com/test?answers=true' + new_params = {'answers': False, 'data': ['some', 'values']} + result = add_url_params(url, new_params) + assert "data=values" in result + assert "answers=false" in result + + +def test_add_url_param_clean(): + url = 'http://stackoverflow.com/test' + new_params = {'data': ['some', 'values']} + result = add_url_params(url, new_params) + assert "data=some" in result + assert "data=values" in result + + +def test_load_logger(tmpdir): + """ + Test loading the Tribler logger configuration. + """ + logger_count = len(logging.root.manager.loggerDict) + load_logger_config('test', tmpdir) + assert len(logging.root.manager.loggerDict) >= logger_count diff --git a/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py b/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py deleted file mode 100644 index 63a8e9574aa..00000000000 --- a/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py +++ /dev/null @@ -1,99 +0,0 @@ -from aiohttp import ClientSession - -import pytest - -from tribler_core.utilities.utilities import ( - is_channel_public_key, - is_infohash, - is_simple_match_query, - is_valid_url, - parse_magnetlink, - random_infohash, -) - - -def test_parse_magnetlink_lowercase(): - """ - Test if a lowercase magnet link can be parsed - """ - _, hashed, _ = parse_magnetlink('magnet:?xt=urn:btih:apctqfwnowubxzoidazgaj2ba6fs6juc') - - assert hashed == b"\x03\xc58\x16\xcdu\xa8\x1b\xe5\xc8\x182`'A\x07\x8b/&\x82" - - -def test_parse_magnetlink_uppercase(): - """ - Test if an uppercase magnet link can be parsed - """ - _, hashed, _ = parse_magnetlink('magnet:?xt=urn:btih:APCTQFWNOWUBXZOIDAZGAJ2BA6FS6JUC') - - assert hashed == b"\x03\xc58\x16\xcdu\xa8\x1b\xe5\xc8\x182`'A\x07\x8b/&\x82" - - -def test_valid_url(): - """ Test if the URL is valid """ - test_url = "http://anno nce.torrentsmd.com:8080/announce" - assert not is_valid_url(test_url) - - test_url2 = "http://announce.torrentsmd.com:8080/announce " - assert is_valid_url(test_url2) - - test_url3 = "http://localhost:1920/announce" - assert is_valid_url(test_url3) - - test_url4 = "udp://localhost:1264" - assert is_valid_url(test_url4) - - -@pytest.mark.asyncio -async def test_http_get_with_redirect(magnet_redirect_server): - """ - Test if http_get is working properly if url redirects to a magnet link. - """ - # Setup a redirect server which redirects to a magnet link - magnet_link = "magnet:?xt=urn:btih:DC4B96CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" - - test_url = "http://localhost:%d" % magnet_redirect_server - async with ClientSession() as session: - response = await session.get(test_url, allow_redirects=False) - assert response.headers['Location'] == magnet_link - - -def test_simple_search_query(): - query = '"\xc1ubuntu"* AND "debian"*' - assert is_simple_match_query(query) - - query = '""* AND "Petersburg"*' - assert not is_simple_match_query(query) - - query2 = '"\xc1ubuntu"* OR "debian"*' - assert not is_simple_match_query(query2) - - -def test_is_infohash(): - hex_40 = "DC4B96CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" - assert is_infohash(hex_40) - - hex_not_40 = "DC4B96CF85A85CEEDB8ADC4B96CF85" - assert not is_infohash(hex_not_40) - - not_hex = "APPLE6CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" - assert not is_infohash(not_hex) - - -def test_is_channel_public_key(): - hex_128 = "224b20c30b90d0fc7b2cf844f3d651de4481e21c7cdbbff258fa737d117d2c4ac7536de5cc93f4e9d5" \ - "1012a1ae0c46e9a05505bd017f0ecb78d8eec4506e848a" - assert is_channel_public_key(hex_128) - - hex_not_128 = "DC4B96CF85A85CEEDB8ADC4B96CF85" - assert not is_channel_public_key(hex_not_128) - - not_hex = "APPLE6CF85A85CEEDB8ADC4B96CF85A85CEEDB8A" - assert not is_channel_public_key(not_hex) - - -def test_random_infohash(): - test_infohash = random_infohash() - assert isinstance(test_infohash, bytes) - assert len(test_infohash) == 20 diff --git a/src/tribler-core/tribler_core/utilities/tiny_tribler_service.py b/src/tribler-core/tribler_core/utilities/tiny_tribler_service.py index 34f01fe07a5..3a406945900 100644 --- a/src/tribler-core/tribler_core/utilities/tiny_tribler_service.py +++ b/src/tribler-core/tribler_core/utilities/tiny_tribler_service.py @@ -4,11 +4,10 @@ from pathlib import Path from typing import List -from tribler_common.osutils import get_root_state_directory -from tribler_common.process_checker import ProcessChecker - from tribler_core.components.base import Component from tribler_core.start_core import Session +from tribler_core.utilities.osutils import get_root_state_directory +from tribler_core.utilities.process_checker import ProcessChecker class TinyTriblerService: diff --git a/src/tribler-core/tribler_core/utilities/utilities.py b/src/tribler-core/tribler_core/utilities/utilities.py index d7b127c009d..8256f0eb109 100644 --- a/src/tribler-core/tribler_core/utilities/utilities.py +++ b/src/tribler-core/tribler_core/utilities/utilities.py @@ -4,11 +4,16 @@ Author(s): Jie Yang """ import binascii +import itertools import logging +import platform import random import re +import sys from base64 import b32decode +from dataclasses import dataclass, field from functools import wraps +from typing import Set, Tuple from urllib.parse import parse_qsl, urlsplit from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt @@ -169,3 +174,102 @@ def bdecode_compat(packet_buffer): def random_infohash(random_gen=None): r = random_gen or random return r.getrandbits(20 * 8).to_bytes(20, byteorder='big') + + +def is_frozen(): + """ + Return whether we are running in a frozen environment + """ + try: + # PyInstaller creates a temp folder and stores path in _MEIPASS + sys._MEIPASS # pylint: disable=protected-access + except Exception: # pylint: disable=broad-except + return False + return True + + +fts_query_re = re.compile(r'\w+', re.UNICODE) +tags_re = re.compile(r'#[^\s^#]{3,50}(?=[#\s]|$)') + + +@dataclass +class Query: + original_query: str + tags: Set[str] = field(default_factory=set) + fts_text: str = '' + + +def parse_query(query: str) -> Query: + """ + The query structure: + query = [tag1][tag2] text + ^ ^ + tags fts query + """ + if not query: + return Query(original_query=query) + + tags, remaining_text = extract_tags(query) + return Query(original_query=query, tags=tags, fts_text=remaining_text.strip()) + + +def extract_tags(text: str) -> Tuple[Set[str], str]: + if not text: + return set(), '' + + tags = set() + positions = [0] + + for m in tags_re.finditer(text): + tag = m.group(0)[1:] + tags.add(tag.lower()) + positions.extend(itertools.chain.from_iterable(m.regs)) + positions.append(len(text)) + + remaining_text = ''.join(text[positions[i] : positions[i + 1]] for i in range(0, len(positions) - 1, 2)) + return tags, remaining_text + + +def to_fts_query(text): + if not text: + return None + + words = [f'"{w}"' for w in fts_query_re.findall(text) if w] + if not words: + return None + + return ' '.join(words) + '*' + + +def show_system_popup(title, text): + """ + Create a native pop-up without any third party dependency. + + :param title: the pop-up title + :param text: the pop-up body + """ + sep = "*" * 80 + + # pylint: disable=import-outside-toplevel, import-error, broad-except + print('\n'.join([sep, title, sep, text, sep]), file=sys.stderr) # noqa: T001 + system = platform.system() + try: + if system == 'Windows': + import win32api + + win32api.MessageBox(0, text, title) + elif system == 'Linux': + import subprocess + + subprocess.Popen(['xmessage', '-center', text]) + elif system == 'Darwin': + import subprocess + + subprocess.Popen(['/usr/bin/osascript', '-e', text]) + else: + print(f'cannot create native pop-up for system {system}') # noqa: T001 + except Exception as exception: + # Use base Exception, because code above can raise many + # non-obvious types of exceptions: + # (SubprocessError, ImportError, win32api.error, FileNotFoundError) + print(f'Error while showing a message box: {exception}') # noqa: T001 diff --git a/src/tribler-gui/tribler_gui/__init__.py b/src/tribler-gui/tribler_gui/__init__.py index db943ff80fb..7d706e4b5d5 100644 --- a/src/tribler-gui/tribler_gui/__init__.py +++ b/src/tribler-gui/tribler_gui/__init__.py @@ -1,6 +1,6 @@ """ This package contains the code for the GUI, written in pyQt. """ -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter gui_sentry_reporter = SentryReporter() diff --git a/src/tribler-gui/tribler_gui/dialogs/addtagsdialog.py b/src/tribler-gui/tribler_gui/dialogs/addtagsdialog.py index 659c0d5dfe8..c40bec7cb93 100644 --- a/src/tribler-gui/tribler_gui/dialogs/addtagsdialog.py +++ b/src/tribler-gui/tribler_gui/dialogs/addtagsdialog.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import QModelIndex, QPoint, pyqtSignal from PyQt5.QtWidgets import QSizePolicy, QWidget -from tribler_common.tag_constants import MAX_TAG_LENGTH, MIN_TAG_LENGTH +from tribler_core.components.tag.tag_constants import MAX_TAG_LENGTH, MIN_TAG_LENGTH from tribler_gui.defs import TAG_HORIZONTAL_MARGIN from tribler_gui.dialogs.dialogcontainer import DialogContainer diff --git a/src/tribler-gui/tribler_gui/dialogs/feedbackdialog.py b/src/tribler-gui/tribler_gui/dialogs/feedbackdialog.py index fc98001ef9d..5e455bafbdf 100644 --- a/src/tribler-gui/tribler_gui/dialogs/feedbackdialog.py +++ b/src/tribler-gui/tribler_gui/dialogs/feedbackdialog.py @@ -8,10 +8,10 @@ from PyQt5 import uic from PyQt5.QtWidgets import QAction, QApplication, QDialog, QMessageBox, QTreeWidgetItem -from tribler_common.reported_error import ReportedError -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter -from tribler_common.sentry_reporter.sentry_scrubber import SentryScrubber -from tribler_common.sentry_reporter.sentry_tools import CONTEXT_DELIMITER, LONG_TEXT_DELIMITER +from tribler_core.components.reporter.reported_error import ReportedError +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter +from tribler_core.sentry_reporter.sentry_scrubber import SentryScrubber +from tribler_core.sentry_reporter.sentry_tools import CONTEXT_DELIMITER, LONG_TEXT_DELIMITER from tribler_gui.event_request_manager import received_events from tribler_gui.sentry_mixin import AddBreadcrumbOnShowMixin diff --git a/src/tribler-gui/tribler_gui/dialogs/startdownloaddialog.py b/src/tribler-gui/tribler_gui/dialogs/startdownloaddialog.py index fbc8e2c9b2a..edf23861a23 100644 --- a/src/tribler-gui/tribler_gui/dialogs/startdownloaddialog.py +++ b/src/tribler-gui/tribler_gui/dialogs/startdownloaddialog.py @@ -8,7 +8,7 @@ from PyQt5.QtCore import QTimer, pyqtSignal from PyQt5.QtWidgets import QFileDialog, QSizePolicy -from tribler_common.rest_utils import FILE_SCHEME, MAGNET_SCHEME, scheme_from_uri, uri_to_path +from tribler_core.utilities.rest_utils import FILE_SCHEME, MAGNET_SCHEME, scheme_from_uri, uri_to_path from tribler_gui.defs import METAINFO_MAX_RETRIES, METAINFO_TIMEOUT from tribler_gui.dialogs.confirmationdialog import ConfirmationDialog diff --git a/src/tribler-gui/tribler_gui/error_handler.py b/src/tribler-gui/tribler_gui/error_handler.py index 51cc2a41c78..405e2d412be 100644 --- a/src/tribler-gui/tribler_gui/error_handler.py +++ b/src/tribler-gui/tribler_gui/error_handler.py @@ -1,8 +1,8 @@ import logging import traceback -from tribler_common.reported_error import ReportedError -from tribler_common.sentry_reporter.sentry_reporter import SentryStrategy +from tribler_core.components.reporter.reported_error import ReportedError +from tribler_core.sentry_reporter.sentry_reporter import SentryStrategy from tribler_gui import gui_sentry_reporter from tribler_gui.dialogs.feedbackdialog import FeedbackDialog diff --git a/src/tribler-gui/tribler_gui/event_request_manager.py b/src/tribler-gui/tribler_gui/event_request_manager.py index e557a5fbeab..a86f0d16e55 100644 --- a/src/tribler-gui/tribler_gui/event_request_manager.py +++ b/src/tribler-gui/tribler_gui/event_request_manager.py @@ -5,8 +5,8 @@ from PyQt5.QtCore import QTimer, QUrl, pyqtSignal from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest -from tribler_common.reported_error import ReportedError -from tribler_common.simpledefs import NTFY +from tribler_core.components.reporter.reported_error import ReportedError +from tribler_core.utilities.simpledefs import NTFY from tribler_gui import gui_sentry_reporter from tribler_gui.exceptions import CoreConnectTimeoutError, CoreConnectionError diff --git a/src/tribler-gui/tribler_gui/requirements.txt b/src/tribler-gui/tribler_gui/requirements.txt index 8c1b4bbf23d..569980bb2b9 100644 --- a/src/tribler-gui/tribler_gui/requirements.txt +++ b/src/tribler-gui/tribler_gui/requirements.txt @@ -1,7 +1,6 @@ -configobj==5.0.6 -networkx==2.6.3 +-r ../../tribler-core/tribler_core/requirements.txt + Pillow==9.0.0 -psutil==5.8.0 PyQt5==5.15.1 PyQt5-sip==12.8.1 pyqtgraph==0.12.3 diff --git a/src/tribler-gui/tribler_gui/start_gui.py b/src/tribler-gui/tribler_gui/start_gui.py index 33ab278b6ac..226c5164ea5 100644 --- a/src/tribler-gui/tribler_gui/start_gui.py +++ b/src/tribler-gui/tribler_gui/start_gui.py @@ -4,10 +4,6 @@ from PyQt5.QtCore import QSettings -from tribler_common.logger import load_logger_config -from tribler_common.rest_utils import path_to_uri -from tribler_common.sentry_reporter.sentry_reporter import SentryStrategy - from tribler_core.check_os import ( check_and_enable_code_tracing, check_environment, @@ -16,6 +12,9 @@ error_and_exit, ) from tribler_core.exceptions import TriblerException +from tribler_core.logger.logger import load_logger_config +from tribler_core.sentry_reporter.sentry_reporter import SentryStrategy +from tribler_core.utilities.rest_utils import path_to_uri from tribler_gui import gui_sentry_reporter from tribler_gui.tribler_app import TriblerApplication diff --git a/src/tribler-gui/tribler_gui/tests/test_error_handler.py b/src/tribler-gui/tribler_gui/tests/test_error_handler.py index f90fbc04133..a3d7509dd9b 100644 --- a/src/tribler-gui/tribler_gui/tests/test_error_handler.py +++ b/src/tribler-gui/tribler_gui/tests/test_error_handler.py @@ -2,8 +2,8 @@ import pytest -from tribler_common.reported_error import ReportedError -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter, SentryStrategy +from tribler_core.components.reporter.reported_error import ReportedError +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter, SentryStrategy from tribler_gui.error_handler import ErrorHandler from tribler_gui.exceptions import CoreConnectTimeoutError, CoreCrashedError diff --git a/src/tribler-gui/tribler_gui/tests/test_gui.py b/src/tribler-gui/tribler_gui/tests/test_gui.py index 3153fd68757..8696a7c10db 100644 --- a/src/tribler-gui/tribler_gui/tests/test_gui.py +++ b/src/tribler-gui/tribler_gui/tests/test_gui.py @@ -10,12 +10,11 @@ import pytest -import tribler_common -from tribler_common.reported_error import ReportedError -from tribler_common.rest_utils import path_to_uri -from tribler_common.sentry_reporter.sentry_reporter import SentryReporter -from tribler_common.tag_constants import MIN_TAG_LENGTH - +from tribler_core.components.reporter.reported_error import ReportedError +from tribler_core.components.tag.tag_constants import MIN_TAG_LENGTH +from tribler_core.sentry_reporter.sentry_reporter import SentryReporter +from tribler_core.tests.tools.common import TESTS_DATA_DIR +from tribler_core.utilities.rest_utils import path_to_uri from tribler_core.utilities.unicode import hexlify import tribler_gui @@ -31,8 +30,7 @@ from tribler_gui.widgets.torrentfiletreewidget import CHECKBOX_COL RUN_TRIBLER_PY = Path(tribler_gui.__file__).parent.parent.parent / "run_tribler.py" -COMMON_DATA_DIR = Path(tribler_common.__file__).parent / "data" -TORRENT_WITH_DIRS = COMMON_DATA_DIR / "multi_entries.torrent" +TORRENT_WITH_DIRS = TESTS_DATA_DIR / "multi_entries.torrent" @pytest.fixture(scope="module") diff --git a/src/tribler-gui/tribler_gui/tribler_app.py b/src/tribler-gui/tribler_gui/tribler_app.py index bb82efefa3d..b2c0d472670 100644 --- a/src/tribler-gui/tribler_gui/tribler_app.py +++ b/src/tribler-gui/tribler_gui/tribler_app.py @@ -4,8 +4,7 @@ from PyQt5.QtCore import QCoreApplication, QEvent, Qt -from tribler_common.rest_utils import path_to_uri - +from tribler_core.utilities.rest_utils import path_to_uri from tribler_core.utilities.unicode import ensure_unicode from tribler_gui.code_executor import CodeExecutor diff --git a/src/tribler-gui/tribler_gui/tribler_window.py b/src/tribler-gui/tribler_gui/tribler_window.py index 5f4284e6b98..d6904d9d1b8 100644 --- a/src/tribler-gui/tribler_gui/tribler_window.py +++ b/src/tribler-gui/tribler_gui/tribler_window.py @@ -38,13 +38,18 @@ from psutil import LINUX -from tribler_common.network_utils import default_network_utils -from tribler_common.process_checker import ProcessChecker -from tribler_common.rest_utils import FILE_SCHEME, MAGNET_SCHEME, scheme_from_uri, uri_is_valid_file, uri_to_path -from tribler_common.utilities import parse_query -from tribler_common.version_manager import VersionHistory - +from tribler_core.upgrade.version_manager import VersionHistory +from tribler_core.utilities.network_utils import default_network_utils +from tribler_core.utilities.process_checker import ProcessChecker +from tribler_core.utilities.rest_utils import ( + FILE_SCHEME, + MAGNET_SCHEME, + scheme_from_uri, + uri_is_valid_file, + uri_to_path, +) from tribler_core.utilities.unicode import hexlify +from tribler_core.utilities.utilities import parse_query from tribler_core.version import version_id from tribler_gui.core_manager import CoreManager @@ -165,7 +170,6 @@ def __init__( self.tribler_started = False self.tribler_settings = None - # TODO: move version_id to tribler_common and get core version in the core crash message self.tribler_version = version_id self.debug_window = None diff --git a/src/tribler-gui/tribler_gui/upgrade_manager.py b/src/tribler-gui/tribler_gui/upgrade_manager.py index d6ecd3f93bf..8acc9a6ac43 100644 --- a/src/tribler-gui/tribler_gui/upgrade_manager.py +++ b/src/tribler-gui/tribler_gui/upgrade_manager.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import QObject, QThread, pyqtSignal from PyQt5.QtWidgets import QMessageBox -from tribler_common.version_manager import TriblerVersion, VersionHistory +from tribler_core.upgrade.version_manager import TriblerVersion, VersionHistory from tribler_gui.utilities import connect, format_size, tr diff --git a/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py b/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py index cec979e7d10..715404262ac 100644 --- a/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py +++ b/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py @@ -7,10 +7,9 @@ from psutil import LINUX -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.metadata_store.db.orm_bindings.channel_node import DIRTY_STATUSES, NEW from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_gui.defs import ( BUTTON_TYPE_CONFIRM, diff --git a/src/tribler-gui/tribler_gui/widgets/channelsmenulistwidget.py b/src/tribler-gui/tribler_gui/widgets/channelsmenulistwidget.py index 11ba114b865..2c7c2bc1e02 100644 --- a/src/tribler-gui/tribler_gui/widgets/channelsmenulistwidget.py +++ b/src/tribler-gui/tribler_gui/widgets/channelsmenulistwidget.py @@ -4,9 +4,8 @@ from PyQt5.QtGui import QBrush, QColor, QIcon, QPixmap from PyQt5.QtWidgets import QAbstractItemView, QAbstractScrollArea, QAction, QListWidget, QListWidgetItem -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_gui.tribler_action_menu import TriblerActionMenu from tribler_gui.tribler_request_manager import TriblerNetworkRequest diff --git a/src/tribler-gui/tribler_gui/widgets/downloadsdetailstabwidget.py b/src/tribler-gui/tribler_gui/widgets/downloadsdetailstabwidget.py index c2854ba40c4..0d9010e9ca7 100644 --- a/src/tribler-gui/tribler_gui/widgets/downloadsdetailstabwidget.py +++ b/src/tribler-gui/tribler_gui/widgets/downloadsdetailstabwidget.py @@ -3,7 +3,7 @@ from PyQt5.QtCore import QTimer, Qt from PyQt5.QtWidgets import QTabWidget, QTreeWidgetItem -from tribler_common.simpledefs import dlstatus_strings +from tribler_core.utilities.simpledefs import dlstatus_strings from tribler_gui.defs import DLSTATUS_STOPPED_ON_ERROR, DLSTATUS_STRINGS from tribler_gui.tribler_request_manager import TriblerNetworkRequest diff --git a/src/tribler-gui/tribler_gui/widgets/downloadwidgetitem.py b/src/tribler-gui/tribler_gui/widgets/downloadwidgetitem.py index 4e42d28d881..257c00be417 100644 --- a/src/tribler-gui/tribler_gui/widgets/downloadwidgetitem.py +++ b/src/tribler-gui/tribler_gui/widgets/downloadwidgetitem.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QProgressBar, QTreeWidgetItem, QVBoxLayout, QWidget -from tribler_common.simpledefs import dlstatus_strings +from tribler_core.utilities.simpledefs import dlstatus_strings from tribler_gui.defs import DLSTATUS_DOWNLOADING, DLSTATUS_METADATA, DLSTATUS_STRINGS from tribler_gui.utilities import duration_to_string, format_size, format_speed diff --git a/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py b/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py index abc72d59865..0680546c15a 100644 --- a/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py +++ b/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py @@ -5,9 +5,8 @@ from PyQt5 import uic -from tribler_common.utilities import Query, to_fts_query - from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT +from tribler_core.utilities.utilities import Query, to_fts_query from tribler_gui.sentry_mixin import AddBreadcrumbOnShowMixin from tribler_gui.tribler_request_manager import TriblerNetworkRequest diff --git a/src/tribler-gui/tribler_gui/widgets/settingspage.py b/src/tribler-gui/tribler_gui/widgets/settingspage.py index 46175b67985..551056816c5 100644 --- a/src/tribler-gui/tribler_gui/widgets/settingspage.py +++ b/src/tribler-gui/tribler_gui/widgets/settingspage.py @@ -3,9 +3,9 @@ from PyQt5.QtCore import pyqtSignal from PyQt5.QtWidgets import QCheckBox, QFileDialog, QMessageBox, QSizePolicy, QWidget -from tribler_common.osutils import get_root_state_directory -from tribler_common.simpledefs import MAX_LIBTORRENT_RATE_LIMIT -from tribler_common.version_manager import remove_state_dirs +from tribler_core.upgrade.version_manager import remove_state_dirs +from tribler_core.utilities.osutils import get_root_state_directory +from tribler_core.utilities.simpledefs import MAX_LIBTORRENT_RATE_LIMIT from tribler_gui.defs import ( DARWIN, diff --git a/src/tribler-gui/tribler_gui/widgets/tablecontentdelegate.py b/src/tribler-gui/tribler_gui/widgets/tablecontentdelegate.py index 9fba25595e3..f2ef8c39cea 100644 --- a/src/tribler-gui/tribler_gui/widgets/tablecontentdelegate.py +++ b/src/tribler-gui/tribler_gui/widgets/tablecontentdelegate.py @@ -7,10 +7,9 @@ from psutil import LINUX -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.metadata_store.db.orm_bindings.channel_node import LEGACY_ENTRY from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_gui.defs import ( COMMIT_STATUS_COMMITTED, diff --git a/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py b/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py index c032b936290..f927d50ffa6 100644 --- a/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py +++ b/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py @@ -7,11 +7,10 @@ from PyQt5.QtCore import QAbstractTableModel, QModelIndex, QRectF, QSize, Qt, pyqtSignal -from tribler_common.simpledefs import CHANNELS_VIEW_UUID, CHANNEL_STATE -from tribler_common.utilities import to_fts_query - from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT +from tribler_core.utilities.simpledefs import CHANNELS_VIEW_UUID, CHANNEL_STATE +from tribler_core.utilities.utilities import to_fts_query from tribler_gui.defs import BITTORRENT_BIRTHDAY, COMMIT_STATUS_TODELETE, HEALTH_CHECKING from tribler_gui.tribler_request_manager import TriblerNetworkRequest diff --git a/src/tribler-gui/tribler_gui/widgets/triblertablecontrollers.py b/src/tribler-gui/tribler_gui/widgets/triblertablecontrollers.py index 4acf9b621f2..f8beca77b3f 100644 --- a/src/tribler-gui/tribler_gui/widgets/triblertablecontrollers.py +++ b/src/tribler-gui/tribler_gui/widgets/triblertablecontrollers.py @@ -10,9 +10,8 @@ from PyQt5.QtNetwork import QNetworkRequest from PyQt5.QtWidgets import QAction -from tribler_common.simpledefs import CHANNEL_STATE - from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT +from tribler_core.utilities.simpledefs import CHANNEL_STATE from tribler_gui.defs import HEALTH_CHECKING, HEALTH_UNCHECKED from tribler_gui.tribler_action_menu import TriblerActionMenu diff --git a/src/tribler.sh b/src/tribler.sh index 2c58174eea2..060ca80c1cb 100755 --- a/src/tribler.sh +++ b/src/tribler.sh @@ -10,7 +10,7 @@ UNAME="$(uname -s)" # Add all required modules to PYTHONPATH SRC_DIR="$(dirname "$(script_path "$0")")/src" -PYTHONPATH="$PYTHONPATH:"$SRC_DIR/pyipv8":"$SRC_DIR/anydex":"$SRC_DIR/tribler-common":"$SRC_DIR/tribler-core":"$SRC_DIR/tribler-gui"" +PYTHONPATH="$PYTHONPATH:"$SRC_DIR/pyipv8":"$SRC_DIR/anydex":"$SRC_DIR/tribler-core":"$SRC_DIR/tribler-gui"" export PYTHONPATH TRIBLER_SCRIPT=$SRC_DIR/run_tribler.py diff --git a/tribler.spec b/tribler.spec index d7c483e6a83..b79594c829e 100644 --- a/tribler.spec +++ b/tribler.spec @@ -16,7 +16,6 @@ src_dir = os.path.join(root_dir, "src") tribler_components = [ os.path.join(src_dir, "pyipv8"), - os.path.join(src_dir, "tribler-common"), os.path.join(src_dir, "tribler-core"), os.path.join(src_dir, "tribler-gui"), ] @@ -42,7 +41,6 @@ data_to_copy = [ (os.path.join(src_dir, "tribler-gui", "tribler_gui", "qt_resources"), 'qt_resources'), (os.path.join(src_dir, "tribler-gui", "tribler_gui", "images"), 'images'), (os.path.join(src_dir, "tribler-gui", "tribler_gui", "i18n"), 'i18n'), - (os.path.join(src_dir, "tribler-common", "tribler_common"), 'tribler_source/tribler_common'), (os.path.join(src_dir, "tribler-core", "tribler_core"), 'tribler_source/tribler_core'), (os.path.join(src_dir, "tribler-gui", "tribler_gui"), 'tribler_source/tribler_gui'), (os.path.join(root_dir, "build", "win", "resources"), 'tribler_source/resources'),