Skip to content

Issue with encoding of file in windows #37

@aarmn

Description

@aarmn

I have a pyproject.toml file and I wanted to use this tool to extract some info into a pipeline in terminal, but for some absurd reason, the formatting in windows is fixated on "cp1252" with no way to change, and it doesn't seem to check the system for actual format of the file, here is an example of the issue (and it only happened after I added a 🖼️emoji to the file)

expected output:

> uvx --from toml-cli toml get --toml-path pyproject.toml project.version
0.2.0

current output:

> uvx --from toml-cli toml get --toml-path pyproject.toml project.version
╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ C:\Users\a\AppData\Local\uv\cache\archive-v0\cWbLwjkBJn0V9fMPPzLOx\Lib\s │
│ ite-packages\toml_cli\__init__.py:20 in get                                  │
│                                                                              │
│    17 │   default: Optional[str] = typer.Option(None),                       │
│    18 ):                                                                     │
│    19 │   """Get a value from a toml file"""                                 │
│ ❱  20 │   toml_part = tomlkit.parse(toml_path.read_text())                   │
│    21 │                                                                      │
│    22 │   if key is not None:                                                │
│    23 │   │   for key_part in key.split("."):                                │
│                                                                              │
│ ╭───────────────── locals ──────────────────╮                                │
│ │   default = None                          │                                │
│ │       key = 'project.version'             │                                │
│ │ toml_path = WindowsPath('pyproject.toml') │                                │
│ ╰───────────────────────────────────────────╯                                │
│                                                                              │
│ C:\Program Files\Python312\Lib\pathlib.py:1028 in read_text                  │
│                                                                              │
│   1025 │   │   """                                                           │
│   1026 │   │   encoding = io.text_encoding(encoding)                         │
│   1027 │   │   with self.open(mode='r', encoding=encoding, errors=errors) as │
│ ❱ 1028 │   │   │   return f.read()                                           │
│   1029 │                                                                     │
│   1030 │   def write_bytes(self, data):                                      │
│   1031 │   │   """                                                           │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ encoding = 'locale'                                                      │ │
│ │   errors = None                                                          │ │
│ │        f = <_io.TextIOWrapper name='pyproject.toml' mode='r'             │ │
│ │            encoding='cp1252'>                                            │ │
│ │     self = WindowsPath('pyproject.toml')                                 │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ C:\Program Files\Python312\Lib\encodings\cp1252.py:23 in decode              │
│                                                                              │
│    20                                                                        │
│    21 class IncrementalDecoder(codecs.IncrementalDecoder):                   │
│    22 │   def decode(self, input, final=False):                              │
│ ❱  23 │   │   return codecs.charmap_decode(input,self.errors,decoding_table) │
│    24                                                                        │
│    25 class StreamWriter(Codec,codecs.StreamWriter):                         │
│    26 │   pass                                                               │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ final = True                                                             │ │
│ │ input = b'# Schema:                                                      │ │
│ │         https://json.schemastore.org/pyproject.json\n\n[project]\nname = │ │
│ │         "pixelis'+1714                                                   │ │
│ │  self = <encodings.cp1252.IncrementalDecoder object at                   │ │
│ │         0x000001CB62947860>                                              │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────╯
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 122:
character maps to <undefined>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions