Skip to content

Commit

Permalink
PyLint
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jun 21, 2021
1 parent 8ff88c2 commit 6c25dac
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ async def test_put_path_absolute(tmpdir):


@pytest.mark.asyncio
async def test_null_replacement(tmpdir):
async def test_null_replacement():
section = TriblerTestConfigSection(path='None')
assert section.path is None
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_path_as_absolute(self, property_name: str, state_dir: Path = None) -> Op
return state_dir / path

@root_validator(pre=True)
def convert_from_none_string_to_none_type(cls, values):
def convert_from_none_string_to_none_type(cls, values): # pylint: disable=no-self-argument
"""After a convert operation from "ini" to "pydantic", None values
becomes 'None' string values.
Expand Down
12 changes: 6 additions & 6 deletions src/tribler-core/tribler_core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def get_free_port():

@pytest.fixture
def seed_config(tribler_config, tmpdir_factory):
seed_config = tribler_config.copy(deep=True)
seed_config.set_state_dir(tmpdir_factory.mktemp("seeder"))
seed_config.libtorrent.enabled = True
seed_config.libtorrent.port = get_free_port()
seed_config.tunnel_community.socks5_listen_ports = [(get_free_port()) for _ in range(5)]
config = tribler_config.copy(deep=True)
config.set_state_dir(tmpdir_factory.mktemp("seeder"))
config.libtorrent.enabled = True
config.libtorrent.port = get_free_port()
config.tunnel_community.socks5_listen_ports = [(get_free_port()) for _ in range(5)]

return seed_config
return config


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tribler_core.config.tribler_config_section import TriblerConfigSection


# pylint: disable=no-self-argument
@validator('port', 'anon_listen_port')
def validate_port_with_minus_one(v):
assert v is None or -1 <= v <= NetworkUtils.MAX_PORT, 'Port must be in range [-1..65535]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def test_proxy_type_validation():


@pytest.mark.asyncio
async def test_proxy_type_validation():
async def test_anon_proxy_server_ip_validation():
settings = LibtorrentSettings(anon_proxy_server_ip='127.0.0.1')
assert settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@pytest.mark.asyncio
@pytest.mark.timeout(20)
async def test_channel_update_and_download(
enable_chant, channel_tdef, channel_seeder_session, session
enable_chant, channel_tdef, channel_seeder_session, session # pylint: disable=unused-argument
):
"""
Test whether we can successfully update a channel and download the new version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class PopularityCommunitySettings(TriblerConfigSection):
enabled: bool = True
cache_dir: str = 'health_cache'
cache_dir: str = 'health_cache'
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tribler_core.config.tribler_config_section import TriblerConfigSection


# pylint: disable=no-self-argument
class ResourceMonitorSettings(TriblerConfigSection):
enabled: bool = True
cpu_priority: int = 1
Expand Down
2 changes: 2 additions & 0 deletions src/tribler-core/tribler_core/modules/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from pydantic import validator

from tribler_common.network_utils import NetworkUtils

from tribler_core.config.tribler_config_section import TriblerConfigSection


