From 978644e147dc7d8814a30188dcfdc7f33791828e Mon Sep 17 00:00:00 2001 From: Jakob Gamper <97gamjak@gmail.com> Date: Wed, 12 Jun 2024 00:29:32 +0200 Subject: [PATCH] pylint: improved score - now threshold again at old value of 9.75 --- .github/workflows/pylint.yml | 9 ++---- PQAnalysis/__init__.py | 1 - PQAnalysis/atomic_system/_decorators.py | 1 - PQAnalysis/core/api.py | 4 +-- PQAnalysis/io/gen_file/gen_file_reader.py | 1 + .../io/input_file_reader/input_file_parser.py | 3 ++ .../io/input_file_reader/pq/output_files.py | 2 -- PQAnalysis/io/nep/nep_writer.py | 18 +++++++---- .../io/topology_file/topology_file_reader.py | 30 +++++++++++++++++++ PQAnalysis/io/traj_file/frame_reader.py | 5 +++- PQAnalysis/io/traj_file/setup.py | 10 ------- 11 files changed, 55 insertions(+), 29 deletions(-) delete mode 100644 PQAnalysis/io/traj_file/setup.py diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index e4cc9ef1..cc1adcd1 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -47,9 +47,6 @@ jobs: python .github/scripts/parse_pylint.py pylint_output.txt | tee comment.txt fi - - #check if the first line of comment.txt rates higher than 9.75 with following format - #Your code has been rated at 9.86/10 (previous run: 7.63/10, +2.22) - name: Check if pylint score is higher than 9.75 id: check_pylint_score run: | @@ -57,10 +54,10 @@ jobs: head -n3 comment.txt | tail -n 1 | awk '{print $7}' head -n3 comment.txt | tail -n 1 | awk '{print $7}' | cut -d '/' -f 1 score=$(head -n3 comment.txt | tail -n 1 | awk '{print $7}' | cut -d '/' -f 1) - if (( $(echo "$score > 9.5" | bc -l) )); then - echo "Pylint score is higher than 9.5 and is $score" + if (( $(echo "$score > 9.75" | bc -l) )); then + echo "Pylint score is higher than 9.75 and is $score" else - echo "Pylint score is lower than 9.5 and is $score" + echo "Pylint score is lower than 9.75 and is $score" exit 1 fi shell: bash diff --git a/PQAnalysis/__init__.py b/PQAnalysis/__init__.py index de9facd6..bafc6c29 100644 --- a/PQAnalysis/__init__.py +++ b/PQAnalysis/__init__.py @@ -21,7 +21,6 @@ # BEARTYPE SETUP # ################## -# TODO: change the default level to "RELEASE" after all changes are implemented __beartype_default_level__ = "RELEASE" __beartype_level__ = os.getenv( "PQANALYSIS_BEARTYPE_LEVEL", __beartype_default_level__ diff --git a/PQAnalysis/atomic_system/_decorators.py b/PQAnalysis/atomic_system/_decorators.py index 31fbe9c7..8fba3a38 100644 --- a/PQAnalysis/atomic_system/_decorators.py +++ b/PQAnalysis/atomic_system/_decorators.py @@ -17,7 +17,6 @@ of atoms is equal to the number of positions. """ -import sys import numpy as np from beartype.typing import Any diff --git a/PQAnalysis/core/api.py b/PQAnalysis/core/api.py index 5b214578..0b0d4f61 100644 --- a/PQAnalysis/core/api.py +++ b/PQAnalysis/core/api.py @@ -17,7 +17,7 @@ def distance( pos1: Np1DNumberArray | Np2DNumberArray, pos2: Np1DNumberArray | Np2DNumberArray, cell: _cell.Cell = _cell.Cell(), - **kwargs + **kwargs # pylint: disable=unused-argument ) -> PositiveReal | Np1DNumberArray | Np2DNumberArray: """ Returns the distances between all combinations of two position arrays. @@ -66,7 +66,7 @@ def distance( cell : Cell, optional The unit cell of the system. Default is Cell(). **kwargs - Arbitrary keyword arguments. + Additional keyword arguments. Returns ------- diff --git a/PQAnalysis/io/gen_file/gen_file_reader.py b/PQAnalysis/io/gen_file/gen_file_reader.py index 1daca314..f41df07b 100644 --- a/PQAnalysis/io/gen_file/gen_file_reader.py +++ b/PQAnalysis/io/gen_file/gen_file_reader.py @@ -93,6 +93,7 @@ def _read_header(self, """ n_atoms, periodicity = header[0].split() n_atoms = int(n_atoms) + is_periodic = False # Default value if periodicity.lower() == "c": is_periodic = False diff --git a/PQAnalysis/io/input_file_reader/input_file_parser.py b/PQAnalysis/io/input_file_reader/input_file_parser.py index ccceaf7b..64f53125 100644 --- a/PQAnalysis/io/input_file_reader/input_file_parser.py +++ b/PQAnalysis/io/input_file_reader/input_file_parser.py @@ -79,6 +79,9 @@ def parse(self) -> "InputDictionary": InputDictionary: InputDictionary The parsed input file dictionary. """ + + grammar_file = None # to avoid linter warning + if self.input_format == InputFileFormat.PQANALYSIS: grammar_file = "inputGrammar.lark" elif self.input_format in [InputFileFormat.PQ, InputFileFormat.QMCFC]: diff --git a/PQAnalysis/io/input_file_reader/pq/output_files.py b/PQAnalysis/io/input_file_reader/pq/output_files.py index a1553c28..fd013699 100644 --- a/PQAnalysis/io/input_file_reader/pq/output_files.py +++ b/PQAnalysis/io/input_file_reader/pq/output_files.py @@ -2,8 +2,6 @@ A module containing a Mixin class for output files of a PQ input file. """ -from PQAnalysis.exceptions import PQKeyError - class _OutputFileMixin: diff --git a/PQAnalysis/io/nep/nep_writer.py b/PQAnalysis/io/nep/nep_writer.py index 9f4f2fe4..4289054c 100644 --- a/PQAnalysis/io/nep/nep_writer.py +++ b/PQAnalysis/io/nep/nep_writer.py @@ -316,6 +316,8 @@ def write_from_files( self.is_validation = False + file_to_write = None # to avoid linting warning + if j in train_indices: self.n_train_frames += 1 file_to_write = self.train_file @@ -339,7 +341,11 @@ def write_from_files( ) self.write_from_atomic_system( - system, file_to_write, use_forces, use_stress, use_virial + system, + file_to_write, + use_forces, + use_stress, + use_virial, ) if self.is_validation: @@ -437,12 +443,16 @@ def _setup_frame_splitting_for_training( exception=NEPError ) + n_train = 0.0 + n_validation = 0.0 + n_test = 0.0 + if total_ratios is not None: ratios = total_ratios.split(":") if len(ratios) == 2: n_train = float(ratios[0]) n_test = float(ratios[1]) - n_validation = 0 + n_validation = 0.0 elif len(ratios) == 3: n_train = float(ratios[0]) n_test = float(ratios[1]) @@ -456,10 +466,6 @@ def _setup_frame_splitting_for_training( ), exception=NEPError ) - else: - n_train = 0.0 - n_validation = 0.0 - n_test = 0.0 sum_frames = n_train + n_test + n_validation diff --git a/PQAnalysis/io/topology_file/topology_file_reader.py b/PQAnalysis/io/topology_file/topology_file_reader.py index 79ba6782..8c9a58c5 100644 --- a/PQAnalysis/io/topology_file/topology_file_reader.py +++ b/PQAnalysis/io/topology_file/topology_file_reader.py @@ -209,6 +209,11 @@ def _parse_bonds(self, block: List[str]) -> List[Bond]: line, comment = self._get_data_line_comment(line) + index = None # to avoid linter warning + target_index = None # to avoid linter warning + bond_type = None # to avoid linter warning + is_linker = None # to avoid linter warning + if len(line.split()) == 4: index, target_index, bond_type, _ = line.split() is_linker = True @@ -263,6 +268,12 @@ def _parse_angles(self, block: List[str]) -> List[Angle]: line, comment = self._get_data_line_comment(line) + index1 = None # to avoid linter warning + index2 = None # to avoid linter warning + index3 = None # to avoid linter warning + angle_type = None # to avoid linter warning + is_linker = None # to avoid linter warning + if len(line.split()) == 5: index1, index2, index3, angle_type, _ = line.split() is_linker = True @@ -318,6 +329,13 @@ def _parse_dihedrals(self, block: List[str]) -> List[Dihedral]: line, comment = self._get_data_line_comment(line) + index1 = None # to avoid linter warning + index2 = None # to avoid linter warning + index3 = None # to avoid linter warning + index4 = None # to avoid linter warning + dihedral_type = None # to avoid linter warning + is_linker = None # to avoid linter warning + if len(line.split()) == 6: index1, index2, index3, index4, dihedral_type, _ = line.split() is_linker = True @@ -374,6 +392,13 @@ def _parse_impropers(self, block: List[str]) -> List[Dihedral]: line, comment = self._get_data_line_comment(line) + index1 = None # to avoid linter warning + index2 = None # to avoid linter warning + index3 = None # to avoid linter warning + index4 = None # to avoid linter warning + dihedral_type = None # to avoid linter warning + is_linker = None # to avoid linter warning + if len(line.split()) == 6: index1, index2, index3, index4, dihedral_type, _ = line.split() is_linker = True @@ -431,6 +456,11 @@ def _parse_shake(self, block: List[str]) -> List[Bond]: line, comment = self._get_data_line_comment(line) + index = None # to avoid linter warning + target_index = None # to avoid linter warning + distance = None # to avoid linter warning + is_linker = None # to avoid linter warning + if len(line.split()) == 4: index, target_index, distance, _ = line.split() is_linker = True diff --git a/PQAnalysis/io/traj_file/frame_reader.py b/PQAnalysis/io/traj_file/frame_reader.py index 51c25f02..127259a7 100644 --- a/PQAnalysis/io/traj_file/frame_reader.py +++ b/PQAnalysis/io/traj_file/frame_reader.py @@ -17,7 +17,7 @@ from PQAnalysis import __package_name__ from .exceptions import FrameReaderError -from .process_lines import process_lines_with_atoms +from .process_lines import process_lines_with_atoms # pylint: disable=import-error @@ -316,6 +316,9 @@ def _read_header_line(self, header_line: str) -> Tuple[int, Cell]: If the header line is not valid. Either it contains too many or too few values. """ + n_atoms = 0 # default value + cell = None # default value + header_line = header_line.split() if len(header_line) == 4: diff --git a/PQAnalysis/io/traj_file/setup.py b/PQAnalysis/io/traj_file/setup.py deleted file mode 100644 index 9050f847..00000000 --- a/PQAnalysis/io/traj_file/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from setuptools import setup, Extension - -module = Extension('mytest', sources=['mytest.c']) - -setup( - name='MyTest', - version='1.0', - description='Python interface for the FrameReader C library', - ext_modules=[module], -)