Skip to content

Commit

Permalink
Improve code formatting and linting
Browse files Browse the repository at this point in the history
* switch out black,isort and flake8 for ruff
* update tox
* reformat/lint/sort imports to comply with ruff settings
  • Loading branch information
JakubFrejlach committed Dec 20, 2024
1 parent c8882a2 commit 2f7c8f4
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- name: Install dependencies
run: python3 -m pip install --upgrade pip build
- name: Build python package
Expand Down
21 changes: 5 additions & 16 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
name: Lint
on: [push]
jobs:
black:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- name: Install dependencies
run: pip install tox==3.24.5
- name: Check that code is formatted with black
run: tox -e black
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: pip install tox==3.24.5
- name: Check that imports are formatted with isort
run: tox -e isort
run: pip install tox==4.23.2
- name: Check that code is formatted and linted with ruff
run: tox -e ruff
1 change: 1 addition & 0 deletions devel-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
openapi-python-client
pip-tools
pytest
ruff
tox
81 changes: 44 additions & 37 deletions devel-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,49 @@ attrs==24.2.0 \
--hash=sha256:5cfb1b9148b5b086569baec03f20d7b6bf3bcacc9a42bebf87ffaaca362f6346 \
--hash=sha256:81921eb96de3191c8258c199618104dd27ac608d9366f5e35d011eae1867ede2
# via
# -c requirements.txt
# -c /home/jfrejlac/work/osidb-bindings/requirements.txt
# openapi-python-client
backports-entry-points-selectable==1.1.1 \
--hash=sha256:7fceed9532a7aa2bd888654a7314f864a3c16a4e710b34a58cfc0f08114c663b \
--hash=sha256:914b21a479fde881635f7af5adc7f6e38d6b274be32269070c53b698c60d5386
# via virtualenv
build==1.2.2.post1 \
--hash=sha256:1d61c0887fa860c01971625baae8bdd338e517b836a2f70dd1f7aa3a6b2fc5b5 \
--hash=sha256:b36993e92ca9375a219c99e606a122ff365a760a2d4bba0caa09bd5278b608b7
# via pip-tools
cachetools==5.5.0 \
--hash=sha256:02134e8439cdc2ffb62023ce1debca2944c3f289d66bb17ead3ab3dede74b292 \
--hash=sha256:2cc24fb4cbe39633fb7badd9db9ca6295d766d9c2995f245725a46715d050f2a
# via tox
certifi==2024.8.30 \
--hash=sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8 \
--hash=sha256:bec941d2aa8195e248a60b31ff9f0558284cf01a52591ceda73ea9afffd69fd9
# via
# -c requirements.txt
# -c /home/jfrejlac/work/osidb-bindings/requirements.txt
# httpx
chardet==5.2.0 \
--hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \
--hash=sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970
# via tox
charset-normalizer==2.0.7 \
--hash=sha256:e019de665e2bcf9c2b64e2e5aa025fa991da8720daa3c1138cadd2fd1856aed0 \
--hash=sha256:f7af805c321bfa1ce6714c51f254e0d5bb5e5834039bc17db7ebe3a4cec9492b
# via
# -c requirements.txt
# -c /home/jfrejlac/work/osidb-bindings/requirements.txt
# httpx
click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
--hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
# via
# pip-tools
# typer
distlib==0.3.3 \
--hash=sha256:c8b54e8454e5bf6237cc84c20e8264c3e991e824ef27e8f1e81049867d861e31 \
--hash=sha256:d982d0751ff6eaaab5e2ec8e691d949ee80eddf01a62eaa96ddb11531fe16b05
colorama==0.4.6 \
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
# via tox
distlib==0.3.9 \
--hash=sha256:47f8c22fd27c27e25a65601af709b38e4f0a45ea4fc2e710f65755fa8caaaf87 \
--hash=sha256:a60f20dea646b8a33f3e7772f74dc0b2d0772d2837ee1342a00645c81edf9403
# via virtualenv
filelock==3.4.0 \
--hash=sha256:2e139a228bcf56dd8b2274a65174d005c4a6b68540ee0bdbb92c76f43f29f7e8 \
--hash=sha256:93d512b32a23baf4cac44ffd72ccf70732aeff7b8050fcaf6d3ec406d954baf4
filelock==3.16.1 \
--hash=sha256:2082e5703d51fbf98ea75855d9d5527e33d8ff23099bec374a134febee6946b0 \
--hash=sha256:c249fbfcd5db47e5e2d6d62198e565475ee65e4831e2561c8e313fa7eb961435
# via
# tox
# virtualenv
Expand All @@ -70,7 +78,7 @@ idna==3.10 \
--hash=sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9 \
--hash=sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3
# via
# -c requirements.txt
# -c /home/jfrejlac/work/osidb-bindings/requirements.txt
# anyio
# rfc3986
iniconfig==1.1.1 \
Expand Down Expand Up @@ -169,26 +177,25 @@ packaging==24.2 \
--hash=sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f
# via
# build
# pyproject-api
# pytest
# tox
pip-tools==7.4.1 \
--hash=sha256:4c690e5fbae2f21e87843e89c26191f0d9454f362d8acdbd695716493ec8b3a9 \
--hash=sha256:864826f5073864450e24dbeeb85ce3920cdfb09848a3d69ebf537b521f14bcc9
# via -r devel-requirements.in
platformdirs==2.4.0 \
--hash=sha256:367a5e80b3d04d2428ffa76d33f124cf11e8fff2acdaa9b43d545f5c7d661ef2 \
--hash=sha256:8868bbe3c3c80d42f20156f22e7131d2fb321f5bc86a2a345375c6481a67021d
# via virtualenv
platformdirs==4.3.6 \
--hash=sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907 \
--hash=sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb
# via
# tox
# virtualenv
pluggy==1.5.0 \
--hash=sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1 \
--hash=sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669
# via
# pytest
# tox
py==1.11.0 \
--hash=sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719 \
--hash=sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378
# via tox
pydantic==2.10.3 \
--hash=sha256:be04d85bbc7b65651c5f8e6b9976ed9c6f41782a55524cef079a34a0bb82144d \
--hash=sha256:cb5ac360ce894ceacd69c403187900a02c4b20b693a9dd1d643e1effab9eadf9
Expand Down Expand Up @@ -299,6 +306,10 @@ pygments==2.18.0 \
--hash=sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199 \
--hash=sha256:b8e6aca0523f3ab76fee51799c488e38782ac06eafcf95e7ba832985c8e7b13a
# via rich
pyproject-api==1.8.0 \
--hash=sha256:3d7d347a047afe796fd5d1885b1e391ba29be7169bd2f102fcd378f04273d228 \
--hash=sha256:77b8049f2feb5d33eefcc21b57f1e279636277a8ac8ad6b5871037b243778496
# via tox
pyproject-hooks==1.2.0 \
--hash=sha256:1e859bd5c40fae9448642dd871adf459e5e2084186e8d2c2a79a824c970da1f8 \
--hash=sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913
Expand All @@ -313,7 +324,7 @@ python-dateutil==2.8.2 \
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
# via
# -c requirements.txt
# -c /home/jfrejlac/work/osidb-bindings/requirements.txt
# openapi-python-client
rfc3986[idna2008]==1.5.0 \
--hash=sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835 \
Expand Down Expand Up @@ -394,7 +405,9 @@ ruff==0.8.2 \
--hash=sha256:ec016beb69ac16be416c435828be702ee694c0d722505f9c1f35e1b9c0cc1bf5 \
--hash=sha256:f05cdf8d050b30e2ba55c9b09330b51f9f97d36d4673213679b965d25a785f3c \
--hash=sha256:fb88e2a506b70cfbc2de6fae6681c4f944f7dd5f2fe87233a7233d888bad73e8
# via openapi-python-client
# via
# -r devel-requirements.in
# openapi-python-client
shellingham==1.4.0 \
--hash=sha256:4855c2458d6904829bd34c299f11fdeed7cfefbf8a2c522e4caea6cd76b3171e \
--hash=sha256:536b67a0697f2e4af32ab176c00a50ac2899c5a05e0d8e2dadac8e58888283f9
Expand All @@ -405,24 +418,18 @@ six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
# via
# -c requirements.txt
# -c /home/jfrejlac/work/osidb-bindings/requirements.txt
# python-dateutil
# tox
# virtualenv
sniffio==1.2.0 \
--hash=sha256:471b71698eac1c2112a40ce2752bb2f4a4814c22a54a3eed3676bc0f5ca9f663 \
--hash=sha256:c4666eecec1d3f50960c6bdf61ab7bc350648da6c126e3cf6898d8cd4ddcd3de
# via
# anyio
# httpcore
# httpx
toml==0.10.2 \
--hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \
--hash=sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f
# via tox
tox==3.24.4 \
--hash=sha256:5e274227a53dc9ef856767c21867377ba395992549f02ce55eb549f9fb9a8d10 \
--hash=sha256:c30b57fa2477f1fb7c36aa1d83292d5c2336cd0018119e1b1c17340e2c2708ca
tox==4.23.2 \
--hash=sha256:452bc32bb031f2282881a2118923176445bac783ab97c874b8770ab4c3b76c38 \
--hash=sha256:86075e00e555df6e82e74cfc333917f91ecb47ffbc868dcafbd2672e332f4a2c
# via -r devel-requirements.in
typer==0.13.1 \
--hash=sha256:5b59580fd925e89463a29d363e0a43245ec02765bde9fb77d39e5d0f29dd7157 \
Expand All @@ -436,9 +443,9 @@ typing-extensions==4.12.2 \
# pydantic
# pydantic-core
# typer
virtualenv==20.10.0 \
--hash=sha256:4b02e52a624336eece99c96e3ab7111f469c24ba226a53ec474e8e787b365814 \
--hash=sha256:576d05b46eace16a9c348085f7d0dc8ef28713a2cabaa1cf0aea41e8f12c9218
virtualenv==20.28.0 \
--hash=sha256:23eae1b4516ecd610481eda647f3a7c09aea295055337331bb4e6892ecce47b0 \
--hash=sha256:2c9c3262bb8e7b87ea801d715fae4495e6032450c71d2309be9550e7364049aa
# via tox
wheel==0.45.1 \
--hash=sha256:661e1abd9198507b1409a20c02106d9670b2576e916d58f520316666abca6729 \
Expand Down
5 changes: 4 additions & 1 deletion osidb_bindings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from .session import Paginator, new_session
from .session import Paginator
from .session import new_session
from .utils import cve_ids

