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

Fixes for flake8 linting #1117

Merged
Merged
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
22 changes: 21 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
[flake8]
ignore =
# Conflicts with black
E203
E203
# Line break occurred before a binary operator. Update by W504 Line
W503
# Allow "import torch.nn.functional as F"
N812
# Line length, handled separately by max-line-length
E501
# too many leading '#' for block comments
E266


per-file-ignores =
# Unused imports in __init__.py are OK
**/__init__.py:F401

exclude =
*_pb2*,
.git,
__pycache__,
build,
dist,
.venv

max-line-length = 100

copyright-check = True

# Enable specific checks or plugins
# B: Bandit security checks (e.g., detecting insecure function use).
# C: Cyclomatic complexity, used to flag overly complex functions.
# E: PEP8 errors (e.g., style issues).
# F: Pyflakes errors, like unused imports or undefined names.
# W: PEP8 warnings (e.g., stylistic issues).
# T4: Type checking from third-party tools (like mypy).
# B9: Bugbear, for additional warnings about potentially error-prone code.
select = B,C,E,F,W,T4,B9
rajithkrishnegowda marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def start(self):
)
self.collaborators = self.runtime.collaborators

validate_agg_private_attr(self, "start", aggr = ["test_loader_agg"], collabs =["train_loader", "test_loader"])
validate_agg_private_attr(self, "start", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"])

self.exclude_agg_to_agg = 10
self.include_agg_to_agg = 100
Expand All @@ -49,7 +49,7 @@ def aggregator_step(self):
Testing whether Agg private attributes are accessible in next agg step.
Collab private attributes should not be accessible here
"""
validate_agg_private_attr(self, "aggregator_step", aggr = ["test_loader_agg"], collabs =["train_loader", "test_loader"])
validate_agg_private_attr(self, "aggregator_step", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"])

self.include_agg_to_collab = 42
self.exclude_agg_to_collab = 40
Expand All @@ -66,7 +66,7 @@ def collaborator_step_a(self):
Aggregator private attributes should not be accessible here
"""
validate_collab_private_attrs(
self, "collaborator_step_a", aggr = ["test_loader_agg"], collabs =["train_loader", "test_loader"]
self, "collaborator_step_a", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"]
)

self.exclude_collab_to_collab = 2
Expand All @@ -81,7 +81,7 @@ def collaborator_step_b(self):
"""

validate_collab_private_attrs(
self, "collaborator_step_b", aggr = ["test_loader_agg"], collabs =["train_loader", "test_loader"]
self, "collaborator_step_b", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"]
)
self.exclude_collab_to_agg = 10
self.include_collab_to_agg = 12
Expand Down Expand Up @@ -152,7 +152,7 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
step_name: Name of the step being validated
private_attr_kwargs: Keyword arguments specifying the names of private attributes for the aggregator and collaborators.
"""
agg_attrs = private_attrs_kwargs.get('aggr',[])
agg_attrs = private_attrs_kwargs.get('aggr', [])
collab_attrs = private_attrs_kwargs.get('collabs', [])
# Aggregator should only be able to access its own attributes

Expand All @@ -168,7 +168,7 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
)

# check for collaborator private attributes that should not be accessible
breached_collab_attrs = [attr for attr in collab_attrs if hasattr(self,attr)]
breached_collab_attrs = [attr for attr in collab_attrs if hasattr(self, attr)]
if breached_collab_attrs:
TestFlowPrivateAttributes.ERROR_LIST.append(
step_name + "_collaborator_attributes_found"
Expand All @@ -177,9 +177,6 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
f"{bcolors.FAIL} ... Attribute test failed in {step_name} - collaborator"
+ f"private attributes accessible:{','.join(breached_collab_attrs)} {bcolors.ENDC}"
)



