Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified task runner scripts #1086

Merged
merged 20 commits into from
Mar 7, 2023
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/build_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
with:
poetry-version: 1.2.2
- run: poetry install
- run: poetry run poe test
- run: poetry run poe typecheck
- run: poetry run poe codestyle
- run: poetry run poe liccheck
- run: poetry run poe tests_unit
- run: poetry run poe checks_codestyle
- run: poetry run poe checks_typing
- run: poetry run poe checks_license

build:
needs: [test]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/goth-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ jobs:
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry run poe goth-assets
poetry run poe goth-tests
poetry run poe tests_integration_assets
poetry run poe tests_integration

- name: Upload test logs
uses: actions/upload-artifact@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/goth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry run poe goth-assets
poetry run poe goth-tests
poetry run poe tests_integration_assets
poetry run poe tests_integration

- name: Upload test logs
uses: actions/upload-artifact@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ jobs:
- run: poetry install -E docs
if: ${{ steps.extended-checks-sphinx.outputs.ENABLE }}

- run: poetry run poe test
- run: poetry run poe typecheck
- run: poetry run poe codestyle
- run: poetry run poe tests_unit
- run: poetry run poe checks_codestyle
- run: poetry run poe checks_typing
if: ${{ steps.extended-checks.outputs.ENABLE }}
- run: poetry run poe liccheck
- 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 }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/
*.log
*.png
.coverage
.requirements.txt
requirements.txt

tests/goth_tests/assets/

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ All of the project's dependencies will be installed to that virtual environment.
Declarations of project tasks can be found in `pyproject.toml`.

```bash
poetry run poe test
poetry run poe tests_unit
```

### Running `goth` integration tests
Expand Down Expand Up @@ -96,23 +96,23 @@ poetry install -E integration-tests
Finally, generate goth's default assets:

```bash
poetry run poe goth-assets
poetry run poe tests_integration_assets
```

#### Running the tests

Once you have the environment set up, to run all the integration tests, use:

```bash
poetry run poe goth-tests
poetry run poe tests_integration
```

### Contributing

It is recommended to run unit tests and static code analysis before committing changes.

```bash
poetry run poe check
poetry run poe checks
```

You can clean up the artifacts created during the test runs with:
Expand Down
3 changes: 2 additions & 1 deletion docs/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
import os
import sys
from typing import List

sys.path.insert(0, os.path.abspath("../../"))

Expand Down Expand Up @@ -56,7 +57,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
html_static_path: List[str] = []

# This removes the `yapapi.log` docstrings.
# There are two reasons:
Expand Down
5 changes: 3 additions & 2 deletions examples/blender/blender.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from datetime import datetime, timedelta
import pathlib
import sys
from datetime import datetime, timedelta

from yapapi import Golem, Task, WorkContext
from yapapi.payload import vm
Expand Down Expand Up @@ -31,7 +31,8 @@ async def main(
min_mem_gib=0.5,
# only run on provider nodes that have more than 2gb of storage space available
min_storage_gib=2.0,
# only run on provider nodes which a certain number of CPU threads (logical CPU cores) available
# only run on provider nodes which a certain number of CPU threads (logical CPU cores)
# available
min_cpu_threads=min_cpu_threads,
)

Expand Down
8 changes: 4 additions & 4 deletions examples/blender/start_stop_blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

"""Other version of the blender example.

Instead of using Golem in the default way - as a context manager - we directly call `Golem.start()` and `Golem.stop()`.
This way of using Golem might be more convenient for some specific use cases (although doesn't change a lot
in the blender example).
Instead of using Golem in the default way - as a context manager - we directly call `Golem.start()`
and `Golem.stop()`. This way of using Golem might be more convenient for some specific use cases
(although doesn't change a lot in the blender example).
"""

from datetime import datetime, timedelta
import pathlib
import sys
from datetime import datetime, timedelta

from yapapi import Golem, Task, WorkContext
from yapapi.payload import vm
Expand Down
9 changes: 6 additions & 3 deletions examples/custom-usage-counter/custom_usage_counter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
import asyncio
from dataclasses import dataclass
from datetime import datetime, timedelta
from decimal import Decimal
import pathlib
import sys
from datetime import datetime, timedelta
from decimal import Decimal

from dataclasses import dataclass

