From f156e21537ba6bc5bcfdcb2d2ec1875a0e948d3c Mon Sep 17 00:00:00 2001 From: E3E Date: Tue, 20 Feb 2024 22:57:53 -0500 Subject: [PATCH] remove pylint and suppressed inline errors from pylint Signed-off-by: E3E --- .github/dependabot.yml | 1 - examples/uploader/_localrepo.py | 3 +- pyproject.toml | 50 ----------------------- requirements/lint.txt | 1 - tests/repository_simulator.py | 1 - tests/test_api.py | 5 +-- tests/test_examples.py | 1 - tests/test_metadata_eq_.py | 2 +- tests/test_metadata_serialization.py | 1 - tests/test_trusted_metadata_set.py | 1 - tests/test_updater_consistent_snapshot.py | 1 - tests/test_updater_delegation_graphs.py | 1 - tests/test_updater_fetch_target.py | 1 - tests/test_updater_key_rotations.py | 4 -- tests/test_updater_ng.py | 2 - tests/test_updater_top_level_update.py | 2 - tests/test_updater_validation.py | 1 - tests/test_utils.py | 1 - tests/utils.py | 2 - tox.ini | 1 - tuf/api/exceptions.py | 1 - tuf/api/metadata.py | 6 --- tuf/api/serialization/__init__.py | 1 - tuf/api/serialization/json.py | 1 - 24 files changed, 3 insertions(+), 88 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 58391f2e..ed5569da 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -18,7 +18,6 @@ updates: - "bandit" - "coverage" - "mypy" - - "pylint" - "ruff" - "tox" dependencies: diff --git a/examples/uploader/_localrepo.py b/examples/uploader/_localrepo.py index 351b99e2..554c85ba 100644 --- a/examples/uploader/_localrepo.py +++ b/examples/uploader/_localrepo.py @@ -62,7 +62,6 @@ def open(self, role: str) -> Metadata: # if there is a metadata version fetched from remote, use that # HACK: access Updater internals - # pylint: disable=protected-access if role in self.updater._trusted_set: return copy.deepcopy(self.updater._trusted_set[role]) @@ -105,7 +104,7 @@ def add_target(self, role: str, targetpath: str) -> bool: with self.edit_targets(role) as delegated: delegated.targets[targetpath] = targetfile - except Exception as e: # pylint: disable=broad-except + except Exception as e: print(f"Failed to submit new {role} with added target: {e}") return False diff --git a/pyproject.toml b/pyproject.toml index da3ecb88..455bd6b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,56 +95,6 @@ ignore = ["D400","D415","D213","D205","D202","D107","D407","D413","D212","D104", "tests/*" = ["D", "E"] "examples/*/*" = ["D"] -# Pylint section - -# Minimal pylint configuration file for Secure Systems Lab Python Style Guide: -# https://github.com/secure-systems-lab/code-style-guidelines -# -# Based on Google Python Style Guide pylintrc and pylint defaults: -# https://google.github.io/styleguide/pylintrc -# http://pylint.pycqa.org/en/latest/technical_reference/features.html - -[tool.pylint.message_control] -# Disable the message, report, category or checker with the given id(s). -# NOTE: To keep this config as short as possible we only disable checks that -# are currently in conflict with our code. If new code displeases the linter -# (for good reasons) consider updating this config file, or disable checks with. -disable=[ - "fixme", - "too-few-public-methods", - "too-many-arguments", - "format", - "duplicate-code" -] - -[tool.pylint.basic] -good-names = ["i","j","k","v","e","f","fn","fp","_type","_"] -# Regexes for allowed names are copied from the Google pylintrc -# NOTE: Pylint captures regex name groups such as 'snake_case' or 'camel_case'. -# If there are multiple groups it enfoces the prevalent naming style inside -# each modules. Names in the exempt capturing group are ignored. -function-rgx="^(?:(?PsetUp|tearDown|setUpModule|tearDownModule)|(?P_?[A-Z][a-zA-Z0-9]*)|(?P_?[a-z][a-z0-9_]*))$" -method-rgx="(?x)^(?:(?P_[a-z0-9_]+__|runTest|setUp|tearDown|setUpTestCase|tearDownTestCase|setupSelf|tearDownClass|setUpClass|(test|assert)_*[A-Z0-9][a-zA-Z0-9_]*|next)|(?P_{0,2}[A-Z][a-zA-Z0-9_]*)|(?P_{0,2}[a-z][a-z0-9_]*))$" -argument-rgx="^[a-z][a-z0-9_]*$" -attr-rgx="^_{0,2}[a-z][a-z0-9_]*$" -class-attribute-rgx="^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$" -class-rgx="^_?[A-Z][a-zA-Z0-9]*$" -const-rgx="^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$" -inlinevar-rgx="^[a-z][a-z0-9_]*$" -module-rgx="^(_?[a-z][a-z0-9_]*|__init__)$" -no-docstring-rgx="(__.*__|main|test.*|.*test|.*Test)$" -variable-rgx="^[a-z][a-z0-9_]*$" -docstring-min-length=10 - -[tool.pylint.logging] -logging-format-style="old" - -[tool.pylint.miscellaneous] -notes="TODO" - -[tool.pylint.STRING] -check-quote-consistency="yes" - # mypy section # Read more here: https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file [tool.mypy] diff --git a/requirements/lint.txt b/requirements/lint.txt index 0a779191..68648084 100644 --- a/requirements/lint.txt +++ b/requirements/lint.txt @@ -6,7 +6,6 @@ # Lint tools # (We are not so interested in the specific versions of the tools: the versions # are pinned to prevent unexpected linting failures when tools update) -pylint==3.0.3 ruff==0.2.1 mypy==1.8.0 bandit==1.7.7 diff --git a/tests/repository_simulator.py b/tests/repository_simulator.py index 1e8bebe9..f51b0f98 100644 --- a/tests/repository_simulator.py +++ b/tests/repository_simulator.py @@ -99,7 +99,6 @@ class RepositoryTarget: class RepositorySimulator(FetcherInterface): """Simulates a repository that can be used for testing.""" - # pylint: disable=too-many-instance-attributes def __init__(self) -> None: self.md_delegates: Dict[str, Metadata[Targets]] = {} diff --git a/tests/test_api.py b/tests/test_api.py index 74d41e04..1ebece61 100755 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -56,7 +56,6 @@ logger = logging.getLogger(__name__) -# pylint: disable=too-many-public-methods,too-many-statements class TestMetadata(unittest.TestCase): """Tests for public API of all classes in 'tuf/api/metadata.py'.""" @@ -246,7 +245,7 @@ def test_sign_failures(self) -> None: os.path.join(self.repo_dir, "metadata", "snapshot.json") ) - class FailingSigner(Signer): # pylint: disable=missing-class-docstring + class FailingSigner(Signer): @classmethod def from_priv_key_uri( cls, @@ -365,7 +364,6 @@ def test_metadata_verify_delegate(self) -> None: role2.verify_delegate("role1", role1) def test_signed_verify_delegate(self) -> None: - # pylint: disable=too-many-locals,too-many-statements root_path = os.path.join(self.repo_dir, "metadata", "root.json") root_md = Metadata[Root].from_file(root_path) root = root_md.signed @@ -742,7 +740,6 @@ def test_root_add_key_and_revoke_key(self) -> None: root.signed.revoke_key(keyid, "nosuchrole") def test_is_target_in_pathpattern(self) -> None: - # pylint: disable=protected-access supported_use_cases = [ ("foo.tgz", "foo.tgz"), ("foo.tgz", "*"), diff --git a/tests/test_examples.py b/tests/test_examples.py index 3fd24d03..c382d7ba 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -53,7 +53,6 @@ def _run_script_and_assert_files( CWD.""" script_path = str(self.repo_examples_dir / script_name) with open(script_path, "rb") as f: - # pylint: disable=exec-used exec( compile(f.read(), script_path, "exec"), {"__file__": script_path}, diff --git a/tests/test_metadata_eq_.py b/tests/test_metadata_eq_.py index dcadb444..d806d0ba 100644 --- a/tests/test_metadata_eq_.py +++ b/tests/test_metadata_eq_.py @@ -89,7 +89,7 @@ def setUpClass(cls) -> None: @utils.run_sub_tests_with_dataset(classes_attributes_modifications) def test_classes_eq_(self, test_case_data: Dict[str, Any]) -> None: - obj = self.objects[self.case_name] # pylint: disable=no-member + obj = self.objects[self.case_name] # Assert that obj is not equal to an object from another type self.assertNotEqual(obj, "") diff --git a/tests/test_metadata_serialization.py b/tests/test_metadata_serialization.py index cc3bee37..5fb8d3fd 100644 --- a/tests/test_metadata_serialization.py +++ b/tests/test_metadata_serialization.py @@ -34,7 +34,6 @@ logger = logging.getLogger(__name__) -# pylint: disable=too-many-public-methods class TestSerialization(unittest.TestCase): """Test serialization for all classes in 'tuf/api/metadata.py'.""" diff --git a/tests/test_trusted_metadata_set.py b/tests/test_trusted_metadata_set.py index dce680d4..13e7e540 100644 --- a/tests/test_trusted_metadata_set.py +++ b/tests/test_trusted_metadata_set.py @@ -29,7 +29,6 @@ logger = logging.getLogger(__name__) -# pylint: disable=too-many-public-methods class TestTrustedMetadataSet(unittest.TestCase): """Tests for all public API of the TrustedMetadataSet class.""" diff --git a/tests/test_updater_consistent_snapshot.py b/tests/test_updater_consistent_snapshot.py index e4bab8a8..b0b85a5f 100644 --- a/tests/test_updater_consistent_snapshot.py +++ b/tests/test_updater_consistent_snapshot.py @@ -32,7 +32,6 @@ class TestConsistentSnapshot(unittest.TestCase): dump_dir: Optional[str] = None def setUp(self) -> None: - # pylint: disable=consider-using-with self.subtest_count = 0 self.temp_dir = tempfile.TemporaryDirectory() self.metadata_dir = os.path.join(self.temp_dir.name, "metadata") diff --git a/tests/test_updater_delegation_graphs.py b/tests/test_updater_delegation_graphs.py index ca04621d..373be15d 100644 --- a/tests/test_updater_delegation_graphs.py +++ b/tests/test_updater_delegation_graphs.py @@ -67,7 +67,6 @@ class TestDelegations(unittest.TestCase): dump_dir: Optional[str] = None def setUp(self) -> None: - # pylint: disable=consider-using-with self.subtest_count = 0 self.temp_dir = tempfile.TemporaryDirectory() self.metadata_dir = os.path.join(self.temp_dir.name, "metadata") diff --git a/tests/test_updater_fetch_target.py b/tests/test_updater_fetch_target.py index 7207d0fd..af4bb4be 100644 --- a/tests/test_updater_fetch_target.py +++ b/tests/test_updater_fetch_target.py @@ -34,7 +34,6 @@ class TestFetchTarget(unittest.TestCase): dump_dir: Optional[str] = None def setUp(self) -> None: - # pylint: disable-next=consider-using-with self.temp_dir = tempfile.TemporaryDirectory() self.metadata_dir = os.path.join(self.temp_dir.name, "metadata") self.targets_dir = os.path.join(self.temp_dir.name, "targets") diff --git a/tests/test_updater_key_rotations.py b/tests/test_updater_key_rotations.py index 7bfc77ad..62212806 100644 --- a/tests/test_updater_key_rotations.py +++ b/tests/test_updater_key_rotations.py @@ -41,7 +41,6 @@ class TestUpdaterKeyRotations(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - # pylint: disable-next=consider-using-with cls.temp_dir = tempfile.TemporaryDirectory() # Pre-create a bunch of keys and signers @@ -58,14 +57,12 @@ def tearDownClass(cls) -> None: def setup_subtest(self) -> None: # Setup repository for subtest: make sure no roots have been published - # pylint: disable=attribute-defined-outside-init self.sim = RepositorySimulator() self.sim.signed_roots.clear() self.sim.root.version = 0 if self.dump_dir is not None: # create subtest dumpdir - # pylint: disable=no-member name = f"{self.id().split('.')[-1]}-{self.case_name}" self.sim.dump_dir = os.path.join(self.dump_dir, name) os.mkdir(self.sim.dump_dir) @@ -76,7 +73,6 @@ def _run_refresh(self) -> None: self.sim.write() # bootstrap with initial root - # pylint: disable=attribute-defined-outside-init self.metadata_dir = tempfile.mkdtemp(dir=self.temp_dir.name) with open(os.path.join(self.metadata_dir, "root.json"), "bw") as f: f.write(self.sim.signed_roots[0]) diff --git a/tests/test_updater_ng.py b/tests/test_updater_ng.py index c87a8fdc..73ca703a 100644 --- a/tests/test_updater_ng.py +++ b/tests/test_updater_ng.py @@ -36,7 +36,6 @@ class TestUpdater(unittest.TestCase): """Test the Updater class from 'tuf/ngclient/updater.py'.""" - # pylint: disable=too-many-instance-attributes server_process_handler: ClassVar[utils.TestServerProcess] @classmethod @@ -282,7 +281,6 @@ def test_length_hash_mismatch(self) -> None: targetinfo.hashes = {"sha256": "abcd"} self.updater.download_target(targetinfo) - # pylint: disable=protected-access def test_updating_root(self) -> None: # Bump root version, resign and refresh self._modify_repository_root(lambda root: None, bump_version=True) diff --git a/tests/test_updater_top_level_update.py b/tests/test_updater_top_level_update.py index b5abb377..89c8ea74 100644 --- a/tests/test_updater_top_level_update.py +++ b/tests/test_updater_top_level_update.py @@ -36,7 +36,6 @@ from tuf.ngclient import Updater -# pylint: disable=too-many-public-methods class TestRefresh(unittest.TestCase): """Test update of top-level metadata following 'Detailed client workflow' in the specification.""" @@ -49,7 +48,6 @@ class TestRefresh(unittest.TestCase): ) - datetime.timedelta(days=5) def setUp(self) -> None: - # pylint: disable=consider-using-with self.temp_dir = tempfile.TemporaryDirectory() self.metadata_dir = os.path.join(self.temp_dir.name, "metadata") self.targets_dir = os.path.join(self.temp_dir.name, "targets") diff --git a/tests/test_updater_validation.py b/tests/test_updater_validation.py index 3ce7d4f7..e5244e94 100644 --- a/tests/test_updater_validation.py +++ b/tests/test_updater_validation.py @@ -20,7 +20,6 @@ class TestUpdater(unittest.TestCase): """Test ngclient Updater input validation.""" def setUp(self) -> None: - # pylint: disable-next=consider-using-with self.temp_dir = tempfile.TemporaryDirectory() self.metadata_dir = os.path.join(self.temp_dir.name, "metadata") self.targets_dir = os.path.join(self.temp_dir.name, "targets") diff --git a/tests/test_utils.py b/tests/test_utils.py index 2fefeedb..b70794da 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -36,7 +36,6 @@ def can_connect(port: int) -> bool: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", port)) return True - # pylint: disable=broad-except except Exception: return False finally: diff --git a/tests/utils.py b/tests/utils.py index 1cae523f..ea7a1524 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -230,7 +230,6 @@ def _start_process(self, extra_cmd_args: List[str], popen_cwd: str) -> None: # Reusing one subprocess in multiple tests, but split up the logs # for each. - # pylint: disable=consider-using-with self.__server_process = subprocess.Popen( command, stdout=subprocess.PIPE, @@ -362,5 +361,4 @@ def clean(self) -> None: def is_process_running(self) -> bool: assert isinstance(self.__server_process, subprocess.Popen) - # pylint: disable=simplifiable-if-expression return True if self.__server_process.poll() is None else False diff --git a/tox.ini b/tox.ini index 88bee67d..6cd567c9 100644 --- a/tox.ini +++ b/tox.ini @@ -49,7 +49,6 @@ lint_dirs = tuf examples tests verify_release commands = ruff check {[testenv:lint]lint_dirs} ruff format --diff {[testenv:lint]lint_dirs} - pylint -j 0 --rcfile=pyproject.toml {[testenv:lint]lint_dirs} mypy {[testenv:lint]lint_dirs} diff --git a/tuf/api/exceptions.py b/tuf/api/exceptions.py index 30c7af12..f74be40a 100644 --- a/tuf/api/exceptions.py +++ b/tuf/api/exceptions.py @@ -10,7 +10,6 @@ #### Repository errors #### -# pylint: disable=unused-import from securesystemslib.exceptions import StorageError # noqa: F401 diff --git a/tuf/api/metadata.py b/tuf/api/metadata.py index d679bba5..e20c3e3a 100644 --- a/tuf/api/metadata.py +++ b/tuf/api/metadata.py @@ -70,7 +70,6 @@ _TARGETS = "targets" _TIMESTAMP = "timestamp" -# pylint: disable=too-many-lines logger = logging.getLogger(__name__) @@ -157,7 +156,6 @@ def signed_bytes(self) -> bytes: """Default canonical json byte representation of ``self.signed``.""" # Use local scope import to avoid circular import errors - # pylint: disable=import-outside-toplevel from tuf.api.serialization.json import CanonicalJSONSerializer return CanonicalJSONSerializer().serialize(self.signed) @@ -267,7 +265,6 @@ def from_bytes( if deserializer is None: # Use local scope import to avoid circular import errors - # pylint: disable=import-outside-toplevel from tuf.api.serialization.json import JSONDeserializer deserializer = JSONDeserializer() @@ -297,7 +294,6 @@ def to_bytes( if serializer is None: # Use local scope import to avoid circular import errors - # pylint: disable=import-outside-toplevel from tuf.api.serialization.json import JSONSerializer serializer = JSONSerializer(compact=True) @@ -855,7 +851,6 @@ class Root(Signed, _DelegatorMixin): type = _ROOT - # pylint: disable=too-many-arguments def __init__( self, version: Optional[int] = None, @@ -2001,7 +1996,6 @@ class Targets(Signed, _DelegatorMixin): type = _TARGETS - # pylint: disable=too-many-arguments def __init__( self, version: Optional[int] = None, diff --git a/tuf/api/serialization/__init__.py b/tuf/api/serialization/__init__.py index 7aef8b98..f24a7022 100644 --- a/tuf/api/serialization/__init__.py +++ b/tuf/api/serialization/__init__.py @@ -20,7 +20,6 @@ from tuf.api.exceptions import RepositoryError if TYPE_CHECKING: - # pylint: disable=cyclic-import from tuf.api.metadata import Metadata, Signed diff --git a/tuf/api/serialization/json.py b/tuf/api/serialization/json.py index 3355511a..b9e964c1 100644 --- a/tuf/api/serialization/json.py +++ b/tuf/api/serialization/json.py @@ -13,7 +13,6 @@ from securesystemslib.formats import encode_canonical -# pylint: disable=cyclic-import # ... to allow de/serializing Metadata and Signed objects here, while also # creating default de/serializers there (see metadata local scope imports). # NOTE: A less desirable alternative would be to add more abstraction layers.