Skip to content

Commit

Permalink
chore: apply new line-length
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo committed Oct 27, 2023
1 parent bce1a7e commit cceb76d
Show file tree
Hide file tree
Showing 54 changed files with 464 additions and 1,648 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
exclude: "^docs/"
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
Expand Down
6 changes: 1 addition & 5 deletions ansible_rulebook/action/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ async def __call__(self):
elif "var" in self.action_args:
key = self.action_args.get("var")
try:
print(
dpath.get(
self.helper.control.variables, key, separator="."
)
)
print(dpath.get(self.helper.control.variables, key, separator="."))
except KeyError:
logger.error("Key %s not found in variable pool", key)
raise
Expand Down
4 changes: 1 addition & 3 deletions ansible_rulebook/action/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def get_events(self) -> Dict:

def embellish_internal_event(self, event: Dict) -> Dict:
"""Insert metadata for every internally generated event"""
return insert_meta(
event, **{"source_name": self.action, "source_type": "internal"}
)
return insert_meta(event, **{"source_name": self.action, "source_type": "internal"})

def set_action(self, action) -> None:
self.action = action
Expand Down
4 changes: 1 addition & 3 deletions ansible_rulebook/action/print_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ async def __call__(self):
if "pretty" in self.action_args:
print_fn = pprint

var_name = (
"events" if "events" in self.helper.control.variables else "event"
)
var_name = "events" if "events" in self.helper.control.variables else "event"

print_fn(self.helper.control.variables[var_name])
sys.stdout.flush()
Expand Down
13 changes: 3 additions & 10 deletions ansible_rulebook/action/run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
from drools import ruleset as lang

from ansible_rulebook.conf import settings
from ansible_rulebook.exception import (
ControllerApiException,
JobTemplateNotFoundException,
)
from ansible_rulebook.exception import ControllerApiException, JobTemplateNotFoundException
from ansible_rulebook.job_template_runner import job_template_runner
from ansible_rulebook.util import run_at

Expand Down Expand Up @@ -61,9 +58,7 @@ async def __call__(self):
self.helper.metadata.rule,
)

self.job_args["extra_vars"] = self.helper.collect_extra_vars(
self.job_args.get("extra_vars", {})
)
self.job_args["extra_vars"] = self.helper.collect_extra_vars(self.job_args.get("extra_vars", {}))
await self._job_start_event()
await self._run()

Expand Down Expand Up @@ -119,9 +114,7 @@ async def _post_process(self) -> None:
post_events = self.action_args.get("post_events", False)

if set_facts or post_events:
ruleset = self.action_args.get(
"ruleset", self.helper.metadata.rule_set
)
ruleset = self.action_args.get("ruleset", self.helper.metadata.rule_set)
logger.debug("set_facts")
facts = self.controller_job.get("artifacts", {})
if facts:
Expand Down
51 changes: 12 additions & 39 deletions ansible_rulebook/action/run_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
import yaml
from drools import ruleset as lang

