seddonym / import-linter

Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://import-linter.readthedocs.io/
BSD 2-Clause "Simplified" License
676 stars 46 forks source link

'charmap' codec can't decode byte 0x8d in position 622: character maps to <undefined> #242

Open fraser-langton opened 3 hours ago

fraser-langton commented 3 hours ago

Can't offer too much more info unfortunately, I literally opened my laptop up in the morning and the same command won't run, quite baffling

> lint-imports --verbose
=============
Import Linter
=============

Verbose mode.
'charmap' codec can't decode byte 0x8d in position 622: character maps to <undefined>
fraser-langton commented 3 hours ago

found the culprit using this script

from pathlib import Path

def check_files_for_charmap_error(glob_pattern):
    # Use glob to filter files based on the provided pattern in the current directory
    for file_path in Path().glob(glob_pattern):  # Use the glob pattern to find matching files
        if file_path.is_file():  # Ensure it's a file
            if ".venv" in file_path.parts:  # Exclude files in .venv directory
                continue

            try:
                with file_path.open(encoding="cp1252") as f:  # Windows default encoding
                    f.read()
            except UnicodeDecodeError as e:
                print(f"Error decoding {file_path}: {e}")
            except Exception as e:
                print(f"An error occurred with {file_path}: {e}")

if __name__ == "__main__":
    glob_pattern = "**/*.py"
    check_files_for_charmap_error(glob_pattern)
fraser-langton commented 3 hours ago

And this single char was the culprit: Í