Skip to content

Commit

Permalink
Merge pull request #34 from asmfreak/add-ghci
Browse files Browse the repository at this point in the history
Enable Github Actions
  • Loading branch information
asmfreak authored Jan 27, 2025
2 parents 861651e + bd492b3 commit 3673aae
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 108 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 flake8-quotes mypy nose rednose coverage hypothesis responses pylint
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
- name: Lints
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics setup.py habitipy &&
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics setup.py habitipy &&
pylint --rcfile=pylintrc --output-format=colorized --reports=no setup.py habitipy &&
mypy --ignore-missing-imports habitipy
- name: Tests
run: |
pip install -e . &&
nose2 -v --with-coverage --coverage=habitipy
2 changes: 1 addition & 1 deletion habitipy/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __call__( # type: ignore
**kwargs) -> Union[Dict, List]:
return self._request(*self._prepare_request(backend=session, **kwargs))

async def _request(self, request, request_args, request_kwargs):
async def _request(self, request, request_args, request_kwargs): # pylint: disable=invalid-overridden-method
async with request(*request_args, **request_kwargs) as resp:
if resp.status != self._node.retcode:
resp.raise_for_status()
Expand Down
17 changes: 10 additions & 7 deletions habitipy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
habitipy - tools and library for Habitica restful API
RESTful api abstraction module using requests
"""
# pylint: disable=invalid-name,too-few-public-methods,too-many-locals, bad-continuation
# pylint: disable=bad-whitespace
# pylint: disable=invalid-name,too-few-public-methods,too-many-locals

import json
import re
Expand Down Expand Up @@ -161,6 +160,7 @@ class Habitipy:
```
"""
# pylint: disable=too-many-arguments
def __init__(self, conf: Dict[str, str], *,
apis=None, current: Optional[List[str]] = None,
from_github=False, branch=None,
Expand Down Expand Up @@ -261,7 +261,7 @@ def _prepare_request(self, backend=requests, **kwargs):
raise TypeError('Mandatory param {} is missing'.format(name))
request = getattr(backend, method)
request_args = (uri,)
request_kwargs = dict(headers=headers, params=query)
request_kwargs = {'headers': headers, 'params': query}
if method in ['put', 'post', 'delete']:
request_kwargs['data'] = json.dumps(kwargs)
return request, request_args, request_kwargs
Expand All @@ -285,11 +285,14 @@ def __call__(self, **kwargs) -> Union[Dict, List]:
return self._request(*self._prepare_request(**kwargs))


def download_api(branch=None) -> str:
def download_api(branch=None, timeout=None) -> str:
"""download API documentation from _branch_ of Habitica\'s repo on Github"""
habitica_github_api = 'https://api.github.com/repos/HabitRPG/habitica'
if not branch:
branch = requests.get(habitica_github_api + '/releases/latest').json()['tag_name']
branch = requests.get(
habitica_github_api + '/releases/latest',
timeout=timeout
).json()['tag_name']
curl = local['curl']['-sL', habitica_github_api + '/tarball/{}'.format(branch)]
tar = local['tar'][
'axzf', '-', '--wildcards', '*/website/server/controllers/api-v3/*', '--to-stdout']
Expand All @@ -303,7 +306,7 @@ def save_apidoc(text: str) -> None:
apidoc_local = local.path(APIDOC_LOCAL_FILE)
if not apidoc_local.dirname.exists():
apidoc_local.dirname.mkdir()
with open(apidoc_local, 'w') as f:
with open(apidoc_local, 'w', encoding='utf-8') as f:
f.write(text)


Expand All @@ -323,7 +326,7 @@ def parse_apidoc(
if save_github_version:
save_apidoc(text)
else:
with open(file_or_branch) as f:
with open(file_or_branch, encoding='utf-8') as f:
text = f.read()
for line in text.split('\n'):
line = line.replace('\n', '')
Expand Down
Loading

0 comments on commit 3673aae

Please sign in to comment.