Skip to content

Commit

Permalink
lint with black
Browse files Browse the repository at this point in the history
  • Loading branch information
ninthreezy committed Mar 18, 2022
1 parent 7a3e887 commit 2eee941
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 78 deletions.
8 changes: 4 additions & 4 deletions datatorch/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setup_logging() -> None:


async def _exit_jobs() -> None:
""" Exits active running agent jobs """
"""Exits active running agent jobs"""
logger.info(f"Exiting {len(tasks)} active jobs.")

for task in tasks:
Expand All @@ -77,7 +77,7 @@ async def _close_transport(transport: WebsocketsTransport):


async def _exit_tasks() -> None:
""" Exits all active asyncio tasks """
"""Exits all active asyncio tasks"""
current_task = asyncio.Task.current_task()
all_tasks = asyncio.Task.all_tasks()
not_current_tasks = [task for task in all_tasks if task is not current_task]
Expand All @@ -87,7 +87,7 @@ async def _exit_tasks() -> None:


async def start() -> None:
""" Creates and runs an agent. """
"""Creates and runs an agent."""
setup_logging()

click.echo(
Expand Down Expand Up @@ -131,7 +131,7 @@ async def start() -> None:


async def stop() -> None:
""" Stop all run tasks. """
"""Stop all run tasks."""

print(" ")

Expand Down
4 changes: 2 additions & 2 deletions datatorch/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _init_threads(self):
tasks.append(task)

async def process_loop(self):
""" Waits for jobs from server. """
"""Waits for jobs from server."""
logger.info("Waiting for jobs.")
async for job_request in self.api.agent_jobs():
loop = asyncio.get_event_loop()
Expand All @@ -55,7 +55,7 @@ async def process_loop(self):
tasks.append(task)

async def _run_job(self, job: AgentJobConfig):
""" Runs a job """
"""Runs a job"""
job_id = job.get("id")
job_name = job.get("name")
job_steps = job.get("steps")
Expand Down
4 changes: 2 additions & 2 deletions datatorch/agent/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, session: AsyncClientSession):
self.session = session

