Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scaleway-async/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
1 change: 1 addition & 0 deletions scaleway-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
17 changes: 9 additions & 8 deletions scaleway-core/scaleway_core/profile/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
from dataclasses import dataclass
from pathlib import Path
from typing import Optional, Type, TypeVar

import yaml
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion scaleway-core/tests/test_profile_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
import unittest
import uuid
from pathlib import Path
from unittest import mock

import utils
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions scaleway/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
Loading