Skip to content

Commit

Permalink
fix: sarif workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
FallenDeity committed Dec 14, 2023
1 parent 1b60941 commit f6fa001
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ jobs:
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"

# upload SARIF if there are any results from the code scanning
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "../results/python.sarif"
category: "Code Scanning Results"
7 changes: 4 additions & 3 deletions pokelance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PokeLance:
----------
_http : HttpClient
The HTTP client used to make requests to the PokeAPI.
_logger : logging.Logger
_logger : typing.Union[logging.Logger, Logger]
The logger used to log information about the client.
_ext_tasks : t.List[t.Tuple[t.Coroutine[t.Any, t.Any, None], str]]
A list of coroutines to load extension data.
Expand Down Expand Up @@ -71,6 +71,7 @@ class PokeLance:
"""

EXTENSIONS: Path = Path(__file__).parent / "ext"
_logger: t.Union["logging.Logger", Logger]
berry: "Berry"
contest: "Contest"
evolution: "Evolution"
Expand Down Expand Up @@ -98,7 +99,7 @@ def __init__(
The size of the image cache. Defaults to 128.
cache_size : int
The size of the cache to use for the HTTP client.
logger : logging.Logger
logger : typing.Optional[logging.Logger]
The logger to use. If not provided, a new logger will be created.
file_logging : bool
Whether to log to a file. Defaults to False.
Expand Down Expand Up @@ -278,7 +279,7 @@ def ext_tasks(self) -> t.List[t.Tuple[t.Coroutine[t.Any, t.Any, None], str]]:
return self._ext_tasks

@property
def logger(self) -> "logging.Logger":
def logger(self) -> t.Union["logging.Logger", Logger]:
"""
The logger used to log information about the client.
Expand Down
21 changes: 18 additions & 3 deletions pokelance/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,34 @@ def __init__(
self._tasks_queue: t.List[asyncio.Task[None]] = []

async def _load_ext(self, coro: t.Coroutine[t.Any, t.Any, None], message: str) -> None:
"""
Load an extension's resources.
Parameters
----------
coro: typing.Coroutine
The coroutine to load.
message: str
The message to log.
"""
task: t.Optional[asyncio.Task[None]] = asyncio.current_task()
self._client.logger.debug(f"Loading {message}")
await coro
self._client.logger.info(message)
if task is not None:
self._tasks_queue.remove(task)
self._client.logger.info(f"Loaded {message}")

async def _schedule_tasks(self) -> None:
"""Schedules the tasks for the HTTP client."""
total = len(self._client.ext_tasks)
for num, (coro, name) in enumerate(self._client.ext_tasks):
message = f"Extension {name} endpoints ({num + 1}/{total})"
self._client.logger.debug(f"Loading {message}")
task = asyncio.create_task(self._load_ext(coro, f"Loaded {message}"), name=name)
task = asyncio.create_task(coro=self._load_ext(coro, message), name=name)
self._tasks_queue.append(task)
self._client.ext_tasks.clear()

async def close(self) -> None:
"""Closes the HTTP client."""
for task in self._tasks_queue:
if not task.done():
task.cancel()
Expand Down

0 comments on commit f6fa001

Please sign in to comment.