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

initial pass at resolving ruff issues #289

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 6 deletions contentctl/actions/build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import sys
import shutil
import os

from dataclasses import dataclass

from contentctl.objects.enums import SecurityContentProduct, SecurityContentType
from contentctl.input.director import Director, DirectorOutputDto
from contentctl.objects.enums import SecurityContentType
from contentctl.input.director import DirectorOutputDto
from contentctl.output.conf_output import ConfOutput
from contentctl.output.conf_writer import ConfWriter
from contentctl.output.api_json_output import ApiJsonOutput
Expand All @@ -14,7 +11,6 @@
import pathlib
import json
import datetime
from typing import Union

from contentctl.objects.config import build

Expand Down
3 changes: 0 additions & 3 deletions contentctl/actions/deploy_acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from contentctl.input.director import DirectorInputDto
from contentctl.output.conf_output import ConfOutput


from typing import Union

@dataclass(frozen=True)
class ACSDeployInputDto:
director_input_dto: DirectorInputDto
Expand Down
19 changes: 6 additions & 13 deletions contentctl/actions/detection_testing/DetectionTestingManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
from contentctl.actions.detection_testing.infrastructures.DetectionTestingInfrastructure import DetectionTestingInfrastructure
from contentctl.actions.detection_testing.infrastructures.DetectionTestingInfrastructureContainer import DetectionTestingInfrastructureContainer
from contentctl.actions.detection_testing.infrastructures.DetectionTestingInfrastructureServer import DetectionTestingInfrastructureServer
from urllib.parse import urlparse
from copy import deepcopy
from contentctl.objects.enums import DetectionTestingTargetInfrastructure
import signal
import datetime
# from queue import Queue
from dataclasses import dataclass
# import threading
import ctypes
from contentctl.actions.detection_testing.infrastructures.DetectionTestingInfrastructure import (
DetectionTestingInfrastructure,
DetectionTestingManagerOutputDto,
)
from contentctl.actions.detection_testing.views.DetectionTestingView import (
DetectionTestingView,
)
from contentctl.objects.enums import PostTestBehavior
from pydantic import BaseModel, Field
from pydantic import BaseModel
from contentctl.objects.detection import Detection
import concurrent.futures
import docker
Expand Down Expand Up @@ -87,7 +80,7 @@ def sigint_handler(signum, frame):
# Wait for all instances to be set up
for future in concurrent.futures.as_completed(future_instances_setup):
try:
result = future.result()
_ = future.result()
except Exception as e:
self.output_dto.terminate = True
print(f"Error setting up container: {str(e)}")
Expand All @@ -102,7 +95,7 @@ def sigint_handler(signum, frame):
# Wait for execution to finish
for future in concurrent.futures.as_completed(future_instances_execute):
try:
result = future.result()
_ = future.result()
except Exception as e:
self.output_dto.terminate = True
print(f"Error running in container: {str(e)}")
Expand All @@ -115,14 +108,14 @@ def sigint_handler(signum, frame):
}
for future in concurrent.futures.as_completed(future_views_shutdowner):
try:
result = future.result()
_ = future.result()
except Exception as e:
print(f"Error stopping view: {str(e)}")

# Wait for original view-related threads to complete
for future in concurrent.futures.as_completed(future_views):
try:
result = future.result()
_ = future.result()
except Exception as e:
print(f"Error running container: {str(e)}")

Expand All @@ -134,7 +127,7 @@ def create_DetectionTestingInfrastructureObjects(self):
if (isinstance(self.input_dto.config, test) and isinstance(infrastructure, Container)):
try:
client = docker.from_env()
except Exception as e:
except Exception:
raise Exception("Unable to connect to docker. Are you sure that docker is running on this host?")
try:

Expand Down
12 changes: 4 additions & 8 deletions contentctl/actions/detection_testing/GitService.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contentctl.input.director import DirectorOutputDto
import logging
import os
import pathlib
Expand All @@ -21,11 +22,6 @@
LOGGER = logging.getLogger(__name__)



from contentctl.input.director import DirectorOutputDto



class GitService(BaseModel):
director: DirectorOutputDto
config: test_common
Expand Down Expand Up @@ -56,7 +52,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
target_tree = repo.revparse_single(target_branch).tree
self.gitHash = target_tree.id
diffs = repo.index.diff_to_tree(target_tree)
except Exception as e:
except Exception:
raise Exception(f"Error parsing diff target_branch '{target_branch}'. Are you certain that it exists?")

#Get the uncommitted changes in the current directory
Expand All @@ -72,7 +68,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
updated_lookups:List[Lookup] =[]

for diff in all_diffs:
if type(diff) == pygit2.Patch:
if isinstance(diff, pygit2.Patch):
if diff.delta.status in (DeltaStatus.ADDED, DeltaStatus.MODIFIED, DeltaStatus.RENAMED):
#print(f"{DeltaStatus(diff.delta.status).name:<8}:{diff.delta.new_file.raw_path}")
decoded_path = pathlib.Path(diff.delta.new_file.raw_path.decode('utf-8'))
Expand Down Expand Up @@ -108,7 +104,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
if len(matched) == 0:
raise Exception(f"Failed to find any lookups that reference the modified CSV file '{decoded_path}'")
elif len(matched) > 1:
raise Exception(f"More than 1 Lookup reference the modified CSV file '{decoded_path}': {[l.file_path for l in matched ]}")
raise Exception(f"More than 1 Lookup reference the modified CSV file '{decoded_path}': {[matched_csv.file_path for matched_csv in matched ]}")
else:
updatedLookup = matched[0]
elif decoded_path.suffix == ".mlmodel":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def removeContainer(self, removeVolumes: bool = True, forceRemove: bool = True):
container: docker.models.containers.Container = (
self.get_docker_client().containers.get(self.get_name())
)
except Exception as e:
except Exception:
# Container does not exist, no need to try and remove it
return
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
)

import time
import datetime
import tqdm


Expand Down Expand Up @@ -39,9 +38,7 @@ def setup(self):
miniters=0,
mininterval=0,
)
fmt = self.format_pbar(
len(self.sync_obj.outputQueue), len(self.sync_obj.inputQueue)
)
self.format_pbar(len(self.sync_obj.outputQueue), len(self.sync_obj.inputQueue))

self.showStatus()

Expand Down
Loading
Loading