for idx, collab in enumerate(self.collaborators):
# Collaborator attributes should not be accessible in aggregator step
if (
Expand All @@ -206,13 +203,13 @@ def validate_collab_private_attrs(self, step_name, **private_attrs_kwargs):
step_name: Name of the step being validated
private_attr_kwargs: Keyword arguments specifying the names of private attributes for the aggregator and collaborators.
"""
agg_attrs = private_attrs_kwargs.get('aggr',[])
agg_attrs = private_attrs_kwargs.get('aggr', [])
collab_attrs = private_attrs_kwargs.get('collabs', [])

# Collaborator should only be able to access its own attributes

# check for missing collaborators attributes
inaccessible_collab_attrs = [attr for attr in collab_attrs if not hasattr(self,attr)]
inaccessible_collab_attrs = [attr for attr in collab_attrs if not hasattr(self, attr)]

if inaccessible_collab_attrs:
TestFlowPrivateAttributes.ERROR_LIST.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def start(self):
)
self.collaborators = self.runtime.collaborators

validate_agg_private_attr(self,"start", aggr = ["test_loader_agg_via_callable"], collabs = ["train_loader_via_callable", "test_loader_via_callable"])
validate_agg_private_attr(self, "start", aggr=["test_loader_agg_via_callable"], collabs=["train_loader_via_callable", "test_loader_via_callable"])

self.exclude_agg_to_agg = 10
self.include_agg_to_agg = 100
Expand All @@ -49,7 +49,7 @@ def aggregator_step(self):
Testing whether Agg private attributes are accessible in next agg step.
Collab private attributes should not be accessible here
"""
validate_agg_private_attr(self, "aggregator_step", aggr = ["test_loader_agg_via_callable"], collabs = ["train_loader_via_callable", "test_loader_via_callable"])
validate_agg_private_attr(self, "aggregator_step", aggr=["test_loader_agg_via_callable"], collabs=["train_loader_via_callable", "test_loader_via_callable"])

self.include_agg_to_collab = 42
self.exclude_agg_to_collab = 40
Expand All @@ -66,7 +66,7 @@ def collaborator_step_a(self):
Aggregator private attributes should not be accessible here
"""
validate_collab_private_attrs(
self, "collaborator_step_a", aggr = ["test_loader_agg_via_callable"], collabs = ["train_loader_via_callable", "test_loader_via_callable"]
self, "collaborator_step_a", aggr=["test_loader_agg_via_callable"], collabs=["train_loader_via_callable", "test_loader_via_callable"]
)

self.exclude_collab_to_collab = 2
Expand All @@ -81,7 +81,7 @@ def collaborator_step_b(self):
"""

validate_collab_private_attrs(
self, "collaborator_step_b", aggr = ["test_loader_agg_via_callable"], collabs = ["train_loader_via_callable", "test_loader_via_callable"]
self, "collaborator_step_b", aggr=["test_loader_agg_via_callable"], collabs=["train_loader_via_callable", "test_loader_via_callable"]
)
self.exclude_collab_to_agg = 10
self.include_collab_to_agg = 12
Expand Down Expand Up @@ -152,7 +152,7 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
step_name: Name of the step being validated
private_attr_kwargs: Keyword arguments specifying the names of private attributes for the aggregator and collaborators.
"""
agg_attrs = private_attrs_kwargs.get('aggr',[])
agg_attrs = private_attrs_kwargs.get('aggr', [])
collab_attrs = private_attrs_kwargs.get('collabs', [])
# Aggregator should only be able to access its own attributes

Expand All @@ -168,7 +168,7 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
)

# check for collaborator private attributes that should not be accessible
breached_collab_attrs = [attr for attr in collab_attrs if hasattr(self,attr)]
breached_collab_attrs = [attr for attr in collab_attrs if hasattr(self, attr)]
if breached_collab_attrs:
TestFlowPrivateAttributes.ERROR_LIST.append(
step_name + "_collaborator_attributes_found"
Expand All @@ -177,9 +177,6 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
f"{bcolors.FAIL} ... Attribute test failed in {step_name} - collaborator"
+ f"private attributes accessible:{','.join(breached_collab_attrs)} {bcolors.ENDC}"
)



for idx, collab in enumerate(self.collaborators):
# Collaborator attributes should not be accessible in aggregator step
if (
Expand All @@ -206,13 +203,13 @@ def validate_collab_private_attrs(self, step_name, **private_attrs_kwargs):
step_name: Name of the step being validated
private_attr_kwargs: Keyword arguments specifying the names of private attributes for the aggregator and collaborators.
"""
agg_attrs = private_attrs_kwargs.get('aggr',[])
agg_attrs = private_attrs_kwargs.get('aggr', [])
collab_attrs = private_attrs_kwargs.get('collabs', [])

# Collaborator should only be able to access its own attributes

# check for missing collaborators attributes
inaccessible_collab_attrs = [attr for attr in collab_attrs if not hasattr(self,attr)]
inaccessible_collab_attrs = [attr for attr in collab_attrs if not hasattr(self, attr)]

if inaccessible_collab_attrs:
TestFlowPrivateAttributes.ERROR_LIST.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def start(self):
)
self.collaborators = self.runtime.collaborators

