Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(linter): add isort & black #12

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8
- run: pip install -r requirements.txt
- uses: isort/isort-action@master
with:
isortVersion: '5.12.0'
- uses: psf/black@stable
with:
version: '23.9.0'

semantic-release:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
# wait until test & lint complete
needs: ['lint']
# needs: ['lint', 'test']
steps:
- uses: actions/checkout@v3
Expand Down
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-case-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: name-tests-test
- id: requirements-txt-fixer
- id: detect-private-key
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--line-length=100", "--python-version=38"]
- repo: https://github.com/psf/black
rev: 23.9.0
hooks:
- id: black
args: ["--line-length=100", "--target-version=py38"]
39 changes: 39 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing to the project

This project is still under construction. We welcome any contributions. Please **carefully** read the following instructions before contributing.

## Code style

We use `isort` with `black` to enforce a consistent code style.
```shell
pip install isort==5.12.0 black==23.9.0
```

Configs can be found in `pyproject.toml`.

CI also checks code style before pushing to `main` branch. Try to run `isort` and `black` locally before pushing to avoid unnecessary CI failures:
```shell
isort .
black .
```

### Pre-commit hook

To automatically run `isort` and `black` before each commit, install `pre-commit`:
```shell
pip install pre-commit
```

Then run `pre-commit install` to install the hook.

## Commit message

