Skip to content

Commit

Permalink
improved ci
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Oct 30, 2024
1 parent a5062dd commit 695b45a
Show file tree
Hide file tree
Showing 13 changed files with 944 additions and 53 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
runs:
using: composite
steps:
- name: "Install UV"
shell: bash
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
81 changes: 44 additions & 37 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
# This workflow will install Python dependencies, run tests with pytest, and publish package on successful builds.
name: Python package

on:
push:
branches:
- main
workflow_dispatch:

jobs:
test:
lock_file:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11']
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run tests
run: |
pytest --maxfail=5 --disable-warnings
deploy:
needs: test
- uses: ./.github/actions/setup
- run: uv lock --locked
linting:
runs-on: ubuntu-latest
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: uvx ruff check .
formatting:
runs-on: ubuntu-latest
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: uvx ruff format --check .
type_consistency:
runs-on: ubuntu-latest
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: uv run pyright .
tests:
runs-on: ubuntu-latest
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: uv run pytest -v --durations=0 --cov --cov-report=xml
# TODO
# - name: Upload Coverage to Codecov
# uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}

build_and_deploy:
runs-on: [ubuntu-latest]
needs: [linting, formatting, type_consistency, tests]
# Run only on manual trigger
if: ${{ github.event_name == 'workflow_dispatch' }}
environment: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build

- uses: ./.github/actions/setup
- run: uv run python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Empty file removed Makefiile
Empty file.
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
clean-pyc: ## Clean Python cache files
find . \( -name '*.pyc' -o -name '*.pyo' -o -name '*~' -o -name '__pycache__' -o -name '.pytest_cache' \) -exec rm -rf {} +

clean-test: ## Cleanup pytest leftovers
rm -f .coverage
rm -fr htmlcov/
rm -fr test_results/
rm -f *report.html log.html test-results.html output.xml

pre-commit-setup: ## Install pre-commit
python3 -m pip install pre-commit
pre-commit --version

requirements: ## Install all requirements
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-test.txt
python3 -m pip install ruff

setup: requirements pre-commit-setup## Set up all requirements

docs: ## Open your browser to the web apps testing docs
@echo "Opening documentation..."
xdg-open http://localhost:5000/docs || open http://localhost:5000/docs
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async def main():
if __name__ == "__main__":
asyncio.run(main())
```
## wiki prices
the wiki via runelite collects item price, which they expose via an api.
```py
import asyncio
from aiohttp import ClientSession
Expand Down
16 changes: 8 additions & 8 deletions osrs/async_api/osrs/hiscores.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@


class Mode(str, Enum):
OLDSCHOOL: str = "hiscore_oldschool"
IRONMAN: str = "hiscore_oldschool_ironman"
HARDCORE: str = "hiscore_oldschool_hardcore_ironman"
ULTIMATE: str = "hiscore_oldschool_ultimate"
DEADMAN: str = "hiscore_oldschool_deadman"
SEASONAL: str = "hiscore_oldschool_seasonal"
TOURNAMENT: str = "hiscore_oldschool_tournament"
OLDSCHOOL = "hiscore_oldschool"
IRONMAN = "hiscore_oldschool_ironman"
HARDCORE = "hiscore_oldschool_hardcore_ironman"
ULTIMATE = "hiscore_oldschool_ultimate"
DEADMAN = "hiscore_oldschool_deadman"
SEASONAL = "hiscore_oldschool_seasonal"
TOURNAMENT = "hiscore_oldschool_tournament"


class Skill(BaseModel):
Expand Down Expand Up @@ -69,7 +69,7 @@ async def get(self, mode: Mode, player: str, session: ClientSession) -> PlayerSt
"""
await self.rate_limiter.check()

logger.info(f"Performing hiscores lookup on {player}")
logger.debug(f"Performing hiscores lookup on {player}")
url = f"{self.BASE_URL}/m={mode.value}/index_lite.json"
params = {"player": player}

Expand Down
10 changes: 5 additions & 5 deletions osrs/async_api/osrs/itemdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


class Mode(str, Enum):
OLDSCHOOL: str = "itemdb_oldschool"
RS3: str = "itemdb_rs"
OLDSCHOOL = "itemdb_oldschool"
RS3 = "itemdb_rs"


class CurrentPrice(BaseModel):
Expand Down Expand Up @@ -122,7 +122,7 @@ async def get_items(
params = {"category": category, "alpha": alpha, "page": page}
params = {k: v for k, v in params.items()}

logger.info(f"[GET]: {url=}, {params=}")
logger.debug(f"[GET]: {url=}, {params=}")

async with session.get(url, proxy=self.proxy, params=params) as response:
response.raise_for_status()
Expand Down Expand Up @@ -150,7 +150,7 @@ async def get_detail(
url = f"{self.BASE_URL}/m={mode.value}/api/catalogue/detail.json"
params = {"item": item_id}

logger.info(f"[GET]: {url=}, {params=}")
logger.debug(f"[GET]: {url=}, {params=}")

async with session.get(url, proxy=self.proxy, params=params) as response:
response.raise_for_status()
Expand Down Expand Up @@ -194,7 +194,7 @@ async def get_graph(

url = f"{self.BASE_URL}/m={mode.value}/api/graph/{item_id}.json"

logger.info(f"[GET]: {url=}")
logger.debug(f"[GET]: {url=}")

async with session.get(url, proxy=self.proxy) as response:
response.raise_for_status()
Expand Down
2 changes: 1 addition & 1 deletion osrs/async_api/wiki/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WikiPrices:

def __init__(
self,
user_agent: str = None,
user_agent: str = "",
proxy: str = "",
rate_limiter: RateLimiter = RateLimiter(),
) -> None:
Expand Down
15 changes: 14 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"aiohttp>=3.10.10",
"pydantic>=2.9.2",
"requests>=2.32.3",
]

[project.urls]
"Homepage" = "https://github.com/Bot-detector/osrs"
"Bug Tracker" = "https://github.com/Bot-detector/osrs/issues"
"Bug Tracker" = "https://github.com/Bot-detector/osrs/issues"

[dependency-groups]
dev = [
"pyright>=1.1.387",
"pytest-asyncio>=0.24.0",
"pytest-cov>=6.0.0",
"pytest>=8.3.3",
]
Binary file removed requirements-test.txt
Binary file not shown.
Binary file removed requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_async_wiki_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def test_get_average_prices_invalid():
with pytest.raises(Exception):
await wiki_prices_instance.get_average_prices(
session=session,
interval="invalid_interval",
interval="invalid_interval", # type: ignore
)


Expand Down
Loading

0 comments on commit 695b45a

Please sign in to comment.