validate_agg_private_attr(self,"start", aggr = ["test_loader_agg"], collabs = ["train_loader", "test_loader"])
validate_agg_private_attr(self, "start", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"])

self.exclude_agg_to_agg = 10
self.include_agg_to_agg = 100
Expand All @@ -49,7 +49,7 @@ def aggregator_step(self):
Testing whether Agg private attributes are accessible in next agg step.
Collab private attributes should not be accessible here
"""
validate_agg_private_attr(self,"aggregator_step", aggr = ["test_loader_agg"], collabs = ["train_loader", "test_loader"])
validate_agg_private_attr(self, "aggregator_step", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"])

self.include_agg_to_collab = 42
self.exclude_agg_to_collab = 40
Expand All @@ -66,7 +66,7 @@ def collaborator_step_a(self):
Aggregator private attributes should not be accessible here
"""
validate_collab_private_attrs(
self, "collaborator_step_a", aggr = ["test_loader_agg"], collabs = ["train_loader", "test_loader"]
self, "collaborator_step_a", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"]
)

self.exclude_collab_to_collab = 2
Expand All @@ -81,7 +81,7 @@ def collaborator_step_b(self):
"""

validate_collab_private_attrs(
self, "collaborator_step_b", aggr = ["test_loader_agg"], collabs = ["train_loader", "test_loader"]
self, "collaborator_step_b", aggr=["test_loader_agg"], collabs=["train_loader", "test_loader"]
)
self.exclude_collab_to_agg = 10
self.include_collab_to_agg = 12
Expand Down Expand Up @@ -152,7 +152,7 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
step_name: Name of the step being validated
private_attr_kwargs: Keyword arguments specifying the names of private attributes for the aggregator and collaborators.
"""
agg_attrs = private_attrs_kwargs.get('aggr',[])
agg_attrs = private_attrs_kwargs.get('aggr', [])
collab_attrs = private_attrs_kwargs.get('collabs', [])
# Aggregator should only be able to access its own attributes

Expand All @@ -168,7 +168,7 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
)

# check for collaborator private attributes that should not be accessible
breached_collab_attrs = [attr for attr in collab_attrs if hasattr(self,attr)]
breached_collab_attrs = [attr for attr in collab_attrs if hasattr(self, attr)]
if breached_collab_attrs:
TestFlowPrivateAttributes.ERROR_LIST.append(
step_name + "_collaborator_attributes_found"
Expand All @@ -177,9 +177,6 @@ def validate_agg_private_attr(self, step_name, **private_attrs_kwargs):
f"{bcolors.FAIL} ... Attribute test failed in {step_name} - collaborator"
+ f"private attributes accessible:{','.join(breached_collab_attrs)} {bcolors.ENDC}"
)



for idx, collab in enumerate(self.collaborators):
# Collaborator attributes should not be accessible in aggregator step
if (
Expand All @@ -205,13 +202,13 @@ def validate_collab_private_attrs(self, step_name, **private_attrs_kwargs):
step_name: Name of the step being validated
private_attr_kwargs: Keyword arguments specifying the names of private attributes for the aggregator and collaborators.
"""
agg_attrs = private_attrs_kwargs.get('aggr',[])
agg_attrs = private_attrs_kwargs.get('aggr', [])
collab_attrs = private_attrs_kwargs.get('collabs', [])

# Collaborator should only be able to access its own attributes

# check for missing collaborators attributes
inaccessible_collab_attrs = [attr for attr in collab_attrs if not hasattr(self,attr)]
inaccessible_collab_attrs = [attr for attr in collab_attrs if not hasattr(self, attr)]

if inaccessible_collab_attrs:
TestFlowPrivateAttributes.ERROR_LIST.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def function_defined_in_notebook(some_parameter):
@TI.register_fl_task(model='model', data_loader='train_dataset',
device='device', optimizer='optimizer')
def train(model, train_dataset, optimizer, device, loss_fn=loss_fn, warmup=False):

# Iterate over the batches of the dataset.
for step, (x_batch_train, y_batch_train) in enumerate(train_dataset):
with tf.GradientTape() as tape:
Expand Down
Loading