Nekmo/pip-rating

View on GitHub

Showing 21 of 25 total issues

File test_rating.py has 572 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import json
import time
import unittest
from unittest.mock import patch, MagicMock, Mock, PropertyMock, mock_open
Severity: Major
Found in tests/test_rating.py - About 1 day to fix

    File results.py has 381 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import datetime
    import json
    import os
    from typing import Optional, TYPE_CHECKING, Union, TypedDict, List, Any
    
    
    Severity: Minor
    Found in pip_rating/results.py - About 5 hrs to fix

      File test_results.py has 328 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """
      Tests for the results module.
      
      This tests can be improved. These tests do not verify the returned outputs.
      """
      Severity: Minor
      Found in tests/test_results.py - About 3 hrs to fix

        Function poetry_version has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

        def poetry_version(version: Union[str, dict, None]) -> str:
            """Convert Poetry version to PEP440 version."""
            if version is None:
                return ""
            if isinstance(version, dict):
        Severity: Minor
        Found in pip_rating/req_files/pyproject.py - About 3 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        File rating.py has 281 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import datetime
        import json
        import os
        import logging
        from functools import cached_property
        Severity: Minor
        Found in pip_rating/rating.py - About 2 hrs to fix

          Function show_packages_results has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def show_packages_results(self, dependencies: "Dependencies"):
                  global_rating_score = self.get_global_rating_score(dependencies)
                  for package in dependencies.packages.values():
                      if package.name not in dependencies.req_file:
                          continue
          Severity: Minor
          Found in pip_rating/results.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Consider simplifying this complex logical expression.
          Open

                  if (
                      e.response is not None
                      and e.response.status_code == 403
                      and e.response.reason == "rate limit exceeded"
                      and not github_token
          Severity: Critical
          Found in pip_rating/sources/sourcecode_page.py - About 1 hr to fix

            Function action has 9 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def action(
            Severity: Major
            Found in _action.py - About 1 hr to fix

              Function find_in_directory has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def find_in_directory(cls, directory: Union[str, Path]) -> Optional["ReqFileBase"]:
                      """Find requirement file in the given directory."""
                      if isinstance(directory, str):
                          directory = Path(directory)
                      for requirements_file in REQUIREMENTS_FILES:
              Severity: Minor
              Found in pip_rating/req_files/requirements.py - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function analyze_file has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def analyze_file(
              Severity: Major
              Found in pip_rating/management.py - About 1 hr to fix

                Function search_in_readme has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                def search_in_readme(content: str, package_name: str) -> Optional[bool]:
                    """Search for patterns in readme. If found the pattern, check if the package name is package_name.
                    If the package name found is package_name, return True, else continues searching. If after all
                    patterns are searched and no package name is found, return False. If any pattern matches,
                    return None.
                Severity: Minor
                Found in pip_rating/sources/sourcecode_page.py - About 55 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(
                Severity: Major
                Found in pip_rating/dependencies.py - About 50 mins to fix

                  Function analyze_package has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  def analyze_package(
                  Severity: Major
                  Found in pip_rating/management.py - About 50 mins to fix

                    Function test_save_to_cache has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def test_save_to_cache(
                    Severity: Major
                    Found in tests/test_rating.py - About 50 mins to fix

                      Function get_github_readme has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def get_github_readme(owner: str, repo: str) -> str:
                          """Get the readme content from GitHub."""
                          headers = {}
                          if github_token:
                              headers["Authorization"] = f"Bearer {github_token}"
                      Severity: Minor
                      Found in pip_rating/sources/sourcecode_page.py - About 45 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function test_save_to_cache has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def test_save_to_cache(
                      Severity: Minor
                      Found in tests/sources/test_base.py - About 35 mins to fix

                        Function get_node_from_parent has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def get_node_from_parent(
                                self, from_package: Optional["Package"] = None
                            ) -> Optional["Node"]:
                                """Given this package and a parent package, return the node in the package that
                                is a descendant of the parent package
                        Severity: Minor
                        Found in pip_rating/packages.py - About 35 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Avoid too many return statements within this function.
                        Open

                                return version
                        Severity: Major
                        Found in pip_rating/req_files/pyproject.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return f"=={version}"
                          Severity: Major
                          Found in pip_rating/req_files/pyproject.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return f">={version},<{version.major}.{version.minor}.{version.micro + 1}"
                            Severity: Major
                            Found in pip_rating/req_files/pyproject.py - About 30 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language