-
Notifications
You must be signed in to change notification settings - Fork 81
Migrate from os.path to pathlib for file path handling #654
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import os | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
|
|
||
| from linode_api4.objects import JSONObject | ||
|
|
||
|
|
@@ -47,9 +47,9 @@ def load_and_validate_keys(authorized_keys): | |
| ret.append(k) | ||
| else: | ||
| # it doesn't appear to be a key.. is it a path to the key? | ||
| k = os.path.expanduser(k) | ||
| if os.path.isfile(k): | ||
| with open(k) as f: | ||
| k_path = Path(k).expanduser() | ||
| if k_path.is_file(): | ||
| with open(k_path) as f: | ||
| ret.append(f.read().rstrip()) | ||
|
Comment on lines
+50
to
53
|
||
| else: | ||
| raise ValueError( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import base64 | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Any, Dict, List, Optional, Union | ||
|
|
||
| from linode_api4.common import load_and_validate_keys | ||
|
|
@@ -457,8 +457,9 @@ def stackscript_create( | |
| script_body = script | ||
| if not script.startswith("#!"): | ||
| # it doesn't look like a stackscript body, let's see if it's a file | ||
| if os.path.isfile(script): | ||
| with open(script) as f: | ||
| script_path = Path(script) | ||
| if script_path.is_file(): | ||
| with open(script_path) as f: | ||
| script_body = f.read() | ||
|
Comment on lines
+460
to
463
|
||
| else: | ||
| raise ValueError( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import os | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
|
|
||
| from linode_api4 import UnexpectedResponseError | ||
| from linode_api4.common import SSH_KEY_TYPES | ||
|
|
@@ -322,9 +322,9 @@ def ssh_key_upload(self, key, label): | |
| """ | ||
| if not key.startswith(SSH_KEY_TYPES): | ||
| # this might be a file path - look for it | ||
| path = os.path.expanduser(key) | ||
| if os.path.isfile(path): | ||
| with open(path) as f: | ||
| key_path = Path(key).expanduser() | ||
| if key_path.is_file(): | ||
| with open(key_path) as f: | ||
| key = f.read().strip() | ||
|
Comment on lines
+325
to
328
|
||
| if not key.startswith(SSH_KEY_TYPES): | ||
| raise ValueError("Invalid SSH Public Key") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In docs/conf.py the comment says to use
Path(...).resolve()but the code usesPath('..').absolute(). Either update the code to useresolve()(and keep the comment accurate) or adjust the comment to match the chosen API to avoid misleading future edits.