From 58387d8a071d16ce3e3cf66a9468a19d5a7e7c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Wed, 30 Jul 2025 09:49:21 +0200 Subject: [PATCH] chore: add support for PTH linter in ruff --- scaleway-async/pyproject.toml | 1 + scaleway-core/pyproject.toml | 1 + scaleway-core/scaleway_core/profile/profile.py | 17 +++++++++-------- scaleway-core/tests/test_profile_file.py | 3 ++- scaleway/pyproject.toml | 1 + 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scaleway-async/pyproject.toml b/scaleway-async/pyproject.toml index 24fc88aa4..0081effe2 100644 --- a/scaleway-async/pyproject.toml +++ b/scaleway-async/pyproject.toml @@ -46,6 +46,7 @@ select = [ "FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt "FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb + "PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth "T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10 "YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt ] diff --git a/scaleway-core/pyproject.toml b/scaleway-core/pyproject.toml index 0c9646f8e..e7047e1fa 100644 --- a/scaleway-core/pyproject.toml +++ b/scaleway-core/pyproject.toml @@ -46,6 +46,7 @@ select = [ "ERA", # https://docs.astral.sh/ruff/rules/#eradicate-era "FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb + "PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth "T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10 "YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt ] diff --git a/scaleway-core/scaleway_core/profile/profile.py b/scaleway-core/scaleway_core/profile/profile.py index f3287e159..882523c9e 100644 --- a/scaleway-core/scaleway_core/profile/profile.py +++ b/scaleway-core/scaleway_core/profile/profile.py @@ -4,6 +4,7 @@ import logging import os from dataclasses import dataclass +from pathlib import Path from typing import Optional, Type, TypeVar import yaml @@ -110,23 +111,23 @@ def from_env(cls: Type[ProfileSelf], force_none: bool = False) -> ProfileSelf: return profile @classmethod - def get_default_config_directory(cls) -> str: + def get_default_config_directory(cls) -> Path: xdg_config_path = os.environ.get("XDG_CONFIG_HOME") if xdg_config_path is not None and xdg_config_path != "": - return os.path.join(xdg_config_path, "scw") + return Path(xdg_config_path) / "scw" - return os.path.join(os.path.expanduser("~"), ".config", "scw") + return Path.expanduser("~") / ".config" / "scw" @classmethod - def get_default_config_file_path(cls, filepath: Optional[str] = None) -> str: + def get_default_config_file_path(cls, filepath: Optional[str] = None) -> Path: if filepath is not None: - return filepath + return Path(filepath) filepath = os.environ.get(ENV_KEY_SCW_CONFIG_PATH) if filepath is not None and filepath != "": - return filepath + return Path(filepath) - return os.path.join(Profile.get_default_config_directory(), "config.yaml") + return Profile.get_default_config_directory() / "config.yaml" @classmethod def from_config_file( @@ -137,7 +138,7 @@ def from_config_file( ) -> ProfileSelf: filepath = cls.get_default_config_file_path(filepath) - with open(filepath, "r") as f: + with Path(filepath).open("r") as f: config = yaml.safe_load(f) if not isinstance(config, dict): diff --git a/scaleway-core/tests/test_profile_file.py b/scaleway-core/tests/test_profile_file.py index b1b650f79..1ffce3a3c 100644 --- a/scaleway-core/tests/test_profile_file.py +++ b/scaleway-core/tests/test_profile_file.py @@ -4,6 +4,7 @@ import tempfile import unittest import uuid +from pathlib import Path from unittest import mock import utils @@ -56,7 +57,7 @@ def setUp(self) -> None: fp.close() def tearDown(self) -> None: - os.unlink(self.profile_file_name) + Path.unlink(self.profile_file_name) def test_load_profile_from_config_file(self) -> None: profile = Profile.from_config_file(self.profile_file_name) diff --git a/scaleway/pyproject.toml b/scaleway/pyproject.toml index 0701c29c5..f70b2fd1c 100644 --- a/scaleway/pyproject.toml +++ b/scaleway/pyproject.toml @@ -47,6 +47,7 @@ select = [ "FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt "FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb + "PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth "T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10 "YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt ]