Skip to content

Commit

Permalink
Merge pull request #103 from golemfactory/big-5-draft
Browse files Browse the repository at this point in the history
Added managers layer
Refactored modules structure
Refactored event bus
Added props and const parsing
  • Loading branch information
lucekdudek authored Jul 28, 2023
2 parents 650a945 + 9a11a77 commit 892db24
Show file tree
Hide file tree
Showing 202 changed files with 6,146 additions and 1,971 deletions.
5 changes: 2 additions & 3 deletions .github/actions/integration-tests-goth/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ runs:
with:
python-version: ${{ inputs.PYTHON_VERSION }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.1
shell: bash
run: python -m pip install -U pip setuptools poetry==1.5.1

- name: Install dependencies
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ build/
.envs/

# licheck artifacts
.requrements.txt
.requirements.txt
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ $ poetry run python examples/rate_providers/rate_providers.py
## CLI

```bash
$ python -m golem_core status
$ python -m golem status

$ python -m golem_core find-node --runtime vm
$ python -m golem_core find-node --runtime vm --subnet public-beta
$ python -m golem_core find-node --runtime vm --timeout 7 # stops after 7 seconds
$ python -m golem_core find-node --runtime vm --timeout 1m # stops after 60 seconds
$ python -m golem find-node --runtime vm
$ python -m golem find-node --runtime vm --subnet public-beta
$ python -m golem find-node --runtime vm --timeout 7 # stops after 7 seconds
$ python -m golem find-node --runtime vm --timeout 1m # stops after 60 seconds

$ python -m golem_core allocation list
$ python -m golem allocation list

$ python -m golem_core allocation new 1
$ python -m golem_core allocation new 2 --driver erc20 --network rinkeby
$ python -m golem allocation new 1
$ python -m golem allocation new 2 --driver erc20 --network goerli

$ python -m golem_core allocation clean
$ python -m golem allocation clean
```

## Docs
Expand Down
90 changes: 39 additions & 51 deletions docs/sphinx/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Golem Python Core API Reference
GolemNode
=========

.. autoclass:: golem_core.core.golem_node.GolemNode
.. autoclass:: golem.node.GolemNode
:members: __init__, __aenter__, __aexit__,
create_allocation, create_demand, create_network,
allocation, debit_note, invoice,
Expand All @@ -19,7 +19,7 @@ GolemNode
.. High-Level API
.. ==============
.. .. autofunction:: golem_core.high.execute_tasks.execute_tasks
.. .. autofunction:: golem.high.execute_tasks.execute_tasks
Mid-level API
=============
Expand All @@ -33,26 +33,26 @@ General components
Classes in this section know nothing about any Golem-specific logic. They should one day be extracted to a sparate library.


.. autoclass:: golem_core.pipeline.Sort
.. autoclass:: golem.pipeline.Sort
:members: __init__, __call__
.. autoclass:: golem_core.pipeline.Chain
.. autoclass:: golem_core.pipeline.Map
.. autoclass:: golem.pipeline.Chain
.. autoclass:: golem.pipeline.Map
:members: __init__, __call__
.. autoclass:: golem_core.pipeline.Zip
.. autoclass:: golem_core.pipeline.Buffer
.. autoclass:: golem.pipeline.Zip
.. autoclass:: golem.pipeline.Buffer
:members: __init__, __call__
.. autoclass:: golem_core.pipeline.Limit
.. autoclass:: golem.pipeline.Limit
:members: __init__


Golem-specific components
------------------------------
Components in this section contain the common logic that is shared by various Golem applications.

.. autofunction:: golem_core.core.market_api.default_negotiate
.. autofunction:: golem_core.core.market_api.default_create_agreement
.. autofunction:: golem_core.core.market_api.default_create_activity
.. autofunction:: golem_core.core.activity_api.default_prepare_activity
.. autofunction:: golem.resources.default_negotiate
.. autofunction:: golem.resources.default_create_agreement
.. autofunction:: golem.resources.default_create_activity
.. autofunction:: golem.resources.default_prepare_activity


Low-level API
Expand All @@ -67,7 +67,7 @@ by performing operations on the low-level objects.
Resource
--------

.. autoclass:: golem_core.core.resources.Resource
.. autoclass:: golem.resources.Resource
:members: id, node,
get_data, data,
parent, children, child_aiter,
Expand All @@ -76,103 +76,91 @@ Resource
Market API
----------

.. autoclass:: golem_core.core.market_api.Demand
.. autoclass:: golem.resources.Demand
:members: initial_proposals, unsubscribe, proposal

.. autoclass:: golem_core.core.market_api.Proposal
.. autoclass:: golem.resources.Proposal
:members: initial, draft, rejected, demand,
respond, responses, reject, create_agreement

.. autoclass:: golem_core.core.market_api.Agreement
.. autoclass:: golem.resources.Agreement
:members: confirm, wait_for_approval, terminate, create_activity,
invoice, activities, close_all

Payment API
-----------

.. autoclass:: golem_core.core.payment_api.Allocation
.. autoclass:: golem.resources.Allocation
:members: release

.. autoclass:: golem_core.core.payment_api.DebitNote
.. autoclass:: golem.resources.DebitNote
:members: accept_full

.. autoclass:: golem_core.core.payment_api.Invoice
.. autoclass:: golem.resources.Invoice
:members: accept_full

Activity API
------------

.. autoclass:: golem_core.core.activity_api.Activity
.. autoclass:: golem.resources.Activity
:members: execute_commands, execute_script, destroy,
idle, destroyed, wait_busy, wait_idle, wait_destroyed,
debit_notes, batch

.. autoclass:: golem_core.core.activity_api.PoolingBatch
.. autoclass:: golem.resources.PoolingBatch
:members: wait, events, done, success

.. autoclass:: golem_core.core.activity_api.Script
.. autoclass:: golem.resources.Script
:members: add_command

Network API
-----------

.. autoclass:: golem_core.core.network_api.Network
.. autoclass:: golem.resources.Network
:members: create_node, deploy_args, refresh_nodes, remove

Commands
--------

.. autoclass:: golem_core.core.activity_api.commands.Command
.. autoclass:: golem_core.core.activity_api.commands.Deploy
.. autoclass:: golem_core.core.activity_api.commands.Start
.. autoclass:: golem_core.core.activity_api.commands.Run
.. autoclass:: golem.resources.Command
.. autoclass:: golem.resources.Deploy
.. autoclass:: golem.resources.Start
.. autoclass:: golem.resources.Run
:members: __init__
.. autoclass:: golem_core.core.activity_api.commands.SendFile
.. autoclass:: golem.resources.SendFile
:members: __init__
.. autoclass:: golem_core.core.activity_api.commands.DownloadFile
.. autoclass:: golem.resources.DownloadFile
:members: __init__

Exceptions
----------

.. autoclass:: golem_core.core.resources.ResourceNotFound
.. autoclass:: golem.resources.ResourceNotFound
:members: resource
.. autoclass:: golem_core.core.payment_api.NoMatchingAccount
.. autoclass:: golem.resources.NoMatchingAccount
:members: network, driver
.. autoclass:: golem_core.core.activity_api.BatchTimeoutError
.. autoclass:: golem.resources.BatchTimeoutError
:members: batch, timeout
.. autoclass:: golem_core.core.activity_api.BatchError
.. autoclass:: golem.resources.BatchError
:members: batch
.. autoclass:: golem_core.core.activity_api.CommandFailed
.. autoclass:: golem.resources.CommandFailed
:members: batch
.. autoclass:: golem_core.core.activity_api.CommandCancelled
.. autoclass:: golem.resources.CommandCancelled
:members: batch
.. autoclass:: golem_core.core.network_api.NetworkFull
.. autoclass:: golem.resources.NetworkFull
:members: network

Events
======

.. autoclass:: golem_core.core.events.EventBus
:members: listen, resource_listen, emit

.. automodule:: golem_core.core.events.event
:members:

.. automodule:: golem_core.core.activity_api.events
.. automodule:: golem.event_bus.base
:members:

.. automodule:: golem_core.core.resources.events
.. automodule:: golem.resources.events
:members:

Logging
=======

.. autoclass:: golem_core.utils.logging.DefaultLogger
.. autoclass:: golem.utils.logging.DefaultLogger
:members: __init__, file_name, logger, on_event

Managers
========

.. autoclass:: golem_core.managers.DefaultPaymentManager
:members: __init__, terminate_agreements, wait_for_invoices
12 changes: 6 additions & 6 deletions examples/attach.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import asyncio
import sys

from golem_core.core.activity_api import commands
from golem_core.core.golem_node import GolemNode
from golem_core.core.payment_api import DebitNote
from golem_core.core.resources import NewResource
from golem.node import GolemNode
from golem.resources import DebitNote, NewResource
from golem.resources.activity import commands
from golem.resources.debit_note.events import NewDebitNote

ACTIVITY_ID = sys.argv[1].strip()


async def accept_debit_note(payment_event: NewResource) -> None:
debit_note: DebitNote = payment_event.resource # type: ignore
debit_note: DebitNote = payment_event.resource

this_activity_id = (await debit_note.get_data()).activity_id
if this_activity_id == ACTIVITY_ID:
Expand All @@ -22,7 +22,7 @@ async def accept_debit_note(payment_event: NewResource) -> None:

async def main() -> None:
golem = GolemNode()
golem.event_bus.resource_listen(accept_debit_note, [NewResource], [DebitNote])
await golem.event_bus.on(NewDebitNote, accept_debit_note)

async with golem:
activity = golem.activity(ACTIVITY_ID)
Expand Down
16 changes: 8 additions & 8 deletions examples/cli_example.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env bash

printf "*** STATUS ***\n"
python3 -m golem_core status
python3 -m golem status

printf "\n*** FIND-NODE ***\n"
python3 -m golem_core find-node --runtime vm --timeout 1
python3 -m golem find-node --runtime vm --timeout 1

printf "\n*** ALLOCATION LIST ***\n"
python3 -m golem_core allocation list
python3 -m golem allocation list

printf "\n*** ALLOCATION NEW ***\n"
python3 -m golem_core allocation new 1
python3 -m golem allocation new 1

printf "\n*** ALLOCATION NEW ***\n"
python3 -m golem_core allocation new 2 --driver erc20 --network rinkeby
python3 -m golem allocation new 2 --driver erc20 --network goerli

printf "\n*** ALLOCATION LIST ***\n"
python3 -m golem_core allocation list
python3 -m golem allocation list

printf "\n*** ALLOCATION CLEAN ***\n"
python3 -m golem_core allocation clean
python3 -m golem allocation clean

printf "\n*** ALLOCATION LIST ***\n"
python3 -m golem_core allocation list
python3 -m golem allocation list
16 changes: 9 additions & 7 deletions examples/core_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
from tempfile import TemporaryDirectory
from typing import AsyncGenerator, Optional

from golem_core.core.activity_api import (
from golem.node import GolemNode
from golem.payload import RepositoryVmPayload
from golem.resources import (
Activity,
BatchError,
CommandCancelled,
CommandFailed,
NewResource,
ResourceClosed,
ResourceEvent,
Script,
commands,
)
from golem_core.core.golem_node import GolemNode
from golem_core.core.market_api import RepositoryVmPayload
from golem_core.core.resources import NewResource, ResourceClosed, ResourceEvent
from golem.resources.activity import commands

PAYLOAD = RepositoryVmPayload("9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae")

Expand Down Expand Up @@ -116,10 +118,10 @@ async def example_5() -> None:
golem = GolemNode()
got_events = []

async def on_event(event: ResourceEvent) -> None:
async def collect_resource_events(event: ResourceEvent) -> None:
got_events.append(event)

golem.event_bus.resource_listen(on_event)
await golem.event_bus.on(ResourceEvent, collect_resource_events)
async with golem:
allocation = await golem.create_allocation(1)

Expand Down
9 changes: 5 additions & 4 deletions examples/detached_activity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio

from golem_core.core.activity_api import Activity, commands
from golem_core.core.golem_node import GolemNode
from golem_core.core.market_api import Agreement, Proposal, RepositoryVmPayload, default_negotiate
from golem_core.pipeline import Chain, Map
from golem.node import GolemNode
from golem.payload import RepositoryVmPayload
from golem.pipeline import Chain, Map
from golem.resources import Activity, Agreement, Proposal, default_negotiate
from golem.resources.activity import commands

PAYLOAD = RepositoryVmPayload("9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae")

Expand Down
Loading

0 comments on commit 892db24

Please sign in to comment.