A bunch of filepath-related fixes #2986
Merged
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.
Clean up & organize the paths list in
classes.info
EXPORT_TESTS
Create
info.BACKUP_FILE
, instead of generating the filename in 4-5 different placesReplace all remaining instances of
path.encode('UTF-8')
withos.fsencode(path)
1Also replace
json.loads('"%s"' % path, encoding="utf-8")
in json_data.py withos.fsencode(path)
, since according to the pydoc forjson.loads()
:So, that wasn't actually doing anything useful anyway.
Notes
Windows. Does. Not. Use! UTF-8 encoding for its filesystem paths.
Even if it works 99% of the time (Python protecting us from ourselves),
open(path.encode('UTF-8'))
oros.path.exists(path.encode('UTF-8'))
is WRONG.If necessary, (and it probably isn't),
os.fsencode(path)
is the correct cross-platform way to encode a file path in the native filesystem encoding. That will generate the proper encoding on all systems.As of PEP-529 (which only arrived with Python 3.6), Python will use UTF-8 for path strings even on Windows. This is done as a convenience for code authors, since Python
str
strings already use UTF-8 encoding. (That's how Python protects us from ourselves, and why.encode('UTF-8')
really shouldn't be necessary anyway.)But even PEP-529 recommends
os.fsencode()
, rather than an explicit.encode('UTF-8')
, as the proper way to explicitly encode path strings for the local OS.