question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace manual path construction with "os.path.join"

See original GitHub issue

Description 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:

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
aribaschcommented, Mar 23, 2022

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?

1reaction
jkucommented, Mar 25, 2022

Is there a reason os.path is used throughout the codebase, instead of pathlib?

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:

self.repo_dir / "metadata/root.json"

… I admit I would have expected that to create something surprising on windows but maybe it just works?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found