Skip to content

Commit

Permalink
Update pre-commit with ruff (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
myakove authored Nov 15, 2023
1 parent b2629e6 commit 48c2599
Show file tree
Hide file tree
Showing 67 changed files with 458 additions and 861 deletions.
8 changes: 5 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[flake8]

max-line-length = 120
select=FCN,M511

exclude =
doc,
Expand All @@ -11,7 +10,7 @@ exclude =
docs/*,
.cache/*

fcfn_exclude_functions =
fcn_exclude_functions =
update,
getLogger,
loads,
Expand Down Expand Up @@ -44,6 +43,9 @@ fcfn_exclude_functions =
re,
requests,
signal,
self,
yaml,
benedict,

enable-extensions =
FCN,
38 changes: 9 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@ default_language_version:
python: python3

repos:
- repo: https://github.com/PyCQA/autoflake
rev: "v2.2.1"
hooks:
- id: autoflake
args:
- --in-place
- --remove-unused-variables
- --remove-all-unused-imports

- repo: https://github.com/hadialqattan/pycln
rev: "v2.3.0"
hooks:
- id: pycln

- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: "23.11.0"
hooks:
- id: black
args: [--preview]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
hooks:
Expand All @@ -37,21 +12,26 @@ repos:
- id: end-of-file-fixer
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-toml

- repo: https://github.com/PyCQA/flake8
rev: "6.1.0"
hooks:
- id: flake8
args: [--max-line-length=120]
args: [--config=.flake8]
additional_dependencies: [
"git+https://github.com/RedHatQE/flake8-plugins.git",
"pep8-naming",
"flake8-comprehensions",
"flake8-mutable",
"flake8-simplify",
]

- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
hooks:
- id: ruff
- id: ruff-format
38 changes: 19 additions & 19 deletions ocp_resources/catalog_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ def __init__(
self.image = image
self.display_name = display_name
self.publisher = publisher
self.update_strategy_registry_poll_interval = (
update_strategy_registry_poll_interval
)
self.update_strategy_registry_poll_interval = update_strategy_registry_poll_interval

def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not all([
self.source_type, self.image, self.display_name, self.publisher
]):
if not all([self.source_type, self.image, self.display_name, self.publisher]):
raise ValueError(
"Passing yaml_file or all parameters 'source_type', 'image',"
" 'display_name' and 'publisher' is required."
)
self.res.update({
"spec": {
"sourceType": self.source_type,
"image": self.image,
"displayName": self.display_name,
"publisher": self.publisher,
self.res.update(
{
"spec": {
"sourceType": self.source_type,
"image": self.image,
"displayName": self.display_name,
"publisher": self.publisher,
}
}
})
)
if self.update_strategy_registry_poll_interval:
self.res["spec"].update({
"updateStrategy": {
"registryPoll": {
"interval": self.update_strategy_registry_poll_interval,
self.res["spec"].update(
{
"updateStrategy": {
"registryPoll": {
"interval": self.update_strategy_registry_poll_interval,
},
},
},
})
}
)
4 changes: 1 addition & 3 deletions ocp_resources/cdi_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def wait_until_upload_url_changed(self, uploadproxy_url, timeout=TIMEOUT_4MINUTE
Returns:
bool: True if url is equal to uploadProxyURL.
"""
self.logger.info(
f"Wait for {self.kind} {self.name} to ensure current URL == uploadProxyURL"
)
self.logger.info(f"Wait for {self.kind} {self.name} to ensure current URL == uploadProxyURL")
samples = TimeoutSampler(
wait_timeout=timeout,
sleep=1,
Expand Down
4 changes: 1 addition & 3 deletions ocp_resources/cluster_role_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not self.cluster_role:
raise ValueError(
"Passing yaml_file or parameter 'cluster_role' is required."
)
raise ValueError("Passing yaml_file or parameter 'cluster_role' is required.")
self.res.setdefault("roleRef", {})
self.res["roleRef"] = {
"apiGroup": self.api_group,
Expand Down
4 changes: 1 addition & 3 deletions ocp_resources/controller_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if self.owner_references:
self.res.setdefault("metadata", {}).update({
"ownerReference": self.owner_references
})
self.res.setdefault("metadata", {}).update({"ownerReference": self.owner_references})
if self.revision_object:
self.res.update({"data": self.revision_object.res})
25 changes: 10 additions & 15 deletions ocp_resources/cron_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,22 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not (self.job_template and self.schedule):
raise ValueError(
"yaml_file or parameters 'job_template' and 'schedule' are"
" required."
)
self.res.update({
"spec": {
"jobTemplate": self.job_template,
"schedule": self.schedule,
raise ValueError("yaml_file or parameters 'job_template' and 'schedule' are" " required.")
self.res.update(
{
"spec": {
"jobTemplate": self.job_template,
"schedule": self.schedule,
}
}
})
)
if self.timezone:
self.res["spec"]["timezone"] = self.timezone
if self.suspend:
self.res["spec"]["suspend"] = self.suspend
if self.successful_jobs_history_limit:
self.res["spec"][
"successfulJobsHistoryLimit"
] = self.successful_jobs_history_limit
self.res["spec"]["successfulJobsHistoryLimit"] = self.successful_jobs_history_limit
if self.failed_jobs_history_limit:
self.res["spec"][
"failedJobsHistoryLimit"
] = self.failed_jobs_history_limit
self.res["spec"]["failedJobsHistoryLimit"] = self.failed_jobs_history_limit
if self.concurrency_policy:
self.res["spec"]["concurrencyPolicy"] = self.concurrency_policy
12 changes: 6 additions & 6 deletions ocp_resources/csi_storage_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not self.storage_class_name:
raise ValueError(
"yaml_file or parameter 'storage_class_name' is required."
)
self.res.update({
"storageClassName": self.storage_class_name,
})
raise ValueError("yaml_file or parameter 'storage_class_name' is required.")
self.res.update(
{
"storageClassName": self.storage_class_name,
}
)
if self.maximum_volume_size:
self.res["maximumVolumeSize"] = self.maximum_volume_size
if self.node_topology:
Expand Down
5 changes: 1 addition & 4 deletions ocp_resources/daemonset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def wait_until_deployed(self, timeout=TIMEOUT_4MINUTES):
status = sample.items[0].status
desired_number_scheduled = status.desiredNumberScheduled
number_ready = status.numberReady
if (
desired_number_scheduled > 0
and desired_number_scheduled == number_ready
):
if desired_number_scheduled > 0 and desired_number_scheduled == number_ready:
return

def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None):
Expand Down
26 changes: 12 additions & 14 deletions ocp_resources/data_import_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,23 @@ def to_dict(self):
if self.image_stream and self.url:
raise ValueError("imageStream and url can not coexist")

self.res.update({
"spec": {
"template": {
"spec": {
"source": {"registry": {"pullMethod": self.pull_method}},
"storage": {
"resources": {"requests": {"storage": self.size}}
},
self.res.update(
{
"spec": {
"template": {
"spec": {
"source": {"registry": {"pullMethod": self.pull_method}},
"storage": {"resources": {"requests": {"storage": self.size}}},
}
}
}
}
})
)
spec = self.res["spec"]["template"]["spec"]
if self.bind_immediate_annotation:
self.res["metadata"].setdefault("annotations", {}).update({
f"{NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO}/storage.bind.immediate.requested": (
"true"
)
})
self.res["metadata"].setdefault("annotations", {}).update(
{f"{NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO}/storage.bind.immediate.requested": ("true")}
)
if self.image_stream:
spec["source"]["registry"]["imageStream"] = self.image_stream
if self.url:
Expand Down
12 changes: 7 additions & 5 deletions ocp_resources/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ def __init__(
def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update({
"spec": {
"source": self.source,
},
})
self.res.update(
{
"spec": {
"source": self.source,
},
}
)

@property
def pvc(self):
Expand Down
Loading

0 comments on commit 48c2599

Please sign in to comment.