def agent_jobs(self):
""" Subscriptions to the agent job assignment namespace. """
"""Subscriptions to the agent job assignment namespace."""
# fmt: off
sub = gql("""
subscription {
Expand Down Expand Up @@ -220,7 +220,7 @@ def upload_step_logs(self, step_id: str, logs: List[Log]):
return self.execute(mutate, params={"id": step_id, "logs": logs})

async def execute(self, query, *args, params: dict = {}, **kwargs) -> dict:
""" Wrapper around execute """
"""Wrapper around execute"""
removed_none = dict((k, v) for k, v in params.items() if v is not None)
if type(query) == str:
query = gql(query)
Expand Down
12 changes: 6 additions & 6 deletions datatorch/agent/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class AgentDirectory(object):
@staticmethod
def path() -> str:
""" Returns the agents directory """
"""Returns the agents directory"""
path = folder.get_app_dir()
return os.getenv("DATATORCH_AGENT_PATH", os.path.join(path, "agent"))

Expand Down Expand Up @@ -36,12 +36,12 @@ def runs_dir(self):

@property
def logs_dir(self):
""" Directory where agent logs are stored. """
"""Directory where agent logs are stored."""
return os.path.join(self.dir, "logs")

@property
def db_dir(self):
""" Sqlite database are stored. """
"""Sqlite database are stored."""
return os.path.join(self.dir, "db")

@property
Expand All @@ -55,7 +55,7 @@ def projects_dir(self):

@property
def actions_dir(self):
""" Directory where actions are stored. """
"""Directory where actions are stored."""
return os.path.join(self.dir, "actions")

def open(self, file: str, mode: str):
Expand All @@ -65,13 +65,13 @@ def action_dir(self, name: str, version: str):
return os.path.join(self.actions_dir, *name.lower().split("/"), version)

def run_dir(self, task_id: str):
""" Returns the directory for a given task """
"""Returns the directory for a given task"""
path = os.path.join(self.runs_dir, task_id)
mkdir_exists(path)
return path

def project_dir(self, project_id: str):
""" Returns the directory for a given project """
"""Returns the directory for a given project"""
path = os.path.join(self.projects_dir, project_id)
mkdir_exists(path)
return path
Expand Down
2 changes: 1 addition & 1 deletion datatorch/agent/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def print_stats(metrics):
class AgentSystemStats(object):
@staticmethod
def initial_stats():
""" Returns stats that do not change over time. """
"""Returns stats that do not change over time."""
# initialize averaging
psutil.cpu_percent()
cpu_freq = psutil.cpu_freq()
Expand Down
2 changes: 1 addition & 1 deletion datatorch/agent/pipelines/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def update(self, status: str) -> None:
await self.agent.api.update_job(variables)

async def run(self, variables: Variables):
""" Runs each step of the job. """
"""Runs each step of the job."""
steps = Step.from_dict_list(self.config.get("steps", []), job=self)
await self.update("RUNNING")

Expand Down
4 changes: 2 additions & 2 deletions datatorch/agent/pipelines/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def from_yaml(cls, path, agent: "Agent" = None):

@classmethod
def from_config(cls, config: Union[str, dict], agent: "Agent" = None):
""" Creates a pipeline from a config file. """
"""Creates a pipeline from a config file."""
if isinstance(config, str):
cf = yaml.load(config, Loader=yaml.FullLoader)
else:
Expand All @@ -35,6 +35,6 @@ def __init__(self, config: dict, agent: "Agent" = None):
self.agent = agent

async def run(self, job_config: dict):
""" Runs a job. """
"""Runs a job."""
# await Job(job_config, agent=self.agent).run()
pass
2 changes: 1 addition & 1 deletion datatorch/agent/pipelines/runner/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RunnerCreateError(Exception):
class RunnerFactory(object):
@staticmethod
def create(action, config: dict) -> Runner:
""" Makes runners to 'use' strings found in config.yaml files. """
"""Makes runners to 'use' strings found in config.yaml files."""
use = config.get("using")
if use is None:
raise RunnerCreateError("Action 'use' property not specified.")
Expand Down
10 changes: 5 additions & 5 deletions datatorch/agent/pipelines/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ async def execute(self) -> Awaitable[dict]:
raise NotImplementedError("This method must be implemented.")

def action_dir(self):
""" Changes the current work directory to the actions directory. """
"""Changes the current work directory to the actions directory."""
os.chdir(self.action.dir)

async def monitor_cmd(self, command: str):
""" Excutes a command and monitors stdout for variables and logging. """
"""Excutes a command and monitors stdout for variables and logging."""
process = await self.run_cmd(command)

async for log in process.stdout:
Expand All @@ -48,11 +48,11 @@ async def monitor_cmd(self, command: str):
)

def get(self, key: str, default=None):
""" Gets a string from config and renders template. """
"""Gets a string from config and renders template."""
return self.variables.render(self.config.get(key, default))

def check_for_output(self, string: str) -> bool:
""" Parse output variable from string if valid. """
"""Parse output variable from string if valid."""
# ::varname::value tranlatest to varname = value
result = string.split("::", 2)
if len(result) != 3:
Expand All @@ -62,7 +62,7 @@ def check_for_output(self, string: str) -> bool:
return True

async def run_cmd(self, command: str, wait: bool = True):
""" Runs a command using asyncio """
"""Runs a command using asyncio"""
process = await asyncio.create_subprocess_shell(
command,
shell=True,
Expand Down
6 changes: 3 additions & 3 deletions datatorch/agent/pipelines/step/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ async def log_uploader(self):

@property
def api(self):
""" Agent API Client if it exists. """
"""Agent API Client if it exists."""
return self.job and self.job.api

def log(self, message: str):
""" Records a log message. """
"""Records a log message."""
iso_date = datetime.now(timezone.utc).isoformat()[:-9] + "Z"
self.logs.append(dict(createdAt=iso_date, message=message)) # type: ignore
self.logger.info(message)

async def upload_logs(self):
""" Uploads saved logs to webserver. """
"""Uploads saved logs to webserver."""
if self.id and len(self.logs) > 0:
logs = self.logs
self.logs = []
Expand Down
2 changes: 1 addition & 1 deletion datatorch/agent/pipelines/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


def create_variables_mock(job: Union[AgentJobConfig, dict] = {}):
""" Merges config with mocked data."""
"""Merges config with mocked data."""
run: AgentRunConfig = {
"id": "run-id",
"name": "Action Name Mock",
Expand Down
2 changes: 1 addition & 1 deletion datatorch/agent/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def restart():
""" Restarts the current process running with itself """
"""Restarts the current process running with itself"""
args = sys.argv[:]
args.insert(0, sys.executable)
if sys.platform == "win32":
Expand Down
12 changes: 6 additions & 6 deletions datatorch/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,26 @@


class ApiClient(Client):
""" Adds simple queries to the client wrapper """
"""Adds simple queries to the client wrapper"""

def settings(self) -> ApiSettings:
""" API instance settings """
"""API instance settings"""
return cast(
ApiSettings, self.query_to_class(ApiSettings, _SETTINGS, path="settings")
)

def viewer(self) -> User:
""" Current logged in user """
"""Current logged in user"""
return cast(User, self.query_to_class(User, _VIEWER, path="viewer"))

@overload
def project(self, id: str) -> Project: # type: ignore
""" Retrieve a project by ID """
"""Retrieve a project by ID"""
pass

@overload
def project(self, login: str, slug: str) -> Project: # type: ignore
""" Retrieve a project by login and slug """
"""Retrieve a project by login and slug"""
pass

def project(self, loginOrId: str, slug: str = None) -> Project:
Expand Down Expand Up @@ -139,7 +139,7 @@ def download_file(
# return []

def validate_endpoint(self) -> bool:
""" Returns true if provided endpoint is correct. """
"""Returns true if provided endpoint is correct."""
try:
version = self.settings().api_version
logger.info("Endpoint API version: {}".format(version))
Expand Down
8 changes: 4 additions & 4 deletions datatorch/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _get_token_header(agent: bool = False):


class Client(object):
""" Wrapper for the DataTorch API including GraphQL and uploading """
"""Wrapper for the DataTorch API including GraphQL and uploading"""

@classmethod
def create_socket_transport(
Expand Down Expand Up @@ -96,22 +96,22 @@ def graphql_url(self) -> str:
def execute_files(
self, paths: List[str], *args, params: dict = {}, **kwargs
) -> dict:
""" Combine and excute query of multiple GraphQL files """
"""Combine and excute query of multiple GraphQL files"""
query = ""
for path in paths:
with open(path) as f:
query += f.read()
return self.execute(query, *args, params=params, **kwargs)

def execute_file(self, path: str, *args, params: dict = {}, **kwargs) -> dict:
""" Excute query from GraphQL file """
"""Excute query from GraphQL file"""
with open(path) as f:
return self.execute(f.read(), *args, params=params, **kwargs)

def execute(
self, query: Union[DocumentNode, str], *args, params: dict = {}, **kwargs
) -> dict:
""" Wrapper around execute """
"""Wrapper around execute"""
removed_none = dict((k, v) for k, v in params.items() if v is not None)
query_doc = gql(query) if isinstance(query, str) else query
return self.client.execute(
Expand Down
6 changes: 3 additions & 3 deletions datatorch/api/entity/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class BaseEntity(object):

@classmethod
def add_fragment(cls, query: str, name: str = None) -> str:
""" Appends GraphQL fragment to the query """
"""Appends GraphQL fragment to the query"""
return query + cls.fragment(name)

@classmethod
@functools.lru_cache()
def fragment(cls, name: str = None) -> str:
""" Creates fragment based on class annotations """
"""Creates fragment based on class annotations"""

annotations = get_annotations(cls)

Expand Down Expand Up @@ -75,7 +75,7 @@ def dict(self) -> dict:
return dic

def to_json(self, indent: int = 2) -> str:
""" Format entity as json """
"""Format entity as json"""
return json.dumps(self.dict(), indent=indent)

def create(self, client=None):
Expand Down
4 changes: 2 additions & 2 deletions datatorch/api/entity/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def fragment(cls, name=None, data_file=False):
annotations: List[Annotation]

def create(self, client=None) -> None:
""" Imports file """
"""Imports file"""
super().create(client=client)

assert self.link_id is not None
Expand Down Expand Up @@ -139,7 +139,7 @@ def _update(self, obj):
super()._update(obj)

def annotator(self):
""" Opens file in annotator """
"""Opens file in annotator"""
import webbrowser

url = self.client.api_url.replace("/api", f"/annotate/{self.id}")
Expand Down
4 changes: 2 additions & 2 deletions datatorch/api/entity/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@


class Project(BaseEntity):
""" Projects contain datasets, files and annotations. """
"""Projects contain datasets, files and annotations."""

id: str
slug: str
Expand Down Expand Up @@ -143,7 +143,7 @@ def storage_links(self) -> List[StorageLink]:
)

def add(self, entity: AddableEntity):
""" Add entity to project """
"""Add entity to project"""

entity.client = self.client

Expand Down
Loading

0 comments on commit 2eee941

Please sign in to comment.