Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoOpenCosmos committed Jan 24, 2025
1 parent d13ce9b commit 319536e
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 87 deletions.
8 changes: 2 additions & 6 deletions datacosmos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def _load_config(self, config_file: str) -> Config:
if os.path.exists(config_file):
self.logger.info(f"Loading configuration from {config_file}")
return Config.from_yaml(config_file)
self.logger.info(
"Loading configuration from environment variables"
)
self.logger.info("Loading configuration from environment variables")
return Config.from_env()
except Exception as e:
self.logger.error(f"Failed to load configuration: {e}")
Expand Down Expand Up @@ -77,9 +75,7 @@ def _authenticate_and_initialize_client(self) -> requests.Session:

# Initialize the HTTP session with the Authorization header
http_client = requests.Session()
http_client.headers.update(
{"Authorization": f"Bearer {self.token}"}
)
http_client.headers.update({"Authorization": f"Bearer {self.token}"})
return http_client
except RequestException as e:
self.logger.error(f"Request failed during authentication: {e}")
Expand Down
86 changes: 27 additions & 59 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,46 +1,15 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "datacosmos-sdk"
version = "0.0.1"
authors = [
{ name="Open Cosmos", email="[email protected]" },
]
description = "A library for interacting with DataCosmos from Python code"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
# pytest configuration
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
]
dependencies = []

[project.optional-dependencies]
test = [
"black==22.12.0",
"flake8==6.0.0",
"pytest==7.2.0",
"bandit[toml]==1.7.4",
"isort==5.11.4",
"pydocstyle==6.1.1",
"flake8-cognitive-complexity==0.1.0",
"ruff==0.0.286"
]

[tool.setuptools.packages]
find = {}

[tool.bandit]
skips = ["B101"] # Example: ignore assert statement usage if needed
targets = ["datacosmos"] # Adjust to point to your project directory

[tool.pydocstyle]
convention = "google"
[tool.pyright]
typeCheckingMode = "basic"

[tool.ruff]
fix = true
line-length = 88
exclude = [
".bzr",
".direnv",
Expand All @@ -60,7 +29,6 @@ exclude = [
".tox",
".venv",
".vscode",
"__pycache__",
"__pypackages__",
"_build",
"buck-out",
Expand All @@ -71,9 +39,25 @@ exclude = [
"venv",
]

line-length = 79
indent-width = 4

[tool.ruff.lint]
# I - Sort imports
# SLF - Private member access
# F - pyflakes
# C90 - Mccabe complexity check
# ANN - Type hint annotations
# BLE - Do not allow blind excepts
# B - Standard bug bears in Python code
# ARG - unused arguments
# ERA - remove uncommented code
extend-select = ["I", "SLF", "F", "C90", "BLE", "B", "ARG", "ERA"]

# Ignored rules
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

Expand All @@ -82,26 +66,10 @@ quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.black]
line-length = 88

[tool.isort]
profile = "black"

[tool.flake8]
max-line-length = 88
exclude = [
".venv",
"__pycache__",
"build",
"dist",
]
ignore = [
"E203", # Whitespace before ':', handled by Black
"W503", # Line break before binary operator
]
2 changes: 1 addition & 1 deletion tests/unit/datacosmos/client/test_client_authentication.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import MagicMock, patch
from unittest.mock import patch

from config.config import Config
from datacosmos.client import DatacosmosClient
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/datacosmos/client/test_client_delete_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from datacosmos.client import DatacosmosClient


@patch(
"datacosmos.client.DatacosmosClient._authenticate_and_initialize_client"
)
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client")
def test_delete_request(mock_auth_client):
"""
Test that the client performs a DELETE request correctly.
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/datacosmos/client/test_client_get_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from datacosmos.client import DatacosmosClient


@patch(
"datacosmos.client.DatacosmosClient._authenticate_and_initialize_client"
)
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client")
def test_client_get_request(mock_auth_client):
"""
Test that the client performs a GET request correctly.
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/datacosmos/client/test_client_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from datacosmos.client import DatacosmosClient


@patch(
"datacosmos.client.DatacosmosClient._authenticate_and_initialize_client"
)
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client")
@patch("os.path.exists", return_value=False)
@patch("config.Config.from_env")
def test_client_initialization(mock_from_env, mock_exists, mock_auth_client):
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/datacosmos/client/test_client_post_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from datacosmos.client import DatacosmosClient


@patch(
"datacosmos.client.DatacosmosClient._authenticate_and_initialize_client"
)
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client")
def test_post_request(mock_auth_client):
"""
Test that the client performs a POST request correctly.
Expand All @@ -26,9 +24,7 @@ def test_post_request(mock_auth_client):
audience="https://mock.audience",
)
client = DatacosmosClient(config=config)
response = client.post(
"https://mock.api/some-endpoint", json={"key": "value"}
)
response = client.post("https://mock.api/some-endpoint", json={"key": "value"})

# Assertions
assert response.status_code == 201
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/datacosmos/client/test_client_put_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from datacosmos.client import DatacosmosClient


@patch(
"datacosmos.client.DatacosmosClient._authenticate_and_initialize_client"
)
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client")
def test_put_request(mock_auth_client):
"""
Test that the client performs a PUT request correctly.
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/datacosmos/client/test_client_token_refreshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from datacosmos.client import DatacosmosClient


@patch(
"datacosmos.client.DatacosmosClient._authenticate_and_initialize_client"
)
@patch("datacosmos.client.DatacosmosClient._authenticate_and_initialize_client")
def test_client_token_refreshing(mock_auth_client):
"""
Test that the client refreshes the token when it expires.
Expand Down

0 comments on commit 319536e

Please sign in to comment.