Skip to content

Commit

Permalink
Merge pull request #7 from M4RC0Sx/develop
Browse files Browse the repository at this point in the history
New linting rules
  • Loading branch information
M4RC0Sx authored Aug 19, 2024
2 parents b7ab221 + 196e8fb commit 5404bb4
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ jobs:
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

#----------------------------------------------
# Run linting checks
#----------------------------------------------
- name: Run linting checks
run: poetry run ruff check

#----------------------------------------------
# Run tests
Expand Down
8 changes: 6 additions & 2 deletions esiosapy/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Optional
from urllib.parse import urljoin, urlparse

import requests
Expand All @@ -23,7 +23,11 @@ def __init__(self, token: str, base_url: str = ESIOS_API_URL):
self.request_helper
)

def raw_request(self, url: str, headers: Dict[str, str] = {}) -> requests.Response:
def raw_request(
self, url: str, headers: Optional[Dict[str, str]] = None
) -> requests.Response:
if headers is None:
headers = {}
headers = self.request_helper.add_default_headers(headers)

if urlparse(url).netloc == "":
Expand Down
2 changes: 1 addition & 1 deletion esiosapy/managers/archive_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Dict, List, Optional, Union
from datetime import datetime
from typing import Dict, List, Optional, Union

from esiosapy.models.archive.archive import Archive
from esiosapy.models.archive.archive_date_type import ArchiveDateType
Expand Down
1 change: 0 additions & 1 deletion esiosapy/managers/indicator_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict, List, Optional, Union


from esiosapy.models.indicator.indicator import Indicator
from esiosapy.utils.request_helper import RequestHelper

Expand Down
1 change: 0 additions & 1 deletion esiosapy/managers/offer_indicator_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict, List, Optional, Union


from esiosapy.models.offer_indicator.offer_indicator import OfferIndicator
from esiosapy.utils.request_helper import RequestHelper

Expand Down
10 changes: 6 additions & 4 deletions esiosapy/models/archive/archive.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os
from datetime import datetime, date
from datetime import date, datetime
from pathlib import Path
from typing import List, Dict, Any, Union
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel

from esiosapy.models.archive.archive_download import ArchiveDownload
from esiosapy.models.archive.taxonomy_term import TaxonomyTerm
from esiosapy.models.archive.vocabulary import Vocabulary

from esiosapy.utils.request_helper import RequestHelper
from esiosapy.utils.zip_utils import recursive_unzip

Expand All @@ -34,10 +33,13 @@ def __init__(self, **data: Any):

def download_file(
self,
path: Union[str, Path] = Path.cwd(),
path: Optional[Union[str, Path]] = None,
unzip: bool = True,
remove_zip: bool = True,
) -> None:
if path is None:
path = Path.cwd()

response = self._request_helper.get_request(self.download.url)

zip_path = Path(os.path.join(path, f"{self.name}.zip"))
Expand Down
8 changes: 5 additions & 3 deletions esiosapy/models/indicator/indicator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Dict, Any, Optional, Union
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel

Expand Down Expand Up @@ -28,8 +28,10 @@ def prettify_description(self) -> str:
from bs4 import BeautifulSoup # type: ignore
except ImportError:
raise ImportError(
"The `beautifulsoup4` package is required to prettify the description. Install it with 'pip install beautifulsoup4' or with your preferred package manager."
)
"The `beautifulsoup4` package is required to prettify the description. "
"Install it with 'pip install beautifulsoup4' "
"or with your preferred package manager."
) from None

soup = BeautifulSoup(self.description, "html.parser")
text = soup.get_text(separator="\n").strip()
Expand Down
8 changes: 5 additions & 3 deletions esiosapy/models/offer_indicator/offer_indicator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Dict, Any, Union
from typing import Any, Dict, List, Union

from pydantic import BaseModel

Expand All @@ -23,8 +23,10 @@ def prettify_description(self) -> str:
from bs4 import BeautifulSoup # type: ignore
except ImportError:
raise ImportError(
"The `beautifulsoup4` package is required to prettify the description. Install it with 'pip install beautifulsoup4' or with your preferred package manager."
)
"The `beautifulsoup4` package is required to prettify the description. "
"Install it with 'pip install beautifulsoup4' "
"or with your preferred package manager."
) from None

soup = BeautifulSoup(self.description, "html.parser")
text = soup.get_text(separator="\n").strip()
Expand Down
11 changes: 8 additions & 3 deletions esiosapy/utils/request_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Dict, List, Optional, Union
from urllib.parse import urljoin
from typing import Dict, List, Union

import requests

Expand All @@ -24,9 +24,14 @@ def add_default_headers(self, headers: Dict[str, str]) -> Dict[str, str]:
def get_request(
self,
path: str,
headers: Dict[str, str] = {},
params: Dict[str, Union[str, int, List[str]]] = {},
headers: Optional[Dict[str, str]] = None,
params: Optional[Dict[str, Union[str, int, List[str]]]] = None,
) -> requests.Response:
if headers is None:
headers = {}
if params is None:
params = {}

headers = self.add_default_headers(headers)
url = urljoin(self.base_url, path)

Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ pytest-mock = "^3.14.0"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff.lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
]

[tool.mypy]
strict = true
plugins = [
Expand Down
12 changes: 7 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest
from pytest_mock import MockerFixture
from typing import Dict
from urllib.parse import urljoin

import pytest
import requests
from pytest_mock import MockerFixture

from esiosapy.client import ESIOSAPYClient
from esiosapy.managers.archive_manager import ArchiveManager
from esiosapy.managers.indicator_manager import IndicatorManager
Expand All @@ -16,13 +18,13 @@ def esios_client(self, mocker: MockerFixture) -> ESIOSAPYClient:
mock_request_helper = mocker.patch(
"esiosapy.client.RequestHelper", autospec=True
)
mock_archive_manager = mocker.patch(
mock_archive_manager = mocker.patch( # noqa: F841
"esiosapy.client.ArchiveManager", autospec=True
)
mock_indicator_manager = mocker.patch(
mock_indicator_manager = mocker.patch( # noqa: F841
"esiosapy.client.IndicatorManager", autospec=True
)
mock_offer_indicator_manager = mocker.patch(
mock_offer_indicator_manager = mocker.patch( # noqa: F841
"esiosapy.client.OfferIndicatorManager", autospec=True
)

Expand Down
5 changes: 3 additions & 2 deletions tests/utils/test_request_helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Dict, List, Union
import pytest
from urllib.parse import urljoin
from pytest_mock import MockerFixture

import pytest
import requests
from pytest_mock import MockerFixture

from esiosapy.utils.request_helper import RequestHelper

Expand Down

0 comments on commit 5404bb4

Please sign in to comment.