Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of filepath-related fixes #2986

Merged
merged 6 commits into from
Nov 19, 2019
Merged

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Sep 9, 2019

  • Clean up & organize the paths list in classes.info

    • Group the members into app paths, user paths, and files
    • Only attempt to create user paths, not app paths
    • Eliminate EXPORT_TESTS
  • Create info.BACKUP_FILE, instead of generating the filename in 4-5 different places

  • Replace all remaining instances of path.encode('UTF-8') with os.fsencode(path)1

  • Also replace json.loads('"%s"' % path, encoding="utf-8") in json_data.py with os.fsencode(path), since according to the pydoc for json.loads():

    The encoding argument is ignored and deprecated.

    So, that wasn't actually doing anything useful anyway.

Notes

  1. 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')) or os.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.

There were like half a dozen places where the backup filename was being generated from `info.BACKUP_PATH + "backup.osp"`.
- Group paths into app dirs, user dirs, user files
- Sort lines somewhat more logically
- Sort for loop list the same way
- Only try to create user dirs, not app dirs
- Eliminate disused `EXPORT_TESTS`
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'))` or `os.path.exists(path.encode('UTF-8'))`
is WRONG.

If necessary, (and it probably isn't), `os.fsencode(path)` is the
correct way to encode a file path in the native filesystem encoding.
Using `json.loads()` to convert path strings to utf-8 is useless anyway, as "The ``encoding`` argument is ignored and deprecated."
@jonoomph
Copy link
Member

Looking good! conflicts...

@ferdnyc
Copy link
Contributor Author

ferdnyc commented Nov 19, 2019

Resolved! Travis likes it, so merging...

@ferdnyc ferdnyc merged commit 02d58d9 into OpenShot:develop Nov 19, 2019
@ferdnyc ferdnyc deleted the info-paths branch November 19, 2019 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants