Nekmo/pip-rating

View on GitHub

Showing 25 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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              @unittest.skipIf(sys.version_info >= (3, 11), "Test for Python 3.10 or lower")
              def test_python_310_or_lower(self):
                  expected_dt = datetime.datetime(
                      2023, 9, 14, 18, 56, 29, 702900, tzinfo=datetime.timezone.utc
                  )
          Severity: Major
          Found in tests/test_utils.py and 1 other location - About 2 hrs to fix
          tests/test_utils.py on lines 8..15

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 50.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              @unittest.skipIf(sys.version_info < (3, 11), "Test for Python 3.11 or higher")
              def test_python_311_or_higher(self):
                  expected_dt = datetime.datetime(
                      2023, 9, 14, 18, 56, 29, 702900, tzinfo=datetime.timezone.utc
                  )
          Severity: Major
          Found in tests/test_utils.py and 1 other location - About 2 hrs to fix
          tests/test_utils.py on lines 17..24

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 50.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          def test_repr(self):
                              """Test the __repr__ method in the PackageList class."""
                              package_list = PackageList(["package", "other"])
                              self.assertEqual("<ReqFile (2)>", repr(package_list))
                      Severity: Minor
                      Found in tests/req_files/test_package_list.py and 1 other location - About 45 mins to fix
                      tests/req_files/test_package_list.py on lines 31..34

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 35.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          def test_str(self):
                              """Test the __str__ method in the PackageList class."""
                              package_list = PackageList(["package", "other"])
                              self.assertEqual("['package', 'other']", str(package_list))
                      Severity: Minor
                      Found in tests/req_files/test_package_list.py and 1 other location - About 45 mins to fix
                      tests/req_files/test_package_list.py on lines 36..39

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 35.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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
                        Severity
                        Category
                        Status
                        Source
                        Language