# pylint: disable=no-self-argument
class BootstrapSettings(TriblerConfigSection):
enabled: bool = True
max_download_rate: int = 1000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def test_watchfolder_no_torrent_file(enable_watch_folder, mock_dlmgr, tribler_st


def test_watchfolder_invalid_dir(enable_watch_folder, mock_dlmgr, tribler_state_dir, session):
shutil.copyfile(TORRENT_UBUNTU_FILE, tribler_state_dir / "watch" / "test.txt")
session.config.watch_folder.put_path_as_relative('directory', tribler_state_dir / "watch" / "test.txt", tribler_state_dir)
file = tribler_state_dir / "watch" / "test.txt"
shutil.copyfile(TORRENT_UBUNTU_FILE, file)
session.config.watch_folder.put_path_as_relative('directory', file, tribler_state_dir)
session.watch_folder.check_watch_folder()
session.dlmgr.start_download.assert_not_called()

Expand Down
1 change: 0 additions & 1 deletion src/tribler-core/tribler_core/modules/watch_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ipv8.taskmanager import TaskManager

from tribler_common.simpledefs import NTFY
from tribler_core.config.tribler_config import TriblerConfig

from tribler_core.modules.libtorrent.download_config import DownloadConfig, get_default_dest_dir
from tribler_core.modules.libtorrent.torrentdef import TorrentDef
Expand Down
5 changes: 3 additions & 2 deletions src/tribler-core/tribler_core/restapi/debug_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ async def get_log(self, request):
# Get the location of log file
param_process = request.query.get('process', 'core')
config = self.session.config
log_file_name = config.general.get_path_as_absolute('log_dir', config.state_dir) / f'tribler-{param_process}-info.log'
log_name = f'tribler-{param_process}-info.log'
log_file_name = config.general.get_path_as_absolute('log_dir', config.state_dir) / log_name

# If the log file is not present in the versioned state directory, try root state directory location
if not log_file_name.exists():
log_file_name = get_root_state_directory() / (f'tribler-{param_process}-info.log')
log_file_name = get_root_state_directory() / log_name

# If the log file is still not found, maybe it is not created yet, then return the default response
if not log_file_name.exists():
Expand Down
19 changes: 11 additions & 8 deletions src/tribler-core/tribler_core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def __init__(self, config, core_test_mode=False):
self.wallets = {}
self.popularity_community = None
self.gigachannel_community = None
self.trustchain_keypair = None
self.trustchain_testnet_keypair = None

self.dht_community = None
self.payout_manager = None
Expand Down Expand Up @@ -176,27 +178,28 @@ def init_keypair(self):
"""
Set parameters that depend on state_dir.
"""
trustchain_pairfilename = self.config.trustchain.get_path_as_absolute('ec_keypair_filename', self.config.state_dir)
keypair_filename = self.config.trustchain.get_path_as_absolute('ec_keypair_filename', self.config.state_dir)
state_dir = self.config.state_dir
if trustchain_pairfilename.exists():
self.trustchain_keypair = permid_module.read_keypair_trustchain(trustchain_pairfilename)
if keypair_filename.exists():
self.trustchain_keypair = permid_module.read_keypair_trustchain(keypair_filename)
else:
self.trustchain_keypair = permid_module.generate_keypair_trustchain()

# Save keypair
trustchain_pubfilename = state_dir / 'ecpub_multichain.pem'
permid_module.save_keypair_trustchain(self.trustchain_keypair, trustchain_pairfilename)
permid_module.save_keypair_trustchain(self.trustchain_keypair, keypair_filename)
permid_module.save_pub_key_trustchain(self.trustchain_keypair, trustchain_pubfilename)

trustchain_testnet_pairfilename = self.config.trustchain.get_path_as_absolute('testnet_keypair_filename', self.config.state_dir)
if trustchain_testnet_pairfilename.exists():
self.trustchain_testnet_keypair = permid_module.read_keypair_trustchain(trustchain_testnet_pairfilename)
testnet_keypair_filename = self.config.trustchain.get_path_as_absolute('testnet_keypair_filename',
self.config.state_dir)
if testnet_keypair_filename.exists():
self.trustchain_testnet_keypair = permid_module.read_keypair_trustchain(testnet_keypair_filename)
else:
self.trustchain_testnet_keypair = permid_module.generate_keypair_trustchain()

# Save keypair
trustchain_testnet_pubfilename = state_dir / 'ecpub_trustchain_testnet.pem'
permid_module.save_keypair_trustchain(self.trustchain_testnet_keypair, trustchain_testnet_pairfilename)
permid_module.save_keypair_trustchain(self.trustchain_testnet_keypair, testnet_keypair_filename)
permid_module.save_pub_key_trustchain(self.trustchain_testnet_keypair, trustchain_testnet_pubfilename)

def unhandled_error_observer(self, loop, context):
Expand Down

0 comments on commit 6c25dac

Please sign in to comment.