From 50c9571947ba951f7cfe8a3b77cd1e72379532a0 Mon Sep 17 00:00:00 2001 From: Andrei Andreev Date: Wed, 9 Mar 2022 13:37:14 +0100 Subject: [PATCH] Update build --- build/debian/makedist_debian.sh | 2 +- build/mac/makedist_macos.sh | 2 +- build/systemd/anontunnel_helper@.service | 4 ++-- build/systemd/bandwidth-crawler.service | 4 ++-- build/update_version_from_git.py | 2 +- build/win/makedist_win.bat | 2 +- doc/conf.py | 11 ++++------ doc/extract_swagger.py | 6 +++--- .../tests/test_gigachannel_community.py | 4 ++-- .../tests/test_gigachannel_manager.py | 2 +- .../tests/test_torrentinfo_endpoint.py | 2 +- .../tests/test_remote_query_community.py | 2 +- .../restapi/tests/test_channels_endpoint.py | 2 +- .../restapi/rest/tests/test_debug_endpoint.py | 4 ++-- .../restapi/rest/tests/test_rest_manager.py | 2 +- src/tribler/core/logger/logger.py | 2 +- src/tribler/core/logger/logger.yaml | 8 ++++---- src/tribler/core/logger/tests/test_logger.py | 10 +++++----- .../tests/test_sentry_reporter.py | 10 +++++----- src/tribler/core/tests/test_check_os.py | 20 +++++++++---------- src/tribler/core/tests/test_start_core.py | 10 +++++----- .../upgrade/tests/test_version_manager.py | 2 +- src/tribler/core/utilities/dependencies.py | 4 ++-- src/tribler/core/utilities/install_dir.py | 2 +- .../core/utilities/tests/test_dependencies.py | 2 +- .../core/utilities/tests/test_utilities.py | 10 +++++----- src/tribler/gui/tests/test_core_manager.py | 14 ++++++------- src/tribler/gui/tests/test_error_handler.py | 18 ++++++++--------- src/tribler/gui/tests/test_gui.py | 4 ++-- tribler.spec | 18 ++++++++--------- 30 files changed, 90 insertions(+), 95 deletions(-) diff --git a/build/debian/makedist_debian.sh b/build/debian/makedist_debian.sh index c42b6c115e7..2ea71e7a6af 100755 --- a/build/debian/makedist_debian.sh +++ b/build/debian/makedist_debian.sh @@ -20,7 +20,7 @@ rm -rf build/debian/tribler/usr/share/tribler python3 build/update_version_from_git.py # ----- Install pip dependencies before the build -python3 -m pip install --upgrade -r src/requirements.txt +python3 -m pip install --upgrade -r requirements.txt python3 -m PyInstaller tribler.spec diff --git a/build/mac/makedist_macos.sh b/build/mac/makedist_macos.sh index c1649ea7ed0..343ae882504 100755 --- a/build/mac/makedist_macos.sh +++ b/build/mac/makedist_macos.sh @@ -14,7 +14,7 @@ export RESOURCES=build/mac/resources # ----- Build # ----- Install pip dependencies before the build -python3 -m pip install --upgrade -r src/requirements.txt +python3 -m pip install --upgrade -r requirements.txt PI=pyinstaller $PI tribler.spec diff --git a/build/systemd/anontunnel_helper@.service b/build/systemd/anontunnel_helper@.service index 91917d98b30..a73034f428f 100644 --- a/build/systemd/anontunnel_helper@.service +++ b/build/systemd/anontunnel_helper@.service @@ -13,11 +13,11 @@ 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-core +Environment=PYTHONPATH=./src WorkingDirectory=/opt/tribler ExecStartPre=/bin/mkdir -p ${HOME} -ExecStart=/usr/bin/python3 src/tribler-core/run_tunnel_helper.py $EXTRA_TUNNEL_ARGS +ExecStart=/usr/bin/python3 scripts/tunnel_helper/run_tunnel_helper.py $EXTRA_TUNNEL_ARGS [Install] WantedBy=multi-user.target diff --git a/build/systemd/bandwidth-crawler.service b/build/systemd/bandwidth-crawler.service index 8da6eb7ab38..255e74ecf26 100644 --- a/build/systemd/bandwidth-crawler.service +++ b/build/systemd/bandwidth-crawler.service @@ -7,9 +7,9 @@ Type=simple User=crawler Group=crawler Restart=always -Environment=PYTHONPATH=./src/pyipv8:./src/tribler-core +Environment=PYTHONPATH=./src WorkingDirectory=/opt/tribler -ExecStart=/usr/bin/python3 src/tribler-core/run_bandwidth_crawler.py --statedir /var/lib/crawler $EXTRA_CRAWLER_ARGS +ExecStart=/usr/bin/python3 scripts/bandwidth_crawler/run_bandwidth_crawler.py --statedir /var/lib/crawler $EXTRA_CRAWLER_ARGS [Install] WantedBy=multi-user.target diff --git a/build/update_version_from_git.py b/build/update_version_from_git.py index e4c1928e481..5cadc20f597 100755 --- a/build/update_version_from_git.py +++ b/build/update_version_from_git.py @@ -42,7 +42,7 @@ def run_command(cmd): logger.info("Build date: %s", build_date) logger.info('Writing runtime version info.') - with open(path.join('src', 'tribler-core', 'tribler_core', 'version.py'), 'w') as f: + with open(path.join('src', 'tribler', 'core', 'version.py'), 'w') as f: f.write( f'version_id = "{version_id}"{linesep}' f'build_date = "{build_date}"{linesep}' diff --git a/build/win/makedist_win.bat b/build/win/makedist_win.bat index 7d23c6742e6..d9d59dffa7b 100644 --- a/build/win/makedist_win.bat +++ b/build/win/makedist_win.bat @@ -43,7 +43,7 @@ call build\win\clean.bat REM ----- Build REM ----- Install pip dependencies before the build -python3 -m pip install --upgrade -r src\requirements.txt +python3 -m pip install --upgrade -r requirements.txt REM Arno: When adding files here, make sure tribler.nsi actually REM packs them in the installer .EXE diff --git a/doc/conf.py b/doc/conf.py index 30999975f6c..816ea7eb91c 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -23,22 +23,19 @@ # pylint: disable=wrong-import-position root_dir = os.path.abspath(os.path.join(os.path.dirname(__name__), '..')) tribler_components = [ - os.path.join(root_dir, "src", "pyipv8"), - os.path.join(root_dir, "src", "anydex"), - os.path.join(root_dir, "src", "tribler-core"), - os.path.join(root_dir, "src", "tribler-gui"), + os.path.join(root_dir, "src"), os.path.join(root_dir, "doc"), ] for component in tribler_components: sys.path.append(str(component)) -from tribler_core.utilities.dependencies import Scope, get_dependencies -from tribler_core.utilities.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)) | {'libtorrent', 'validate'} with patch_import(modules=modules_to_mock): - from tribler_core.components.restapi.rest.root_endpoint import RootEndpoint + from tribler.core.components.restapi.rest.root_endpoint import RootEndpoint add_endpoint = RootEndpoint.add_endpoint RootEndpoint.add_endpoint = lambda self, path, ep: add_endpoint(self, path, ep) \ if path not in ['/ipv8', '/market', '/wallets'] else None diff --git a/doc/extract_swagger.py b/doc/extract_swagger.py index fa34375f465..e313f568ba7 100644 --- a/doc/extract_swagger.py +++ b/doc/extract_swagger.py @@ -7,9 +7,9 @@ import yaml -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.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 async def extract_swagger(destination_fn): diff --git a/src/tribler/core/components/gigachannel/community/tests/test_gigachannel_community.py b/src/tribler/core/components/gigachannel/community/tests/test_gigachannel_community.py index cc4b996c697..77005b527a0 100644 --- a/src/tribler/core/components/gigachannel/community/tests/test_gigachannel_community.py +++ b/src/tribler/core/components/gigachannel/community/tests/test_gigachannel_community.py @@ -27,7 +27,7 @@ # pylint:disable=protected-access -BASE_PATH = 'tribler_core.components.metadata_store.remote_query_community.remote_query_community' +BASE_PATH = 'tribler.core.components.metadata_store.remote_query_community.remote_query_community' class TestGigaChannelUnits(TestBase): @@ -54,7 +54,7 @@ def create_node(self, *args, **kwargs): kwargs['metadata_store'] = metadata_store kwargs['settings'] = ChantSettings() kwargs['rqc_settings'] = RemoteQueryCommunitySettings() - with patch('tribler_core.components.gigachannel.community.gigachannel_community.DiscoveryBooster'): + with patch('tribler.core.components.gigachannel.community.gigachannel_community.DiscoveryBooster'): node = super().create_node(*args, **kwargs) self.count += 1 return node diff --git a/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager.py b/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager.py index e7ec65e30b3..ca3ceed54fe 100644 --- a/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager.py +++ b/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager.py @@ -103,7 +103,7 @@ async def mock_remove_download(download_obj, **_): # Test regenerating a non-empty channel gigachannel_manager.updated_my_channel = MagicMock() metadata_store.ChannelMetadata.consolidate_channel_torrent = lambda *_: MagicMock() - with patch("tribler_core.components.libtorrent.torrentdef.TorrentDef.load_from_dict"): + with patch("tribler.core.components.libtorrent.torrentdef.TorrentDef.load_from_dict"): await gigachannel_manager.regenerate_channel_torrent(chan_pk, chan_id) gigachannel_manager.updated_my_channel.assert_called_once() diff --git a/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py b/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py index 6b94b29685b..f6c6d4bda87 100644 --- a/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py +++ b/src/tribler/core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py @@ -98,7 +98,7 @@ async def mock_http_query(*_): with open(tmp_path / "ubuntu.torrent", 'rb') as f: return f.read() - with patch("tribler_core.components.libtorrent.restapi.torrentinfo_endpoint.query_http_uri", new=mock_http_query): + with patch("tribler.core.components.libtorrent.restapi.torrentinfo_endpoint.query_http_uri", new=mock_http_query): verify_valid_dict(await do_request(rest_api, url, params={'uri': path}, expected_code=200)) path = quote_plus(f'magnet:?xt=urn:btih:{hexlify(UBUNTU_1504_INFOHASH)}' diff --git a/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py b/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py index 31356caba25..65ad9879e97 100644 --- a/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py +++ b/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py @@ -533,7 +533,7 @@ async def test_drop_silent_peer(self): kwargs_dict = {"txt_filter": "ubuntu*"} - basic_path = 'tribler_core.components.metadata_store.remote_query_community.remote_query_community' + basic_path = 'tribler.core.components.metadata_store.remote_query_community.remote_query_community' with self.overlay(1).request_cache.passthrough(): # Stop peer 0 from responding diff --git a/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py b/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py index a424e780898..b6f69e6d2b3 100644 --- a/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py +++ b/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py @@ -565,7 +565,7 @@ async def _mock_fetch(*args): with open(TORRENT_UBUNTU_FILE, 'rb') as f: return f.read() - with patch('tribler_core.components.metadata_store.restapi.channels_endpoint._fetch_uri', new=_mock_fetch): + with patch('tribler.core.components.metadata_store.restapi.channels_endpoint._fetch_uri', new=_mock_fetch): await do_request( rest_api, f'channels/{hexlify(my_channel.public_key)}/{my_channel.id_}/torrents', diff --git a/src/tribler/core/components/restapi/rest/tests/test_debug_endpoint.py b/src/tribler/core/components/restapi/rest/tests/test_debug_endpoint.py index 55a5eacb013..442baf081b5 100644 --- a/src/tribler/core/components/restapi/rest/tests/test_debug_endpoint.py +++ b/src/tribler/core/components/restapi/rest/tests/test_debug_endpoint.py @@ -163,7 +163,7 @@ async def test_debug_pane_core_logs_in_root_dir(rest_api, tmp_path, endpoint): num_logs = 100 create_dummy_logs(root_state_dir, process=process, num_logs=num_logs) - with patch('tribler_core.components.restapi.rest.debug_endpoint.get_root_state_directory', + with patch('tribler.core.components.restapi.rest.debug_endpoint.get_root_state_directory', new=lambda: root_state_dir): json_response = await do_request(rest_api, f'debug/log?process={process}&max_lines={num_logs}', expected_code=200) logs = json_response['content'].strip().split("\n") @@ -194,7 +194,7 @@ async def test_debug_pane_no_logs(rest_api, endpoint, tmp_path): Test whether the API returns the default response when no log files are found. """ module = 'gui' - with patch('tribler_core.components.restapi.rest.debug_endpoint.get_root_state_directory', + with patch('tribler.core.components.restapi.rest.debug_endpoint.get_root_state_directory', new=lambda: tmp_path / 'nondir'): json_response = await do_request(rest_api, f'debug/log?process={module}&max_lines=', expected_code=200) diff --git a/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py b/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py index 334415cd798..2dedc20be75 100644 --- a/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py +++ b/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py @@ -85,7 +85,7 @@ async def test_unhandled_exception(rest_manager, api_port): Testing whether the API returns a formatted 500 error and calls exception handler if an unhandled Exception is raised """ - with patch('tribler_core.components.restapi.rest.rest_manager.default_core_exception_handler') as handler: + with patch('tribler.core.components.restapi.rest.rest_manager.default_core_exception_handler') as handler: response_dict = await do_real_request(api_port, 'settings', expected_code=500, post_data={'general': 'invalid schema'}, request_type='POST') diff --git a/src/tribler/core/logger/logger.py b/src/tribler/core/logger/logger.py index 417f50b9d99..a6f66cabe95 100644 --- a/src/tribler/core/logger/logger.py +++ b/src/tribler/core/logger/logger.py @@ -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_core/logger" + dirname = Path(getattr(sys, '_MEIPASS')) / "tribler_source/tribler/core/logger" return dirname / LOG_CONFIG_FILENAME diff --git a/src/tribler/core/logger/logger.yaml b/src/tribler/core/logger/logger.yaml index 53acc5a2321..967f6493d78 100644 --- a/src/tribler/core/logger/logger.yaml +++ b/src/tribler/core/logger/logger.yaml @@ -1,10 +1,10 @@ -# File: tribler_core/logger.yaml +# File: tribler.core/logger.yaml version: 1 disable_existing_loggers: false filters: stdout_filter: - () : tribler_core.logger.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_core.logger.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_core.logger.logger_streams.stderr_wrapper + stream: ext://tribler.core.logger.logger_streams.stderr_wrapper # Root Logger Configuration root: diff --git a/src/tribler/core/logger/tests/test_logger.py b/src/tribler/core/logger/tests/test_logger.py index a094ffc616f..111dbaf9b9f 100644 --- a/src/tribler/core/logger/tests/test_logger.py +++ b/src/tribler/core/logger/tests/test_logger.py @@ -6,7 +6,7 @@ from tribler.core.logger.logger_streams import StreamWrapper -@patch('tribler_core.logger.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[-7:] == ('x', 'y', 'z', 'tribler_source', 'tribler_core', 'logger', 'logger.yaml') + assert config_path.parts[-7:] == ('x', 'y', 'z', 'tribler_source', 'tribler', 'core', 'logger', 'logger.yaml') -@patch('tribler_core.logger.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_core.logger.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_core.logger.logger.logger') +@patch('tribler.core.logger.logger.logger') @patch('sys.stdout') @patch('sys.stderr') @patch('builtins.print') diff --git a/src/tribler/core/sentry_reporter/tests/test_sentry_reporter.py b/src/tribler/core/sentry_reporter/tests/test_sentry_reporter.py index fcd1ef98b54..af3ed41e5bc 100644 --- a/src/tribler/core/sentry_reporter/tests/test_sentry_reporter.py +++ b/src/tribler/core/sentry_reporter/tests/test_sentry_reporter.py @@ -23,7 +23,7 @@ def sentry_reporter(): return SentryReporter() -@patch('tribler_core.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_core.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_core.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_core.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_core.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/core/tests/test_check_os.py b/src/tribler/core/tests/test_check_os.py index 4354d6b22a4..1d7dcd508fe 100644 --- a/src/tribler/core/tests/test_check_os.py +++ b/src/tribler/core/tests/test_check_os.py @@ -15,7 +15,7 @@ @patch('sys.exit') -@patch('tribler_core.check_os.show_system_popup') +@patch('tribler.core.check_os.show_system_popup') async def test_error_and_exit(mocked_show_system_popup, mocked_sys_exit): error_and_exit('title', 'text') mocked_show_system_popup.assert_called_once_with('title', 'text') @@ -23,7 +23,7 @@ async def test_error_and_exit(mocked_show_system_popup, mocked_sys_exit): @patch_import(['faulthandler'], strict=True, enable=MagicMock()) -@patch('tribler_core.check_os.open', new=MagicMock()) +@patch('tribler.core.check_os.open', new=MagicMock()) async def test_enable_fault_handler(): import faulthandler enable_fault_handler(log_dir=MagicMock()) @@ -32,14 +32,14 @@ async def test_enable_fault_handler(): @patch_import(['faulthandler'], strict=True, always_raise_exception_on_import=True) @patch.object(Logger, 'error') -@patch('tribler_core.check_os.open', new=MagicMock()) +@patch('tribler.core.check_os.open', new=MagicMock()) async def test_enable_fault_handler_import_error(mocked_log_error: MagicMock): enable_fault_handler(log_dir=MagicMock()) mocked_log_error.assert_called_once() @patch_import(['faulthandler'], strict=True, enable=MagicMock()) -@patch('tribler_core.check_os.open', new=MagicMock()) +@patch('tribler.core.check_os.open', new=MagicMock()) async def test_enable_fault_handler_log_dir_not_exists(): log_dir = MagicMock(exists=MagicMock(return_value=False), mkdir=MagicMock()) @@ -48,9 +48,9 @@ async def test_enable_fault_handler_log_dir_not_exists(): log_dir.mkdir.assert_called_once() -@patch('tribler_core.check_os.logger.info') +@patch('tribler.core.check_os.logger.info') @patch('sys.argv', []) -@patch('tribler_core.check_os.get_existing_tribler_pid', MagicMock(return_value=100)) +@patch('tribler.core.check_os.get_existing_tribler_pid', MagicMock(return_value=100)) @patch('os.getpid', MagicMock(return_value=200)) @patch('psutil.Process', MagicMock(return_value=MagicMock(status=MagicMock(side_effect=psutil.NoSuchProcess(100))))) def test_should_kill_other_tribler_instances_process_not_found( @@ -61,13 +61,13 @@ def test_should_kill_other_tribler_instances_process_not_found( mocked_logger_info.assert_called_with('Old process not found') -@patch('tribler_core.check_os.logger.info') +@patch('tribler.core.check_os.logger.info') @patch('sys.argv', []) -@patch('tribler_core.check_os.get_existing_tribler_pid', MagicMock(return_value=100)) +@patch('tribler.core.check_os.get_existing_tribler_pid', MagicMock(return_value=100)) @patch('os.getpid', MagicMock(return_value=200)) @patch('psutil.Process', MagicMock(return_value=MagicMock(status=MagicMock(return_value=psutil.STATUS_ZOMBIE)))) -@patch('tribler_core.check_os.kill_tribler_process') -@patch('tribler_core.check_os.restart_tribler_properly') +@patch('tribler.core.check_os.kill_tribler_process') +@patch('tribler.core.check_os.restart_tribler_properly') def test_should_kill_other_tribler_instances_zombie( mocked_restart_tribler_properly: MagicMock, mocked_kill_tribler_process: MagicMock, diff --git a/src/tribler/core/tests/test_start_core.py b/src/tribler/core/tests/test_start_core.py index bd27dd3b5ae..784141be745 100644 --- a/src/tribler/core/tests/test_start_core.py +++ b/src/tribler/core/tests/test_start_core.py @@ -7,12 +7,12 @@ # fmt: off -@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('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()) -@patch('tribler_core.start_core.TriblerConfig.load', new=MagicMock()) -@patch('tribler_core.start_core.core_session') +@patch('tribler.core.start_core.TriblerConfig.load', new=MagicMock()) +@patch('tribler.core.start_core.core_session') def test_start_tribler_core_no_exceptions(mocked_core_session): # test that base logic of tribler core runs without exceptions run_tribler_core_session(1, 'key', Path('.'), False) diff --git a/src/tribler/core/upgrade/tests/test_version_manager.py b/src/tribler/core/upgrade/tests/test_version_manager.py index 3c1fdaf21f0..06c48f4859f 100644 --- a/src/tribler/core/upgrade/tests/test_version_manager.py +++ b/src/tribler/core/upgrade/tests/test_version_manager.py @@ -388,7 +388,7 @@ def test_coverage(tmpdir): (root_state_dir / 'triblerd.conf').write_text("abc") history = VersionHistory(root_state_dir) - assert history.code_version.version_str == tribler_core.version.version_id + assert history.code_version.version_str == tribler.core.version.version_id assert repr(history) == "" dirs = history.get_disposable_state_directories() diff --git a/src/tribler/core/utilities/dependencies.py b/src/tribler/core/utilities/dependencies.py index 4f65a4237e6..c47c53c3e6a 100644 --- a/src/tribler/core/utilities/dependencies.py +++ b/src/tribler/core/utilities/dependencies.py @@ -29,10 +29,10 @@ def _get_path_to_requirements_txt() -> Optional[Path]: requirements_txt = 'requirements.txt' if scope == Scope.core: import tribler.core - return Path(tribler_core.__file__).parent / requirements_txt + return Path(tribler.core.__file__).parent / requirements_txt if scope == Scope.gui: import tribler.gui - return Path(tribler_gui.__file__).parent / requirements_txt + return Path(tribler.gui.__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/utilities/install_dir.py b/src/tribler/core/utilities/install_dir.py index ba6833481a1..f877fedc46c 100644 --- a/src/tribler/core/utilities/install_dir.py +++ b/src/tribler/core/utilities/install_dir.py @@ -24,5 +24,5 @@ def get_base_path(): def get_lib_path(): if is_frozen(): - return get_base_path() / 'tribler_source' / 'tribler_core' + return get_base_path() / 'tribler_source/tribler/core' return get_base_path() diff --git a/src/tribler/core/utilities/tests/test_dependencies.py b/src/tribler/core/utilities/tests/test_dependencies.py index 9aeac7fe751..0270b437306 100644 --- a/src/tribler/core/utilities/tests/test_dependencies.py +++ b/src/tribler/core/utilities/tests/test_dependencies.py @@ -29,7 +29,7 @@ async def test_extract_libraries_from_requirements(): async def test_pip_dependencies_gen(): # check that libraries extracts from file correctly - path = Path(tribler_core.__file__).parent / 'requirements.txt' + path = Path(tribler.core.__file__).parent / 'requirements.txt' assert list(_get_pip_dependencies(path)) diff --git a/src/tribler/core/utilities/tests/test_utilities.py b/src/tribler/core/utilities/tests/test_utilities.py index cc9bf8adc14..7e5a6cd3071 100644 --- a/src/tribler/core/utilities/tests/test_utilities.py +++ b/src/tribler/core/utilities/tests/test_utilities.py @@ -160,7 +160,7 @@ def test_parse_query(): @patch_import(modules=['win32api'], MessageBox=MagicMock()) @patch('platform.system', new=MagicMock(return_value='Windows')) -@patch('tribler_core.utilities.utilities.print', new=MagicMock) +@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 @@ -181,7 +181,7 @@ def test_show_system_popup_win(): @patch_import(modules=['subprocess'], Popen=MagicMock()) @patch('platform.system', new=MagicMock(return_value='Linux')) -@patch('tribler_core.utilities.utilities.print', new=MagicMock) +@patch('tribler.core.utilities.utilities.print', new=MagicMock) def test_show_system_popup_linux(): import subprocess @@ -192,7 +192,7 @@ def test_show_system_popup_linux(): @patch_import(modules=['subprocess'], Popen=MagicMock()) @patch('platform.system', new=MagicMock(return_value='Darwin')) -@patch('tribler_core.utilities.print', new=MagicMock) +@patch('tribler.core.utilities.print', new=MagicMock) def test_show_system_popup_darwin(): import subprocess @@ -202,7 +202,7 @@ def test_show_system_popup_darwin(): @patch('platform.system', new=MagicMock(return_value='Unknown')) -@patch('tribler_core.utilities.utilities.print') +@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') @@ -210,7 +210,7 @@ def test_show_system_popup_unknown(mocked_print): @patch_import(modules=['subprocess'], Popen=MagicMock(side_effect=ValueError)) @patch('platform.system', new=MagicMock(return_value='Darwin')) -@patch('tribler_core.utilities.utilities.print') +@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') diff --git a/src/tribler/gui/tests/test_core_manager.py b/src/tribler/gui/tests/test_core_manager.py index 972e879197a..be00c8a95de 100644 --- a/src/tribler/gui/tests/test_core_manager.py +++ b/src/tribler/gui/tests/test_core_manager.py @@ -10,7 +10,7 @@ # fmt: off @patch.object(CoreManager, 'quit_application') -@patch('tribler_gui.core_manager.EventRequestManager', new=MagicMock()) +@patch('tribler.gui.core_manager.EventRequestManager', new=MagicMock()) async def test_on_core_finished_call_on_finished(mocked_quit_application: MagicMock): # test that in case of `shutting_down` and `should_quit_app_on_core_finished` flags have been set to True # then `on_finished` function will be called and Exception will not be raised @@ -22,7 +22,7 @@ async def test_on_core_finished_call_on_finished(mocked_quit_application: MagicM mocked_quit_application.assert_called_once() -@patch('tribler_gui.core_manager.EventRequestManager', new=MagicMock()) +@patch('tribler.gui.core_manager.EventRequestManager', new=MagicMock()) async def test_on_core_finished_raises_error(): # test that in case of flag `shutting_down` has been set to True and # exit_code is not equal to 0, then CoreRuntimeError should be raised @@ -32,8 +32,8 @@ async def test_on_core_finished_raises_error(): core_manager.on_core_finished(exit_code=1, exit_status='exit status') -@patch('tribler_gui.core_manager.print') -@patch('tribler_gui.core_manager.EventRequestManager', new=MagicMock()) +@patch('tribler.gui.core_manager.print') +@patch('tribler.gui.core_manager.EventRequestManager', new=MagicMock()) async def test_on_core_stdout_read_ready(mocked_print: MagicMock): # test that method `on_core_stdout_read_ready` converts byte output to a string and prints it core_manager = CoreManager(MagicMock(), MagicMock(), MagicMock(), MagicMock()) @@ -42,8 +42,8 @@ async def test_on_core_stdout_read_ready(mocked_print: MagicMock): mocked_print.assert_called_with('binary string') -@patch('tribler_gui.core_manager.print') -@patch('tribler_gui.core_manager.EventRequestManager', new=MagicMock()) +@patch('tribler.gui.core_manager.print') +@patch('tribler.gui.core_manager.EventRequestManager', new=MagicMock()) @patch('sys.stderr') async def test_on_core_stderr_read_ready(mocked_stderr, mocked_print: MagicMock): # test that method `on_core_stdout_read_ready` converts byte output to a string and prints it @@ -53,7 +53,7 @@ async def test_on_core_stderr_read_ready(mocked_stderr, mocked_print: MagicMock) mocked_print.assert_called_with('binary string', file=mocked_stderr) -@patch('tribler_gui.core_manager.EventRequestManager', new=MagicMock()) +@patch('tribler.gui.core_manager.EventRequestManager', new=MagicMock()) @patch('builtins.print', MagicMock(side_effect=OSError())) def test_on_core_stdout_stderr_read_ready_os_error(): # test that OSError on writing to stdout is suppressed when quitting the application diff --git a/src/tribler/gui/tests/test_error_handler.py b/src/tribler/gui/tests/test_error_handler.py index a8dd08596a4..1aa00fbccbd 100644 --- a/src/tribler/gui/tests/test_error_handler.py +++ b/src/tribler/gui/tests/test_error_handler.py @@ -24,7 +24,7 @@ def reported_error(): return ReportedError(type='Exception', text='text', event={}) -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') async def test_gui_error_tribler_stopped(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler): # test that while tribler_stopped is True FeedbackDialog is not called error_handler._tribler_stopped = True @@ -32,7 +32,7 @@ async def test_gui_error_tribler_stopped(mocked_feedback_dialog: MagicMock, erro mocked_feedback_dialog.assert_not_called() -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') @patch.object(SentryReporter, 'global_strategy', create=True, new=PropertyMock(return_value=SentryStrategy.SEND_SUPPRESSED)) async def test_gui_error_suppressed(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler): @@ -44,7 +44,7 @@ async def test_gui_error_suppressed(mocked_feedback_dialog: MagicMock, error_han logger_info_mock.assert_called_with('GUI error was suppressed and not sent to Sentry: AssertionError: error_text') -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') async def test_gui_info_type_in_handled_exceptions(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler): # test that if exception type in _handled_exceptions then FeedbackDialog is not called error_handler._handled_exceptions = {AssertionError} @@ -53,7 +53,7 @@ async def test_gui_info_type_in_handled_exceptions(mocked_feedback_dialog: Magic assert len(error_handler._handled_exceptions) == 1 -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') @patch.object(ErrorHandler, '_stop_tribler') async def test_gui_core_connect_timeout_error(mocked_stop_tribler, mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler): @@ -62,7 +62,7 @@ async def test_gui_core_connect_timeout_error(mocked_stop_tribler, mocked_feedba mocked_stop_tribler.assert_called_once() -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') @patch.object(ErrorHandler, '_stop_tribler') async def test_gui_core_connect_timeout_error(mocked_stop_tribler: MagicMock, mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler): @@ -72,7 +72,7 @@ async def test_gui_core_connect_timeout_error(mocked_stop_tribler: MagicMock, mo mocked_stop_tribler.assert_called_once() -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') @patch.object(ErrorHandler, '_stop_tribler') async def test_gui_is_not_core_exception(mocked_stop_tribler: MagicMock, mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler): @@ -83,7 +83,7 @@ async def test_gui_is_not_core_exception(mocked_stop_tribler: MagicMock, mocked_ mocked_stop_tribler.assert_not_called() -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') async def test_core_info_type_in_handled_exceptions(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler, reported_error: ReportedError): # test that if exception type in _handled_exceptions then FeedbackDialog is not called @@ -93,7 +93,7 @@ async def test_core_info_type_in_handled_exceptions(mocked_feedback_dialog: Magi assert len(error_handler._handled_exceptions) == 1 -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') async def test_core_should_stop(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler, reported_error: ReportedError): # test that in case of "should_stop=True", Tribler should stop it's work @@ -103,7 +103,7 @@ async def test_core_should_stop(mocked_feedback_dialog: MagicMock, error_handler error_handler._stop_tribler.assert_called_once() -@patch('tribler_gui.error_handler.FeedbackDialog') +@patch('tribler.gui.error_handler.FeedbackDialog') async def test_core_error(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler, reported_error: ReportedError): # test that core_error creates FeedbackDialog diff --git a/src/tribler/gui/tests/test_gui.py b/src/tribler/gui/tests/test_gui.py index 959d4941745..91c4b5a3794 100644 --- a/src/tribler/gui/tests/test_gui.py +++ b/src/tribler/gui/tests/test_gui.py @@ -29,7 +29,7 @@ from tribler.gui.widgets.tagbutton import TagButton from tribler.gui.widgets.torrentfiletreewidget import CHECKBOX_COL -RUN_TRIBLER_PY = Path(tribler_gui.__file__).parent.parent.parent / "run_tribler.py" +RUN_TRIBLER_PY = Path(tribler.gui.__file__).parent.parent.parent / "run_tribler.py" TORRENT_WITH_DIRS = TESTS_DATA_DIR / "multi_entries.torrent" @@ -130,7 +130,7 @@ def screenshot(widget, name=None): if name is not None: img_name = f"screenshot_{name}.jpg" - screenshots_dir = os.path.join(os.path.dirname(tribler_gui.__file__), 'screenshots') + screenshots_dir = os.path.join(os.path.dirname(tribler.gui.__file__), 'screenshots') if not os.path.exists(screenshots_dir): os.mkdir(screenshots_dir) diff --git a/tribler.spec b/tribler.spec index b79594c829e..3192b1fc98e 100644 --- a/tribler.spec +++ b/tribler.spec @@ -15,15 +15,13 @@ root_dir = os.path.abspath(os.path.dirname(__name__)) src_dir = os.path.join(root_dir, "src") tribler_components = [ - os.path.join(src_dir, "pyipv8"), - os.path.join(src_dir, "tribler-core"), - os.path.join(src_dir, "tribler-gui"), + os.path.join(src_dir, "tribler"), ] for component in tribler_components: sys.path.append(str(component)) -from tribler_core.version import version_id +from tribler.core.version import version_id version_str = version_id.split('-')[0] # On macOS, we always show the console to prevent the double-dock bug (although the OS does not actually show the console). @@ -33,16 +31,16 @@ if sys.platform == 'darwin': show_console = True widget_files = [] -for file in os.listdir(os.path.join(src_dir, "tribler-gui", "tribler_gui", "widgets")): +for file in os.listdir(os.path.join(src_dir, "tribler", "gui", "widgets")): if file.endswith(".py"): widget_files.append('tribler_gui.widgets.%s' % file[:-3]) 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-core", "tribler_core"), 'tribler_source/tribler_core'), - (os.path.join(src_dir, "tribler-gui", "tribler_gui"), 'tribler_source/tribler_gui'), + (os.path.join(src_dir, "tribler", "gui", "qt_resources"), 'qt_resources'), + (os.path.join(src_dir, "tribler", "gui", "images"), 'images'), + (os.path.join(src_dir, "tribler", "gui", "i18n"), 'i18n'), + (os.path.join(src_dir, "tribler", "core"), 'tribler_source/tribler/core'), + (os.path.join(src_dir, "tribler", "gui"), 'tribler_source/tribler/gui'), (os.path.join(root_dir, "build", "win", "resources"), 'tribler_source/resources'), (os.path.dirname(aiohttp_apispec.__file__), 'aiohttp_apispec') ]