from ansible_rulebook.collection import (
find_playbook,
has_playbook,
split_collection_name,
)
from ansible_rulebook.collection import find_playbook, has_playbook, split_collection_name
from ansible_rulebook.conf import settings
from ansible_rulebook.exception import (
MissingArtifactKeyException,
Expand Down Expand Up @@ -68,10 +64,7 @@ def __init__(self, metadata: Metadata, control: Control, **action_args):

async def __call__(self):
try:
logger.info(
f"ruleset: {self.helper.metadata.rule_set}, "
f"rule: {self.helper.metadata.rule}"
)
logger.info(f"ruleset: {self.helper.metadata.rule_set}, " f"rule: {self.helper.metadata.rule}")
logger.debug("private data dir %s", self.private_data_dir)
await self._pre_process()
await self._job_start_event()
Expand Down Expand Up @@ -106,9 +99,7 @@ async def _run(self):
if i > 0:
if delay > 0:
await asyncio.sleep(delay)
logger.info(
"Previous run_playbook failed. Retry %d of %d", i, retries
)
logger.info("Previous run_playbook failed. Retry %d of %d", i, retries)

await Runner(
self.private_data_dir,
Expand All @@ -128,9 +119,7 @@ def _runner_args(self):
return {"playbook": self.name, "inventory": self.inventory}

async def _pre_process(self) -> None:
playbook_extra_vars = self.helper.collect_extra_vars(
self.action_args.get("extra_vars", {})
)
playbook_extra_vars = self.helper.collect_extra_vars(self.action_args.get("extra_vars", {}))

env_dir = os.path.join(self.private_data_dir, "env")
inventory_dir = os.path.join(self.private_data_dir, "inventory")
Expand All @@ -143,19 +132,13 @@ async def _pre_process(self) -> None:

if self.helper.control.inventory:
create_inventory(inventory_dir, self.helper.control.inventory)
self.inventory = os.path.join(
inventory_dir, os.path.basename(self.helper.control.inventory)
)
self.inventory = os.path.join(inventory_dir, os.path.basename(self.helper.control.inventory))
os.mkdir(project_dir)

logger.debug(
"project_data_file: %s", self.helper.control.project_data_file
)
logger.debug("project_data_file: %s", self.helper.control.project_data_file)
if self.helper.control.project_data_file:
if os.path.exists(self.helper.control.project_data_file):
await self._untar_project(
project_dir, self.helper.control.project_data_file
)
await self._untar_project(project_dir, self.helper.control.project_data_file)
return
self._copy_playbook_files(project_dir)

Expand All @@ -177,10 +160,7 @@ def _copy_playbook_files(self, project_dir):
os.path.join(project_dir, self.name),
)
else:
msg = (
f"Could not find a playbook for {self.name} "
f"from {os.getcwd()}"
)
msg = f"Could not find a playbook for {self.name} " f"from {os.getcwd()}"
logger.error(msg)
raise PlaybookNotFoundException(msg)

Expand Down Expand Up @@ -210,22 +190,17 @@ async def _post_process(self):
if rc == 0 and (set_facts or post_events):
logger.debug("set_facts")
fact_folder = self._get_latest_artifact("fact_cache", False)
ruleset = self.action_args.get(
"ruleset", self.helper.metadata.rule_set
)
ruleset = self.action_args.get("ruleset", self.helper.metadata.rule_set)
for host_facts in glob.glob(os.path.join(fact_folder, "*")):
with open(host_facts) as file_handle:
fact = json.loads(file_handle.read())
if self.output_key:
if self.output_key not in fact:
logger.error(
"The artifacts from the ansible-runner "
"does not have key %s",
"The artifacts from the ansible-runner " "does not have key %s",
self.output_key,
)
raise MissingArtifactKeyException(
f"Missing key: {self.output_key} in artifacts"
)
raise MissingArtifactKeyException(f"Missing key: {self.output_key} in artifacts")
fact = fact[self.output_key]
fact = self.helper.embellish_internal_event(fact)
logger.debug("fact %s", fact)
Expand All @@ -235,9 +210,7 @@ async def _post_process(self):
lang.post(ruleset, fact)

def _get_latest_artifact(self, component: str, content: bool = True):
files = glob.glob(
os.path.join(self.private_data_dir, "artifacts", "*", component)
)
files = glob.glob(os.path.join(self.private_data_dir, "artifacts", "*", component))
files.sort(key=os.path.getmtime, reverse=True)
if not files:
raise PlaybookStatusNotFoundException(f"No {component} file found")
Expand Down
26 changes: 8 additions & 18 deletions ansible_rulebook/action/run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
from drools import ruleset as lang

from ansible_rulebook.conf import settings
from ansible_rulebook.exception import (
ControllerApiException,
WorkflowJobTemplateNotFoundException,
)
from ansible_rulebook.exception import ControllerApiException, WorkflowJobTemplateNotFoundException
from ansible_rulebook.job_template_runner import job_template_runner
from ansible_rulebook.util import run_at

Expand Down Expand Up @@ -61,9 +58,7 @@ async def __call__(self):
self.helper.metadata.rule,
)

self.job_args["extra_vars"] = self.helper.collect_extra_vars(
self.job_args.get("extra_vars", {})
)
self.job_args["extra_vars"] = self.helper.collect_extra_vars(self.job_args.get("extra_vars", {}))
await self._job_start_event()
await self._run()

Expand All @@ -79,17 +74,14 @@ async def _run(self):
if delay > 0:
await asyncio.sleep(delay)
logger.info(
"Previous run_workflow_template failed. "
"Retry %d of %d",
"Previous run_workflow_template failed. " "Retry %d of %d",
i,
retries,
)
controller_job = (
await job_template_runner.run_workflow_job_template(
self.name,
self.organization,
self.job_args,
)
controller_job = await job_template_runner.run_workflow_job_template(
self.name,
self.organization,
self.job_args,
)
if controller_job["status"] != "failed":
break
Expand Down Expand Up @@ -125,9 +117,7 @@ async def _post_process(self) -> None:
post_events = self.action_args.get("post_events", False)

if set_facts or post_events:
ruleset = self.action_args.get(
"ruleset", self.helper.metadata.rule_set
)
ruleset = self.action_args.get("ruleset", self.helper.metadata.rule_set)
logger.debug("set_facts")
facts = self.controller_job.get("artifacts", {})
if facts:
Expand Down
4 changes: 1 addition & 3 deletions ansible_rulebook/action/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ def cancel_callback():
),
)
except CancelledError:
logger.debug(
"Ansible Runner Thread Pool executor task cancelled"
)
logger.debug("Ansible Runner Thread Pool executor task cancelled")
shutdown = True
raise
finally:
Expand Down
4 changes: 1 addition & 3 deletions ansible_rulebook/action/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,4 @@ async def __call__(self):
message,
)
)
raise ShutdownException(
ShutdownMessage(message=message, delay=delay, kind=kind)
)
raise ShutdownException(ShutdownMessage(message=message, delay=delay, kind=kind))
Loading

0 comments on commit cceb76d

Please sign in to comment.