Use Python's standard filesystem encoding for command-line arguments #4507
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.
This is very much an experiment, but it's an attempt to address persistent issues with invoking command-line tools with non-ASCII arguments. For example, the
replaygain
plugin wants to invokeffmpeg
on filenames that might contain special characters. Doing this in a cross-platform way has always been extremely fraught—it's hard to get it to work right simultaneously on Unix (where filenames are plain bytes that need not obey any specific encoding) and on Windows (where filenames are weird, but they are closer to being Unicode strings).The experiment here is to centralize on the Python standard library's implicit recommendations for this:
fsencode
andfsdecode
. These use surrogate escaping (at least in most configurations??), so they probably shouldn't crash. Thesubprocess
module also apparently assumes this is the right encoding for CLI argument stuff, at least on Windows:https://github.com/python/cpython/blob/54bbb5e3363ef3634f1fd7521ba3f3c42c81a331/Lib/subprocess.py#L561
…so hopefully using this encoding everywhere should make things better on Windows and no worse on Unix.
The hope is to address some CI failures that come from the
replaygain
invokingffmpeg
on Windows.