Check out [this article](https://www.conventionalcommits.org/en/v1.0.0/) for a detailed explanation of how to write a good commit message.

Commit messages started with `feat` will trigger a major version bump, `fix` will trigger a minor version bump.

Also check out [semantic-release](https://github.com/semantic-release/semantic-release) for details.

## Test

⚠ Under construction. ⚠
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Quickstart

.. code-block:: python


import asyncio
import logging

Expand Down Expand Up @@ -69,3 +69,7 @@ Supported python versions:
- 3.11
- 3.10
- 3.9

Contributing
------------
Contributions are always welcome! Please read the `contributing guidelines <CONTRIBUTE.md>`__ first.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ endpoints
- Item class inherits from WorldstateObject and MultiQueryModel
- Put all major infos in the Item class (split them later)

- Test compatibility with Python 3.8

## Version 2.0

- Remove `WorldstateClient.query_list_of(type)` as `WorldstateClient.query(type)` now does the same while keeping the type.
5 changes: 1 addition & 4 deletions examples/worldstate/custom_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from typing import Literal

from warframe.worldstate import WorldstateClient
from warframe.worldstate.common.core import ( # this import might change
SingleQueryModel,
TimedEvent,
)
from warframe.worldstate.common.core import SingleQueryModel, TimedEvent # this import might change


class CustomCambionDrift(SingleQueryModel, TimedEvent):
Expand Down
8 changes: 2 additions & 6 deletions examples/worldstate/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ async def on_cetus_state_change(cetus: Cetus):


async def main():
print(
(await client.query(OrbVallis))
) # this is just to have a reference to the current state
print(
(await client.query(Cetus))
) # this is just to have a reference to the current state
print((await client.query(OrbVallis))) # this is just to have a reference to the current state
print((await client.query(Cetus))) # this is just to have a reference to the current state
on_vallis_state_change.start() # start the listener
on_cetus_state_change.start()
await asyncio.sleep(3600) # for testing, we wait an hour here
Expand Down
8 changes: 6 additions & 2 deletions examples/worldstate/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
async def main():
async with WorldstateClient() as client:
# import from models and pass the type you want the object of
arbi = await client.query(Arbitration) # of Type SingleQuery - a single object of type `Arbitration`
fissures = await client.query(Fissure) # of Type MultiQuery - a list of objects of type `Fissure`
arbi = await client.query(
Arbitration
) # of Type SingleQuery - a single object of type `Arbitration`
fissures = await client.query(
Fissure
) # of Type MultiQuery - a list of objects of type `Fissure`

print(arbi)
for fissure in fissures:
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"
py_version = "38"
line_length = 100

[tool.black]
line-length = 100
target-version = ["py38"]
include = '\.pyi?$'
40 changes: 8 additions & 32 deletions warframe/worldstate/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@
import logging
from datetime import datetime, timezone
from functools import wraps
from typing import (
Any,
Callable,
Coroutine,
List,
Optional,
Type,
TypeVar,
Union,
overload,
)
from typing import Any, Callable, Coroutine, List, Optional, Type, TypeVar, Union, overload

import aiohttp
import msgspec
Expand Down Expand Up @@ -113,21 +103,15 @@ async def _request(

url = build_endpoint(type, language)

logging.getLogger(__name__).debug(
f"Sending request to the {type.__name__} endpoint"
)
logging.getLogger(__name__).debug(f"Sending request to the {type.__name__} endpoint")

async with self._session.get(url) as response:
response_text = await response.text()

if response.status != 200:
raise WorldstateAPIError(
msgspec.json.decode(response_text, type=ErrorMessage)
)
raise WorldstateAPIError(msgspec.json.decode(response_text, type=ErrorMessage))

logging.getLogger(__name__).debug(
f"Got request from the {type.__name__} endpoint"
)
logging.getLogger(__name__).debug(f"Got request from the {type.__name__} endpoint")

return response_text

Expand Down Expand Up @@ -227,19 +211,15 @@ async def get_cetus(self, language: Optional[Language] = None) -> Cetus:
json = await self._request(Cetus, language)
return Cetus._from_json(json)

async def get_cambion_drift(
self, language: Optional[Language] = None
) -> CambionDrift:
async def get_cambion_drift(self, language: Optional[Language] = None) -> CambionDrift:
json = await self._request(CambionDrift, language)
return CambionDrift._from_json(json)

async def get_orb_vallis(self, language: Optional[Language] = None) -> OrbVallis:
json = await self._request(OrbVallis, language)
return OrbVallis._from_json(json)

async def get_alerts(
self, language: Optional[Language] = None
) -> Optional[List[Alert]]:
async def get_alerts(self, language: Optional[Language] = None) -> Optional[List[Alert]]:
json = await self._request(OrbVallis, language)
return Alert._from_json(json)

Expand Down Expand Up @@ -273,12 +253,8 @@ def listen_to(self, type: Type[SingleQueryTimedEvent]):
Returns:
_TaskHelper: A helper class that wraps the callback function. Call `.start()` on it in order to start the listener. Same goes for `.stop()`
"""
if not issubclass(type, SingleQueryModel) and not not issubclass(
type, TimedEvent
):
raise TypeError(
f"{type.__name__} has to implement SingleQueryModel and TimedEvent"
)
if not issubclass(type, SingleQueryModel) and not not issubclass(type, TimedEvent):
raise TypeError(f"{type.__name__} has to implement SingleQueryModel and TimedEvent")

def decorator(
func: Callable[[SingleQueryTimedEvent], Coroutine[Any, Any, None]]
Expand Down
2 changes: 1 addition & 1 deletion warframe/worldstate/enums/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .faction import *
from .mission_type import *
from .language import *
from .mission_type import *
from .syndicate import Syndicate
16 changes: 8 additions & 8 deletions warframe/worldstate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from .alert import *
from .arbitration import *
from .archon_hunt import *
from .cambion_drift import *
from .cetus import *
from .counted_item import *
from .daily_deal import *
from .event import *
from .fissure import *
from .flash_sale import *
from .invasion import *
from .mission import *
from .orb_vallis import *
from .arbitration import *
from .counted_item import *
from .reward import *
from .mission import *
from .invasion import *
from .void_trader import *
from .fissure import *
from .archon_hunt import *
from .sortie import *
from .event import *
from .void_trader import *
5 changes: 2 additions & 3 deletions warframe/worldstate/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

from msgspec import field

from .reward import Reward

from ..common import MultiQueryModel, TimedEvent
from ..enums import MissionType, Faction, Syndicate
from ..enums import Faction, MissionType, Syndicate
from .reward import Reward

__all__ = ["Event"]

Expand Down
2 changes: 1 addition & 1 deletion warframe/worldstate/models/sortie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from msgspec import field

from ..common import SingleQueryModel, TimedEvent
from ..enums import MissionType, Faction
from ..enums import Faction, MissionType

__all__ = ["Sortie"]

Expand Down
2 changes: 1 addition & 1 deletion warframe/worldstate/models/void_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from msgspec import field

from ..common import SingleQueryModel, WorldstateObject, TimedEvent
from ..common import SingleQueryModel, TimedEvent, WorldstateObject

__all__ = ["VoidTrader"]

Expand Down