Replace manual path construction with "os.path.join"
See original GitHub issueDescription of issue or feature request:
I found a couple of places in the tests where we have used f
strings and manually joined paths instead of using os.path.join()
.
This can lead to a problem where on Linux and Mac OS this behavior will work, but on Windows won’t.
Some examples:
- https://github.com/theupdateframework/python-tuf/blob/e7037cf8c42022ea20f3b7891a50aa3ed563521b/tests/test_api.py#L236
- https://github.com/theupdateframework/python-tuf/blob/e7037cf8c42022ea20f3b7891a50aa3ed563521b/tests/test_api.py#L162
When discussing with @jku why don’t we get CI failures from this behavior he found out that:
File I/O in the Windows API converts forward slashes (“/”) to backslashes (''), before passing the request to the native API
Even though that’s the case, it’s better if we replace those instances of manual path construction with the preferred os.path.join
.
We should not forget we are developing python-tuf
for Windows users as well. 😃
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
os.path — Common pathname manipulations — Python 3.11 ...
On Unix, an initial ~ is replaced by the environment variable HOME if it is set; otherwise the current user's home directory is...
Read more >Python os.path.join: A Beginner's Guide - Career Karma
The os.path.join method merges and combines multiple components of a file path into one path. On Career Karma, learn how to use the...
Read more >Python | os.path.join() method - GeeksforGeeks
This method concatenates various path components with exactly one directory separator ('/') following each non-empty part except the last path ...
Read more >Build the full path filename in Python - Stack Overflow
This works fine: os.path.join(dir_name, base_filename + '.' + filename_suffix). Keep in mind that os.path.join() exists only because ...
Read more >10.1. os.path — Common pathname manipulations - IronPython
Join one or more path components intelligently. If any component is an absolute path, all previous components (on Windows, including the previous drive...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! New to open source and looking to contribute. I’ve been able to follow the development installation instructions and run tests for python-tuf, and am looking to tackle some good first issues and familiarize myself with the codebase. I was wondering if I would be able to claim this issue?
I believe historical reasons only: pathlib is a fairly new API. I’m ok with using Pathlib, it’s definitely convenient.
I’d argue that it’s only clearer to people who already know Pathlib. E.g. from your examples:
… I admit I would have expected that to create something surprising on windows but maybe it just works?