Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Mar 9, 2022
1 parent fa9283f commit 50c9571
Show file tree
Hide file tree
Showing 30 changed files with 90 additions and 95 deletions.
2 changes: 1 addition & 1 deletion build/debian/makedist_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build/mac/makedist_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build/systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions build/systemd/bandwidth-crawler.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion build/update_version_from_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
2 changes: 1 addition & 1 deletion build/win/makedist_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions doc/extract_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 4 additions & 4 deletions src/tribler/core/logger/logger.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src/tribler/core/logger/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
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
assert config_path.parts[-4:] == ('a', 'b', 'c', 'logger.yaml')

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')
Expand All @@ -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 = '<log-dir>'
Expand Down Expand Up @@ -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')
Expand Down
10 changes: 5 additions & 5 deletions src/tribler/core/sentry_reporter/tests/test_sentry_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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')
Expand All @@ -64,15 +64,15 @@ 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')
sentry_reporter.capture_exception(exception)
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) == {}
Expand Down
20 changes: 10 additions & 10 deletions src/tribler/core/tests/test_check_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@


@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')
mocked_sys_exit.assert_called_once_with(1)


@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())
Expand All @@ -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())
Expand All @@ -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(
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/tribler/core/tests/test_start_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/upgrade/tests/test_version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) == "<VersionHistory[(7, 6), (7, 5)]>"

dirs = history.get_disposable_state_directories()
Expand Down
Loading

0 comments on commit 50c9571

Please sign in to comment.