Skip to content

Commit 58387d8

Browse files
committed
chore: add support for PTH linter in ruff
1 parent f8bee0f commit 58387d8

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

scaleway-async/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ select = [
4646
"FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
4747
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
4848
"FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
49+
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
4950
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
5051
"YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
5152
]

scaleway-core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ select = [
4646
"ERA", # https://docs.astral.sh/ruff/rules/#eradicate-era
4747
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
4848
"FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
49+
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
4950
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
5051
"YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
5152
]

scaleway-core/scaleway_core/profile/profile.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
from dataclasses import dataclass
7+
from pathlib import Path
78
from typing import Optional, Type, TypeVar
89

910
import yaml
@@ -110,23 +111,23 @@ def from_env(cls: Type[ProfileSelf], force_none: bool = False) -> ProfileSelf:
110111
return profile
111112

112113
@classmethod
113-
def get_default_config_directory(cls) -> str:
114+
def get_default_config_directory(cls) -> Path:
114115
xdg_config_path = os.environ.get("XDG_CONFIG_HOME")
115116
if xdg_config_path is not None and xdg_config_path != "":
116-
return os.path.join(xdg_config_path, "scw")
117+
return Path(xdg_config_path) / "scw"
117118

118-
return os.path.join(os.path.expanduser("~"), ".config", "scw")
119+
return Path.expanduser("~") / ".config" / "scw"
119120

120121
@classmethod
121-
def get_default_config_file_path(cls, filepath: Optional[str] = None) -> str:
122+
def get_default_config_file_path(cls, filepath: Optional[str] = None) -> Path:
122123
if filepath is not None:
123-
return filepath
124+
return Path(filepath)
124125

125126
filepath = os.environ.get(ENV_KEY_SCW_CONFIG_PATH)
126127
if filepath is not None and filepath != "":
127-
return filepath
128+
return Path(filepath)
128129

129-
return os.path.join(Profile.get_default_config_directory(), "config.yaml")
130+
return Profile.get_default_config_directory() / "config.yaml"
130131

131132
@classmethod
132133
def from_config_file(
@@ -137,7 +138,7 @@ def from_config_file(
137138
) -> ProfileSelf:
138139
filepath = cls.get_default_config_file_path(filepath)
139140

140-
with open(filepath, "r") as f:
141+
with Path(filepath).open("r") as f:
141142
config = yaml.safe_load(f)
142143

143144
if not isinstance(config, dict):

scaleway-core/tests/test_profile_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tempfile
55
import unittest
66
import uuid
7+
from pathlib import Path
78
from unittest import mock
89

910
import utils
@@ -56,7 +57,7 @@ def setUp(self) -> None:
5657
fp.close()
5758

5859
def tearDown(self) -> None:
59-
os.unlink(self.profile_file_name)
60+
Path.unlink(self.profile_file_name)
6061

6162
def test_load_profile_from_config_file(self) -> None:
6263
profile = Profile.from_config_file(self.profile_file_name)

scaleway/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ select = [
4747
"FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
4848
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
4949
"FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
50+
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
5051
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
5152
"YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
5253
]

0 commit comments

Comments
 (0)