Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setup.py decoding error #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

runes121
Copy link

@runes121 runes121 commented Nov 8, 2024

User description

Fix the error when trying to pip install package:

 return codecs.charmap_decode(input,self.errors,decoding_table)[0]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 1274: character maps to <undefined>

By using utf-8 encoding


PR Type

Bug fix


Description

  • Fixed a UnicodeDecodeError in setup.py by specifying utf-8 encoding when opening files.
  • Ensured that all file reading operations in setup.py use utf-8 encoding to prevent similar errors.

Changes walkthrough 📝

Relevant files
Bug fix
setup.py
Fix file decoding errors by specifying utf-8 encoding       

setup.py

  • Added utf-8 encoding to file open operations.
  • Fixed potential UnicodeDecodeError in README.md and __init__.py.
  • Ensured consistent encoding for reading requirements files.
  • +3/-3     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Fix the encoding error when loading files in setup.py
    Copy link

    qodo-merge-pro bot commented Nov 8, 2024

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    The file open operations should include error handling in case the files don't exist or have permission issues

    Copy link

    qodo-merge-pro bot commented Nov 8, 2024

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use context managers for file operations to ensure proper resource cleanup

    Use a context manager (with statement) for the file operation in get_version() to
    ensure proper file closure, even if an error occurs.

    setup.py [23]

    -verstrline = open(get_absolute_path(NAME, "__init__.py"), "rt", encoding='utf-8').read()
    +with open(get_absolute_path(NAME, "__init__.py"), "rt", encoding='utf-8') as f:
    +    verstrline = f.read()
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Using a context manager is a critical best practice for file operations as it ensures proper resource cleanup, even in case of exceptions. This prevents potential resource leaks and makes the code more robust.

    8
    Performance
    Optimize memory usage by reading file content only when needed and avoiding unnecessary variables

    Move the file reading operation inside the get_version() function to avoid keeping
    the file content in memory longer than necessary.

    setup.py [23-25]

    -verstrline = open(get_absolute_path(NAME, "__init__.py"), "rt", encoding='utf-8').read()
    -VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
    -mo = re.search(VSRE, verstrline, re.M)
    +with open(get_absolute_path(NAME, "__init__.py"), "rt", encoding='utf-8') as f:
    +    mo = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M)
    • Apply this suggestion
    Suggestion importance[1-10]: 4

    Why: While the suggestion combines file handling improvement with memory optimization, the memory impact is minimal given the small size of init.py files. The removal of the intermediate variable also slightly reduces code readability.

    4

    💡 Need additional feedback ? start a PR chat

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant