From 3f2346eb0121b0a39194e2d5e6150567a4ea1af0 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 24 Feb 2020 13:34:13 -0300 Subject: [PATCH] linting and minor refactor --- .github/workflows/main.yml | 2 ++ Makefile | 2 +- lbry/torrent/session.py | 41 +++++++++++++++++++------------------- setup.cfg | 4 ++-- tox.ini | 3 +-- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fab46fcf4..ad3156f23 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,6 +43,8 @@ jobs: python-version: '3.7' - if: matrix.test == 'other' run: sudo apt install -y --no-install-recommends ffmpeg + - if: matrix.test == 'datanetwork' + run: sudo apt install -y --no-install-recommends libboost1.67-all-dev - run: pip install tox-travis - run: tox -e ${{ matrix.test }} diff --git a/Makefile b/Makefile index f84b5a8e7..a63f302bb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: install tools lint test idea install: - pip install -e git+https://github.com/shyba/libtorrent.git#egg=python-libtorrent + pip install https://s3.amazonaws.com/files.lbry.io/python_libtorrent-1.2.4-py2.py3-none-any.whl CFLAGS="-DSQLITE_MAX_VARIABLE_NUMBER=2500000" pip install -U https://github.com/rogerbinns/apsw/releases/download/3.30.1-r1/apsw-3.30.1-r1.zip \ --global-option=fetch \ --global-option=--version --global-option=3.30.1 --global-option=--all \ diff --git a/lbry/torrent/session.py b/lbry/torrent/session.py index 89cda059a..f3bbd2c53 100644 --- a/lbry/torrent/session.py +++ b/lbry/torrent/session.py @@ -74,9 +74,9 @@ class TorrentHandle: self.metadata_completed.set() log.info("Metadata completed for btih:%s - %s", status.info_hash, self.name) if not status.is_seeding: - log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s' % ( - status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000, - status.num_peers, status.num_seeds, status.state, status.save_path)) + log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s', + status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000, + status.num_peers, status.num_seeds, status.state, status.save_path) elif not self.finished.is_set(): self.finished.set() log.info("Torrent finished: %s", self.name) @@ -95,7 +95,7 @@ class TorrentHandle: async def resume(self): await self._loop.run_in_executor( - self._executor, self._handle.resume + self._executor, lambda: self._handle.resume() # pylint: disable=unnecessary-lambda ) @@ -108,28 +108,15 @@ class TorrentSession: self.tasks = [] async def add_fake_torrent(self): - dir = mkdtemp() - info, btih = self._create_fake(dir) + tmpdir = mkdtemp() + info, btih = _create_fake_torrent(tmpdir) flags = libtorrent.add_torrent_params_flags_t.flag_seed_mode handle = self._session.add_torrent({ - 'ti': info, 'save_path': dir, 'flags': flags + 'ti': info, 'save_path': tmpdir, 'flags': flags }) self._handles[btih] = TorrentHandle(self._loop, self._executor, handle) return btih - def _create_fake(self, dir): - # beware, that's just for testing - path = os.path.join(dir, 'tmp') - with open(path, 'wb') as myfile: - size = myfile.write(b'0' * 40 * 1024 * 1024) - fs = libtorrent.file_storage() - fs.add_file('tmp', size) - t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024) - libtorrent.set_piece_hashes(t, dir) - info = libtorrent.torrent_info(t.generate()) - btih = sha1(info.metadata()).hexdigest() - return info, btih - async def bind(self, interface: str = '0.0.0.0', port: int = 10889): settings = { 'listen_interfaces': f"{interface}:{port}", @@ -216,6 +203,20 @@ def get_magnet_uri(btih): return f"magnet:?xt=urn:btih:{btih}" +def _create_fake_torrent(tmpdir): + # beware, that's just for testing + path = os.path.join(tmpdir, 'tmp') + with open(path, 'wb') as myfile: + size = myfile.write(b'0' * 40 * 1024 * 1024) + file_storage = libtorrent.file_storage() + file_storage.add_file('tmp', size) + t = libtorrent.create_torrent(file_storage, 0, 4 * 1024 * 1024) + libtorrent.set_piece_hashes(t, tmpdir) + info = libtorrent.torrent_info(t.generate()) + btih = sha1(info.metadata()).hexdigest() + return info, btih + + async def main(): if os.path.exists("~/Downloads/ubuntu-18.04.3-live-server-amd64.torrent"): os.remove("~/Downloads/ubuntu-18.04.3-live-server-amd64.torrent") diff --git a/setup.cfg b/setup.cfg index 8bad7f04e..e8bc1920b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,19 +6,19 @@ source = lbry .tox/*/lib/python*/site-packages/lbry -[cryptography.*,coincurve.*,pbkdf2] +[cryptography.*,coincurve.*,pbkdf2, libtorrent] ignore_missing_imports = True [pylint] jobs=8 ignore=words,server,rpc,schema,winpaths.py,migrator,undecorated.py -extension-pkg-whitelist=libtorrent max-parents=10 max-args=10 max-line-length=120 good-names=T,t,n,i,j,k,x,y,s,f,d,h,c,e,op,db,tx,io,cachedproperty,log,id,r,iv,ts,l valid-metaclass-classmethod-first-arg=mcs disable= + c-extension-no-member, fixme, broad-except, no-else-return, diff --git a/tox.ini b/tox.ini index b055e7178..b2485aecb 100644 --- a/tox.ini +++ b/tox.ini @@ -7,8 +7,7 @@ changedir = {toxinidir}/tests setenv = HOME=/tmp commands = - pip install -U pip - pip install -e 'git+https://github.com/shyba/libtorrent.git#egg=python-libtorrent' + pip install https://s3.amazonaws.com/files.lbry.io/python_libtorrent-1.2.4-py2.py3-none-any.whl pip install https://github.com/rogerbinns/apsw/releases/download/3.30.1-r1/apsw-3.30.1-r1.zip \ --global-option=fetch \ --global-option=--version --global-option=3.30.1 --global-option=--all \