from yapapi import Golem
from yapapi.ctx import ActivityUsage
Expand Down Expand Up @@ -101,6 +102,8 @@ def print_instances():
type=int,
help="How long should the the service run (in seconds, default: %(default)s)",
)
now = datetime.now().strftime("%Y-%m-%d_%H.%M.%S")
parser.set_defaults(log_file=f"custom-counters-yapapi-{now}.log")
args = parser.parse_args()
enable_default_logger(
log_file=args.log_file,
Expand Down
1 change: 1 addition & 0 deletions examples/custom_runtime/custom_runtime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio

from dataclasses import dataclass

from yapapi import Golem
Expand Down
4 changes: 2 additions & 2 deletions examples/external-api-request/external_api_request.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
import asyncio
import base64
from datetime import datetime
import pathlib
import sys
from datetime import datetime

from yapapi import Golem
from yapapi.payload import vm
Expand Down Expand Up @@ -46,7 +46,7 @@ async def run(self):
future_result = script.run(
"/bin/sh",
"-c",
f"GOLEM_PRICE=`curl -X 'GET' \
"GOLEM_PRICE=`curl -X 'GET' \
'https://api.coingecko.com/api/v3/simple/price?ids=golem&vs_currencies=usd' \
-H 'accept: application/json' | jq .golem.usd`; \
echo ---; \
Expand Down
9 changes: 4 additions & 5 deletions examples/http-proxy/http_proxy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
"""
a simple http proxy example
"""
"""A simple http proxy example."""
import asyncio
from datetime import datetime, timedelta, timezone
import pathlib
import shlex
import sys
from datetime import datetime, timedelta, timezone

from yapapi import Golem
from yapapi.contrib.service.http_proxy import HttpProxyService, LocalHttpProxy
Expand Down Expand Up @@ -123,7 +121,8 @@ def still_starting():
await proxy.run()

print(
f"{TEXT_COLOR_CYAN}Local HTTP server listening on:\nhttp://localhost:{port}{TEXT_COLOR_DEFAULT}"
f"{TEXT_COLOR_CYAN}Local HTTP server listening on:\n"
f"http://localhost:{port}{TEXT_COLOR_DEFAULT}"
)

# wait until Ctrl-C
Expand Down
4 changes: 2 additions & 2 deletions examples/low-level-api/list-offers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
import asyncio
from asyncio import TimeoutError
from datetime import datetime, timezone
import json
import pathlib
import sys
from asyncio import TimeoutError
from datetime import datetime, timezone

from yapapi import props as yp
from yapapi.config import ApiConfig
Expand Down
11 changes: 7 additions & 4 deletions examples/market-strategy/market_strategy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
from collections import defaultdict
import itertools
import pathlib
import sys
from collections import defaultdict

from yapapi import Golem, Task, WorkContext
from yapapi.payload import vm
Expand All @@ -21,11 +21,13 @@


class FastestProviderStrategy(MarketStrategy):
"""Strategy that ignores all offer parameters (including pricing) and just selects the fastest provider.
"""Strategy that ignores all offer parameters (including pricing) and just selects the fastest \
provider.

Decision algorithm:
* we always try any new provider
* if there are no new providers, we select the one with shortest average execution time in past runs
* if there are no new providers, we select the one with shortest average execution time in past
runs
"""

def __init__(self):
Expand All @@ -45,7 +47,8 @@ async def score_offer(self, offer):
# Non-draft offers are not shown to limit the number of lines printed
if previous_runs:
print(
f"Scored known provider: {provider_id}: {score} ({len(previous_runs)} runs, avg time {avg_time})"
f"Scored known provider: {provider_id}: "
f"{score} ({len(previous_runs)} runs, avg time {avg_time})"
)
else:
print(f"Found new provider: {provider_id}, default score {SCORE_TRUSTED}")
Expand Down
2 changes: 1 addition & 1 deletion examples/scan/scan.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
from datetime import datetime
import logging
import pathlib
import re
import sys
from datetime import datetime
from typing import List

from yapapi import Golem, Task, WorkContext
Expand Down
11 changes: 4 additions & 7 deletions examples/simple-service-poc/simple_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
"""
the requestor agent controlling and interacting with the "simple service"
"""
"""The requestor agent controlling and interacting with the "simple service"."""
import asyncio
from datetime import datetime, timedelta, timezone
import pathlib
import random
import string
import sys
from datetime import datetime, timedelta, timezone

from yapapi import Golem
from yapapi.payload import vm
Expand All @@ -20,7 +18,6 @@
TEXT_COLOR_CYAN,
TEXT_COLOR_DEFAULT,
TEXT_COLOR_MAGENTA,
TEXT_COLOR_RED,
TEXT_COLOR_YELLOW,
build_parser,
format_usage,
Expand Down Expand Up @@ -55,7 +52,7 @@ async def get_payload():
)

async def start(self):
"""handler responsible for starting the service."""
"""Handle starting the service."""

# perform the initialization of the Service
async for script in super().start():
Expand Down Expand Up @@ -148,7 +145,7 @@ async def main(

def print_instances():
print(
f"instances: "
"instances: "
+ str(
[
f"{s.name}: {s.state.value}"
Expand Down
15 changes: 8 additions & 7 deletions examples/simple-service-poc/simple_service/simple_service.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/usr/local/bin/python
"""
a very basic "stub" that exposes a few commands of an imagined, very simple CLI-based
service that is able to accumulate some linear, time-based values and present it stats
"""A very basic "stub" that exposes a few commands of an imagined, very simple CLI-based service.

The Service is able to accumulate some linear, time-based values and present it stats
(characteristics of the statistical distribution of the data collected so far) or provide
distribution and time-series plots of the collected data.

[ part of the VM image that's deployed by the runtime on the Provider's end. ]
"""
import argparse
import contextlib
from datetime import datetime
import enum
import json
import matplotlib.pyplot as plt
import numpy
from pathlib import Path
import random
import sqlite3
import string
from datetime import datetime
from pathlib import Path

import matplotlib.pyplot as plt
import numpy

DB_PATH = Path(__file__).absolute().parent / "service.db"
PLOT_PATH = Path("/golem/out").absolute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/local/bin/python
"""
the "hello world" service here just adds randomized numbers with normal distribution
"""The "hello world" service here just adds randomized numbers with normal distribution.

in a real-world example, this could be e.g. a thermometer connected to the provider's
machine providing its inputs into the database or some other piece of information
Expand All @@ -10,9 +9,9 @@
[ part of the VM image that's deployed by the runtime on the Provider's end. ]
"""
import os
from pathlib import Path
import random
import time
from pathlib import Path

MU = 14
SIGMA = 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/local/bin/python
"""
a helper, control script that starts and stops our example `simulate_observations` service
"""a helper, control script that starts and stops our example `simulate_observations` service.

[ part of the VM image that's deployed by the runtime on the Provider's end. ]
"""
Expand Down
Loading