__all__ = ("cve_ids", "new_session", "Paginator")
1 change: 0 additions & 1 deletion osidb_bindings/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
osidb-bindings constants
"""


from typing import List

OSIDB_API_VERSION: str = "v1"
Expand Down
1 change: 1 addition & 0 deletions osidb_bindings/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
osidb-registry-bindings helpers
"""

import json
from os import getenv
from typing import Any, Union
Expand Down
3 changes: 0 additions & 3 deletions osidb_bindings/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __init__(
init_response=None,
**kwargs,
):

if not init_response and not retrieve_list_fn:
raise OSIDBBindingsException(
(
Expand Down Expand Up @@ -59,7 +58,6 @@ def __iter__(self):

def __next__(self):
if self.current_response is None:

# no current response page - obtain the first page
response = self.retrieve_list_fn(
*self.args,
Expand All @@ -73,7 +71,6 @@ def __next__(self):
self.current_response = response
return response
else:

# existing current response - call next page
response = self.current_response.next()
if response is not None:
Expand Down
21 changes: 6 additions & 15 deletions osidb_bindings/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
auth_token_refresh_create,
auth_token_retrieve,
)
from .bindings.python_client.types import UNSET
from .constants import (
ALL_SESSION_OPERATIONS,
DEFAULT_LIMIT,
Expand Down Expand Up @@ -55,8 +54,8 @@ def file_trackers(self, form_data: Dict[str, Any], *args, **kwargs):
model = getattr(method_module, "REQUEST_BODY_TYPE", None)
if model is None:
raise UndefinedRequestBody(
f'The request body for the resource "trackers" '
f'and the operation "file" is not defined.'
'The request body for the resource "trackers" '
'and the operation "file" is not defined.'
)

transformed_data = serialize_data(form_data, model)
Expand Down Expand Up @@ -92,8 +91,8 @@ def reject_flaw(self, id: str, form_data: Dict[str, Any], *args, **kwargs):
model = getattr(method_module, "REQUEST_BODY_TYPE", None)
if model is None:
raise UndefinedRequestBody(
f'The request body for the resource "flaw" '
f'and the operation "reject" is not defined.'
'The request body for the resource "flaw" '
'and the operation "reject" is not defined.'
)
transformed_data = serialize_data(form_data, model)
return sync_fn(
Expand Down Expand Up @@ -168,11 +167,9 @@ def new_session(
"""Create a new session for selected OSIDB URI"""

if username and password:

# OSIDB instances with the username/password auth for token acquirement
auth = (username, password)
else:

# OSIDB instances with the kerberos auth for token acquirement
auth = "kerberos"

Expand All @@ -185,7 +182,6 @@ class Session:
"""Simple session wrapper which encapsulates the client"""

def __init__(self, base_url, auth=None, verify_ssl=True):

# Store auth for the refresh token acquirement
self.auth = auth

Expand Down Expand Up @@ -316,19 +312,14 @@ def __get_access_token(self) -> str:
try:
response = auth_token_refresh_create.sync(
client=self.__client,
body=models.TokenRefresh.from_dict(
{"refresh": self.refresh_token}
),
body=models.TokenRefresh.from_dict({"refresh": self.refresh_token}),
)
except requests.HTTPError:

# expired refresh token, renew it and try again
self.refresh_token = self.__get_refresh_token()
response = auth_token_refresh_create.sync(
client=self.__client,
body=models.TokenRefresh.from_dict(
{"refresh": self.refresh_token}
),
body=models.TokenRefresh.from_dict({"refresh": self.refresh_token}),
)

return response.access
Expand Down
1 change: 0 additions & 1 deletion osidb_bindings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
osidb-bindings user utilities
"""


from typing import List

from .session import Session
Expand Down
3 changes: 2 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import logging

import pytest

logger = logging.getLogger(__name__)
pytestmark = pytest.mark.unit

Expand Down
Loading

0 comments on commit 2f7c8f4

Please sign in to comment.