Skip to content

Commit

Permalink
Merge pull request #100 from golemfactory/blue/pydantic
Browse files Browse the repository at this point in the history
Port `dapp-runner` to `pydantic`
  • Loading branch information
shadeofblue authored Mar 23, 2023
2 parents a8c5b20 + 3df6a63 commit e0181d2
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 292 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/goth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ jobs:
with:
python-version: '3.8'

- name: Configure poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: 1.2.2
- name: Install and configure Poetry
run: python -m pip install -U pip setuptools poetry==1.3.2

- name: Install dependencies
run: |
poetry env use python3.8
poetry install -vvv --with tests_integration
poetry install -vvv
- name: Disconnect Docker containers from default network
continue-on-error: true
Expand All @@ -56,12 +54,13 @@ jobs:
- name: Log in to GitHub Docker repository
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{github.actor}} --password-stdin

- name: Initialize the test suite
run: poetry run poe tests_integration_init

- name: Run test suite
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry run poe tests_integration_assets
poetry run poe tests_integration
run: poetry run poe tests_integration

- name: Upload test logs
uses: actions/upload-artifact@v2
Expand All @@ -79,6 +78,6 @@ jobs:
- name: Remove poetry virtual env
if: always()
# Python version below should agree with the version set up by this job.
# In future we'll be able to use the `--all` flag here to remove envs for
# In the future we'll be able to use the `--all` flag here to remove envs for
# all Python versions (https://github.com/python-poetry/poetry/issues/3208).
run: poetry env remove python3.8
2 changes: 1 addition & 1 deletion dapp_runner/descriptor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .base import DescriptorError
from .config import Config
from .dapp import DappDescriptor
from .error import DescriptorError

__all__ = (
"DappDescriptor",
Expand Down
120 changes: 0 additions & 120 deletions dapp_runner/descriptor/base.py

This file was deleted.

48 changes: 28 additions & 20 deletions dapp_runner/descriptor/config.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,63 @@
"""Class definitions for the Dapp Runner's configuration descriptor."""
import os
from dataclasses import dataclass, field
from typing import Optional

from .base import BaseDescriptor
from pydantic import BaseModel, Field, validator


@dataclass
class YagnaConfig(BaseDescriptor["YagnaConfig"]):
class YagnaConfig(BaseModel):
"""Yagna daemon configuration properties.
Properties describing the local requestor daemon configuration that
the Dapp Runner will use to run services on Golem.
"""

def __app_key__factory(value: str): # type: ignore [misc] # noqa
subnet_tag: Optional[str]
api_url: Optional[str] = None
gsb_url: Optional[str] = None
app_key: Optional[str] = None

class Config: # noqa: D106
extra = "forbid"

@validator("app_key", always=True)
def __app_key__extrapolate(cls, v):
# TODO this should be applied uniformly across any fields,
# for now, making an exception for the app key

if value and value.startswith("$"):
return os.environ[value[1:]]

return value
if v and v.startswith("$"):
return os.environ[v[1:]]

subnet_tag: Optional[str]
api_url: Optional[str] = None
gsb_url: Optional[str] = None
app_key: Optional[str] = field(metadata={"factory": __app_key__factory}, default=None)
return v


@dataclass
class PaymentConfig:
class PaymentConfig(BaseModel):
"""Requestor's payment config."""

budget: float
driver: str
network: str

class Config: # noqa: D106
extra = "forbid"

@dataclass
class LimitsConfig:

class LimitsConfig(BaseModel):
"""Limits of the running app."""

startup_timeout: Optional[int] = None # seconds
max_running_time: Optional[int] = None # seconds

class Config: # noqa: D106
extra = "forbid"


@dataclass
class Config(BaseDescriptor["Config"]):
class Config(BaseModel):
"""Root configuration descriptor for the Dapp Runner."""

yagna: YagnaConfig
payment: PaymentConfig
limits: LimitsConfig = field(default_factory=LimitsConfig)
limits: LimitsConfig = Field(default_factory=LimitsConfig)

class Config: # noqa: D106
extra = "forbid"
Loading

0 comments on commit e0181d2

Please sign in to comment.