From bedb4051ae5f448d54ea6b2c9dae7c197c200ddd Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Mon, 11 Nov 2024 17:48:45 -0500 Subject: [PATCH] pylint now fails under a rating of 7, current rating 9.42. Refactored some stuff --- .github/workflows/pylint.yml | 4 +++- backend/code/__init__.py | 3 +++ backend/code/main.py | 7 ++++--- backend/code/p2p_client.py | 6 +++--- backend/code/utils.py | 2 +- backend/test/__init__.py | 4 ++++ backend/test/test_utils.py | 4 ++-- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index eb26ac4..6ce92ef 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -17,8 +17,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + cd backend + pip install -r requirements.txt pip install pylint - name: Analysing the code with pylint run: | cd backend - pylint $(git ls-files '*.py') + pylint --fail-under=7.0 $(git ls-files '*.py') diff --git a/backend/code/__init__.py b/backend/code/__init__.py index e69de29..ca0e366 100644 --- a/backend/code/__init__.py +++ b/backend/code/__init__.py @@ -0,0 +1,3 @@ +""" +TODO +""" diff --git a/backend/code/main.py b/backend/code/main.py index 0d9d088..95f61e8 100644 --- a/backend/code/main.py +++ b/backend/code/main.py @@ -6,13 +6,14 @@ import io import json +from code.utils import get_filename_by_file_id, custom_hash +from code.p2p_client import P2PClient +from code.file_tokenizer import SenderTokenizer + from pathlib import Path from flask_cors import CORS from flask import Flask, request, jsonify, send_file -from utils import get_filename_by_file_id, custom_hash -from p2p_client import P2PClient -from file_tokenizer import SenderTokenizer app = Flask(__name__) CORS(app) diff --git a/backend/code/p2p_client.py b/backend/code/p2p_client.py index ff12327..ec56f4b 100644 --- a/backend/code/p2p_client.py +++ b/backend/code/p2p_client.py @@ -11,8 +11,8 @@ from pathlib import Path -from utils import get_filename_by_file_id -from file_tokenizer import ReceiverTokenizer +from code.utils import get_filename_by_file_id +from code.file_tokenizer import ReceiverTokenizer from config import DISCOVERY_PORT, CHAT_PORT, MAX_UDP_PACKET, DISCOVERY_ADDRESS @@ -23,7 +23,7 @@ class P2PClient: def __init__(self): self.user_id = uuid.uuid1().__str__() - self.peers = dict() + self.peers = {} self.discovery_socket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM) self.discovery_socket.setsockopt( diff --git a/backend/code/utils.py b/backend/code/utils.py index ff3ae94..8ddb677 100644 --- a/backend/code/utils.py +++ b/backend/code/utils.py @@ -23,7 +23,7 @@ def find_file(directory, filename): if os.path.exists(directory): for file in os.listdir(directory): - name, ext = os.path.splitext(file) + name, _ = os.path.splitext(file) if name == filename: return file return None diff --git a/backend/test/__init__.py b/backend/test/__init__.py index 99f4cf5..e3e2063 100644 --- a/backend/test/__init__.py +++ b/backend/test/__init__.py @@ -1,3 +1,7 @@ +""" +TODO +""" + import os import sys diff --git a/backend/test/test_utils.py b/backend/test/test_utils.py index 26bf23d..0293709 100644 --- a/backend/test/test_utils.py +++ b/backend/test/test_utils.py @@ -11,14 +11,14 @@ class TestUtils(unittest.TestCase): TODO """ - def test_find_file_with_garbage_file_name_returns_None(self): + def test_find_file_with_garbage_file_name_returns_none(self): """ If a file does not exist, find_file should return None """ self.assertEqual(find_file("uploads", "random_file.txt"), None) - def test_find_file_with_garbage_directory_name_returns_None(self): + def test_find_file_with_garbage_directory_name_returns_none(self): """ If a directory does not exist, find_file should return None """