Skip to content
Open
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
68 changes: 47 additions & 21 deletions .github/workflows/build_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,58 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v6
with:
python-version: '3.9'
- uses: Gr1N/setup-poetry@v8
- run: poetry install
- run: poetry run poe tests_unit
- run: poetry run poe checks_codestyle
- run: poetry run poe checks_typing
- run: poetry run poe checks_license
python-version: '3.13'

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1

- name: Install dependencies
run: poetry install

- name: Unit tests
run: poetry run poe tests_unit

- name: Code style, typing and license checks
run: poetry run poe checks_codestyle

- name: Check typings
run: poetry run poe checks_typing

build:
needs: [test]
name: Build the release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4

- uses: actions/setup-python@v6
with:
python-version: '3.9'
- uses: Gr1N/setup-poetry@v8
python-version: '3.13'

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1

- name: Get git release tag
run: echo "git-release-tag=yapapi $(git describe --tags)" >> $GITHUB_OUTPUT
id: git_describe

- name: Get package version
run: echo "poetry-version=$(poetry version)" >> $GITHUB_OUTPUT
id: poetry_version

- name: Fail on version mismatch
run: exit 1
if:
${{ steps.git_describe.outputs.git-release-tag !=
steps.poetry_version.outputs.poetry-version }}

- name: Build the release
run: poetry build

- name: Store the built package
uses: actions/upload-artifact@v4
with:
Expand All @@ -58,16 +75,21 @@ jobs:
if: ${{ github.event.action == 'prereleased' }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4

- uses: actions/setup-python@v6
with:
python-version: '3.9'
- uses: Gr1N/setup-poetry@v8
python-version: '3.13'

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1

- name: Retrieve the built package
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Publish to pypi
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
Expand All @@ -80,11 +102,15 @@ jobs:
if: ${{ github.event.action == 'released' }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4

- uses: actions/setup-python@v6
with:
python-version: '3.9'
- uses: Gr1N/setup-poetry@v8
python-version: '3.13'

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1

- name: Retrieve the built package
uses: actions/download-artifact@v4
with:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/goth-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ jobs:
run: sudo apt-get install -y libffi-dev build-essential

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure python
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: '3.9'
python-version: '3.13'

- name: Install and configure Poetry
run: python -m pip install -U pip setuptools poetry==1.3.2
run: python -m pip install -U pip setuptools poetry==2.2.1

- name: Install dependencies
run: |
poetry env use python3.9
poetry env use python3.13
poetry install

- name: Disconnect Docker containers from default network
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/goth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
uses: actions/checkout@v4

- name: Configure python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: '3.10'
python-version: '3.13'

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 1.8.2
run: curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1

- name: Install dependencies
run: |
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
os:
- ubuntu-latest
- macos-latest
- windows-latest
exclude:
- os: windows-latest
python-version: "3.10"
- os: macos-latest
python-version: "3.10"
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4

- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v8

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1

- run: echo "ENABLE=1" >> $GITHUB_OUTPUT
if: ${{ matrix.os == 'ubuntu-latest' }}
name: Enable extended checks
id: extended-checks
- run: echo "ENABLE=1" >> $GITHUB_OUTPUT
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' }}
if: ${{ matrix.os == 'ubuntu-latest' }}
name: Enable sphinx check
id: extended-checks-sphinx

Expand All @@ -52,7 +48,5 @@ jobs:
- run: poetry run poe checks_codestyle
- run: poetry run poe checks_typing
if: ${{ steps.extended-checks.outputs.ENABLE }}
- run: poetry run poe checks_license
if: ${{ steps.extended-checks.outputs.ENABLE }}
- run: poetry run poe sphinx -W
if: ${{ steps.extended-checks-sphinx.outputs.ENABLE }}
114 changes: 114 additions & 0 deletions examples/http-auth/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""Utilities for yapapi example scripts."""

import argparse
import asyncio
import tempfile
from datetime import datetime, timezone
from pathlib import Path

import colorama # type: ignore

from yapapi import (
Golem,
NoPaymentAccountError,
)
from yapapi import __version__ as yapapi_version
from yapapi import (
windows_event_loop_fix,
)
from yapapi.log import enable_default_logger

TEXT_COLOR_RED = "\033[31;1m"
TEXT_COLOR_GREEN = "\033[32;1m"
TEXT_COLOR_YELLOW = "\033[33;1m"
TEXT_COLOR_BLUE = "\033[34;1m"
TEXT_COLOR_MAGENTA = "\033[35;1m"
TEXT_COLOR_CYAN = "\033[36;1m"
TEXT_COLOR_WHITE = "\033[37;1m"

TEXT_COLOR_DEFAULT = "\033[0m"

colorama.init()


def build_parser(description: str) -> argparse.ArgumentParser:
current_time_str = datetime.now(tz=timezone.utc).strftime("%Y%m%d_%H%M%S%z")
default_log_path = Path(tempfile.gettempdir()) / f"yapapi_{current_time_str}.log"

parser = argparse.ArgumentParser(description=description)
parser.add_argument(
"--payment-driver", "--driver", help="Payment driver name, for example `erc20`"
)
parser.add_argument(
"--payment-network", "--network", help="Payment network name, for example `rinkeby`"
)
parser.add_argument("--subnet-tag", help="Subnet name, for example `devnet-beta`")
parser.add_argument(
"--log-file",
default=str(default_log_path),
help="Log file for YAPAPI; default: %(default)s",
)
return parser


def format_usage(usage):
return {
"current_usage": usage.current_usage,
"timestamp": usage.timestamp.isoformat(sep=" ") if usage.timestamp else None,
}


def print_env_info(golem: Golem):
print(
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n"
f"Using subnet: {TEXT_COLOR_YELLOW}{golem.subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)


def run_golem_example(example_main, log_file=None):
# This is only required when running on Windows with Python prior to 3.8:
windows_event_loop_fix()

if log_file:
enable_default_logger(
log_file=log_file,
debug_activity_api=True,
debug_market_api=True,
debug_payment_api=True,
debug_net_api=True,
)

loop = asyncio.get_event_loop()
task = loop.create_task(example_main)

try:
loop.run_until_complete(task)
except NoPaymentAccountError as e:
handbook_url = (
"https://handbook.golem.network/requestor-tutorials/"
"flash-tutorial-of-requestor-development"
)
print(
f"{TEXT_COLOR_RED}"
f"No payment account initialized for driver `{e.required_driver}` "
f"and network `{e.required_network}`.\n\n"
f"See {handbook_url} on how to initialize payment accounts for a requestor node."
f"{TEXT_COLOR_DEFAULT}"
)
except KeyboardInterrupt:
print(
f"{TEXT_COLOR_YELLOW}"
"Shutting down gracefully, please wait a short while "
"or press Ctrl+C to exit immediately..."
f"{TEXT_COLOR_DEFAULT}"
)
task.cancel()
try:
loop.run_until_complete(task)
print(
f"{TEXT_COLOR_YELLOW}Shutdown completed, thank you for waiting!{TEXT_COLOR_DEFAULT}"
)
except (asyncio.CancelledError, KeyboardInterrupt):
pass
Loading
Loading