fix: add proper encoding parsing for when working with Windows files #183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Windows 10, when trying to use tbump to push tags in my environment, I was getting the following error:
Error code snippet
(my-test-project) PS C:\Users\Dan\PycharmProjects\my-test-project> tbump 0.0.1.dev10
:: Bumping from 0.0.1.dev9 to 0.0.1.dev10
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Scripts\tbump.exe_main.py", line 10, in
sys.exit(main())
~~~~^^
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\cli.py", line 296, in main
run(args)
~~~^^^^^^
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\cli.py", line 184, in run
run_bump(arguments, working_path, arguments.tag_message)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\cli.py", line 208, in run_bump
bump(bump_options, _construct_operations(arguments))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\cli.py", line 250, in bump
executor = Executor(new_version, file_bumper, config_file)
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\executor.py", line 64, in init
file_bumper.get_patches(new_version),
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\file_bumper.py", line 187, in get_patches
patches_for_request = self.compute_patches_for_change_request(
change_request
)
File "C:\Users\Dan\PycharmProjects\my-test-project.venv\Lib\site-packages\tbump\file_bumper.py", line 205, in compute_patches_for_change_request
old_lines = file_path.read_text().splitlines(keepends=False)
~~~~~~~~~~~~~~~~~~~^^
File "C:\Users\Dan\AppData\Roaming\uv\python\cpython-3.13.3-windows-x86_64-none\Lib\pathlib_local.py", line 546, in read_text
return PathBase.read_text(self, encoding, errors, newline)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dan\AppData\Roaming\uv\python\cpython-3.13.3-windows-x86_64-none\Lib\pathlib_abc.py", line 633, in read_text
return f.read()
~~~~~~^^
File "C:\Users\Dan\AppData\Roaming\uv\python\cpython-3.13.3-windows-x86_64-none\Lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 4611: character maps to
The same project works fine in Linux. Since it was pointing to the pathlib's read_text, which allows for explicit encoding setup, I tried to set the encoding explicitly, which allowed tbump to work without issue. Haven't tested this thoroughly, but this doesn't seem like too much of a change. Would be glad to fix anything else related to this if required.