Skip to content

Commit

Permalink
Run pre-commit all linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajastro committed Jun 17, 2024
1 parent 922c2eb commit 6344c4b
Show file tree
Hide file tree
Showing 27 changed files with 695 additions and 641 deletions.
2 changes: 1 addition & 1 deletion .astro-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ operators:

triggers:
- module: anyscale_provider.triggers.anyscale.AnyscaleJobTrigger
- module: anyscale_provider.triggers.anyscale.AnyscaleServiceTrigger
- module: anyscale_provider.triggers.anyscale.AnyscaleServiceTrigger
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[run]
omit =
tests/*
tests/*
10 changes: 4 additions & 6 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ jobs:
steps:
- run: true

Type-Check:
Static-Check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.11"
architecture: "x64"

- run: pip3 install hatch
- run: hatch run tests.py3.9-2.7:type-check
- run: hatch run tests.py3.9-2.7:static-check

Run-Unit-Tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -133,4 +131,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-integration-test-${{ matrix.python-version }}-${{ matrix.airflow-version }}
path: .coverage
path: .coverage
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ repos:
name: Run codespell to check for common misspellings in files
language: python
types: [text]
args: ["--ignore-words", codespell-ignore-words.txt]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
Expand Down Expand Up @@ -88,4 +89,4 @@ ci:
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
skip:
- mypy # build of https://github.com/pre-commit/mirrors-mypy:types-PyYAML,types-attrs,attrs,types-requests,
#types-python-dateutil,apache-airflow@v1.5.0 for python@python3 exceeds tier max size 250MiB: 262.6MiB
#types-python-dateutil,apache-airflow@v1.5.0 for python@python3 exceeds tier max size 250MiB: 262.6MiB
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ CHANGELOG
- .. code-block:: python

from anyscale_provider.triggers.anyscale import AnyscaleServiceTrigger
- N/A
- N/A
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @venkatajagannath
* @venkatajagannath
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ All tests are inside ``./tests`` directory.
- Just run ``pytest filepath+filename`` to run the tests.


For more information, please see the contributing guide available `here <https://github.com/astronomer/astro-provider-anyscale/blob/main/CONTRIBUTING.rst>`_
For more information, please see the contributing guide available `here <https://github.com/astronomer/astro-provider-anyscale/blob/main/CONTRIBUTING.rst>`_
71 changes: 36 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@ from pathlib import Path
from anyscale_provider.operators.anyscale import SubmitAnyscaleJob

default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2024, 4, 2),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
"owner": "airflow",
"depends_on_past": False,
"start_date": datetime(2024, 4, 2),
"email_on_failure": False,
"email_on_retry": False,
"retries": 1,
"retry_delay": timedelta(minutes=5),
}

# Define the Anyscale connection
ANYSCALE_CONN_ID = "anyscale_conn"

# Constants
FOLDER_PATH = Path(__file__).parent /"ray_scripts"
FOLDER_PATH = Path(__file__).parent / "ray_scripts"

dag = DAG(
'sample_anyscale_workflow',
"sample_anyscale_workflow",
default_args=default_args,
description='A DAG to interact with Anyscale triggered manually',
description="A DAG to interact with Anyscale triggered manually",
schedule_interval=None, # This DAG is not scheduled, only triggered manually
catchup=False,
)

submit_anyscale_job = SubmitAnyscaleJob(
task_id='submit_anyscale_job',
conn_id = ANYSCALE_CONN_ID,
name = 'AstroJob',
image_uri = 'anyscale/ray:2.23.0-py311',
compute_config = 'my-compute-config:1',
working_dir = str(FOLDER_PATH),
entrypoint= 'python script.py',
requirements = ["requests","pandas","numpy","torch"],
max_retries = 1,
task_id="submit_anyscale_job",
conn_id=ANYSCALE_CONN_ID,
name="AstroJob",
image_uri="anyscale/ray:2.23.0-py311",
compute_config="my-compute-config:1",
working_dir=str(FOLDER_PATH),
entrypoint="python script.py",
requirements=["requests", "pandas", "numpy", "torch"],
max_retries=1,
dag=dag,
)

Expand All @@ -96,22 +96,22 @@ from anyscale_provider.operators.anyscale import RolloutAnyscaleService
from anyscale_provider.hooks.anyscale import AnyscaleHook

default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2024, 4, 2),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
"owner": "airflow",
"depends_on_past": False,
"start_date": datetime(2024, 4, 2),
"email_on_failure": False,
"email_on_retry": False,
"retries": 1,
"retry_delay": timedelta(minutes=5),
}

# Define the Anyscale connection
ANYSCALE_CONN_ID = "anyscale_conn"

dag = DAG(
'sample_anyscale_service_workflow',
"sample_anyscale_service_workflow",
default_args=default_args,
description='A DAG to interact with Anyscale triggered manually',
description="A DAG to interact with Anyscale triggered manually",
schedule_interval=None, # This DAG is not scheduled, only triggered manually
catchup=False,
)
Expand All @@ -120,24 +120,25 @@ deploy_anyscale_service = RolloutAnyscaleService(
task_id="rollout_anyscale_service",
conn_id=ANYSCALE_CONN_ID,
name="AstroService",
image_uri='anyscale/ray:2.23.0-py311',
compute_config='my-compute-config:1',
image_uri="anyscale/ray:2.23.0-py311",
compute_config="my-compute-config:1",
working_dir="https://github.com/anyscale/docs_examples/archive/refs/heads/main.zip",
applications=[{"import_path": "sentiment_analysis.app:model"}],
requirements=["transformers", "requests", "pandas", "numpy", "torch"],
in_place=False,
canary_percent=None,
dag=dag
dag=dag,
)


def terminate_service():
hook = AnyscaleHook(conn_id=ANYSCALE_CONN_ID)
result = hook.terminate_service(service_id="AstroService",
time_delay=5)
result = hook.terminate_service(service_id="AstroService", time_delay=5)
print(result)


terminate_anyscale_service = PythonOperator(
task_id='initialize_anyscale_hook',
task_id="initialize_anyscale_hook",
python_callable=terminate_service,
dag=dag,
)
Expand All @@ -159,4 +160,4 @@ __________________

All contributions, bug reports, bug fixes, documentation improvements, enhancements are welcome.

A detailed overview an how to contribute can be found in the [Contributing Guide](https://github.com/astronomer/astro-provider-anyscale/blob/main/CONTRIBUTING.rst)
A detailed overview an how to contribute can be found in the [Contributing Guide](https://github.com/astronomer/astro-provider-anyscale/blob/main/CONTRIBUTING.rst)
7 changes: 4 additions & 3 deletions anyscale_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
__version__ = "1.0.0"

from typing import Any, Dict, Optional
from typing import Any, Dict

def get_provider_info() -> Dict[str,Any]:

def get_provider_info() -> Dict[str, Any]:
return {
"package-name": "astro-provider-anyscale", # Required
"name": "Anyscale", # Required
Expand All @@ -11,4 +12,4 @@ def get_provider_info() -> Dict[str,Any]:
{"connection-type": "anyscale", "hook-class-name": "anyscale_provider.hooks.anyscale.AnyscaleHook"}
],
"versions": [__version__], # Required
}
}
39 changes: 18 additions & 21 deletions anyscale_provider/hooks/anyscale.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import os
import time
import logging
from typing import Any, Dict, Optional

import anyscale
from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook # Adjusted import based on Airflow's newer version
from anyscale import Anyscale
from anyscale.job.models import JobConfig, JobStatus
from anyscale.service.models import ServiceConfig, ServiceStatus, ServiceState
from anyscale.service.models import ServiceConfig, ServiceStatus

from airflow.hooks.base import BaseHook # Adjusted import based on Airflow's newer version
from airflow.exceptions import AirflowException
from airflow.compat.functools import cached_property
from anyscale.sdk.anyscale_client.models import *

class AnyscaleHook(BaseHook):
"""
Expand Down Expand Up @@ -116,13 +112,12 @@ def __init__(self, conn_id: str = default_conn_name, **kwargs: Any) -> None:
# If the token is not found in the connection, try to get it from the environment variable
if not token:
token = os.getenv("ANYSCALE_CLI_TOKEN")

if not token:
raise AirflowException(f"Missing API token for connection id {self.conn_id}")

self.sdk = Anyscale(auth_token=token)


@classmethod
def get_ui_field_behaviour(cls) -> Dict[str, Any]:
"""Return custom field behaviour for the connection form in the UI."""
Expand All @@ -133,23 +128,25 @@ def get_ui_field_behaviour(cls) -> Dict[str, Any]:
}

def submit_job(self, config: JobConfig) -> str:
self.log.info("Creating a job with configuration: {}".format(config))
self.log.info(f"Creating a job with configuration: {config}")
job_id: str = self.sdk.job.submit(config=config)
return job_id

def deploy_service(self, config: ServiceConfig,
in_place: bool = False,
canary_percent: Optional[float] = None,
max_surge_percent: Optional[float] = None) -> str:
self.log.info("Deploying a service with configuration: {}".format(config))
service_id: str = self.sdk.service.deploy(config=config,
in_place=in_place,
canary_percent=canary_percent,
max_surge_percent=max_surge_percent)
def deploy_service(
self,
config: ServiceConfig,
in_place: bool = False,
canary_percent: Optional[float] = None,
max_surge_percent: Optional[float] = None,
) -> str:
self.log.info(f"Deploying a service with configuration: {config}")
service_id: str = self.sdk.service.deploy(
config=config, in_place=in_place, canary_percent=canary_percent, max_surge_percent=max_surge_percent
)
return service_id

def get_job_status(self, job_id: str) -> JobStatus:
self.log.info("Fetching job status for Job name: {}".format(job_id))
self.log.info(f"Fetching job status for Job name: {job_id}")
return self.sdk.job.status(job_id=job_id)

def get_service_status(self, service_name: str) -> ServiceStatus:
Expand Down Expand Up @@ -177,4 +174,4 @@ def terminate_service(self, service_id: str, time_delay: int) -> bool:

def get_logs(self, job_id: str) -> str:
logs: str = self.sdk.job.get_logs(job_id=job_id)
return logs
return logs
Loading

0 comments on commit 6344c4b

Please sign in to comment.