diff --git a/setup.cfg b/setup.cfg index 886f95ce82..5874a2e513 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,16 @@ [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 @@ -13,7 +18,22 @@ per-file-ignores = 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 diff --git a/tests/github/experimental/workspace/testcase_private_attributes/src/testflow_privateattributes.py b/tests/github/experimental/workspace/testcase_private_attributes/src/testflow_privateattributes.py index 1f76015b45..d59f9b1100 100644 --- a/tests/github/experimental/workspace/testcase_private_attributes/src/testflow_privateattributes.py +++ b/tests/github/experimental/workspace/testcase_private_attributes/src/testflow_privateattributes.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 ( @@ -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( diff --git a/tests/github/experimental/workspace/testcase_private_attributes_initialization_with_both_options/src/testflow_privateattributes.py b/tests/github/experimental/workspace/testcase_private_attributes_initialization_with_both_options/src/testflow_privateattributes.py index 49127fef0d..70a600a2e7 100644 --- a/tests/github/experimental/workspace/testcase_private_attributes_initialization_with_both_options/src/testflow_privateattributes.py +++ b/tests/github/experimental/workspace/testcase_private_attributes_initialization_with_both_options/src/testflow_privateattributes.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 ( @@ -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( diff --git a/tests/github/experimental/workspace/testcase_private_attributes_initialization_without_callable/src/testflow_privateattributes.py b/tests/github/experimental/workspace/testcase_private_attributes_initialization_without_callable/src/testflow_privateattributes.py index 5ce49505c6..f9888657b0 100644 --- a/tests/github/experimental/workspace/testcase_private_attributes_initialization_without_callable/src/testflow_privateattributes.py +++ b/tests/github/experimental/workspace/testcase_private_attributes_initialization_without_callable/src/testflow_privateattributes.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 ( @@ -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( diff --git a/tests/github/interactive_api_director/experiments/tensorflow_mnist/experiment.py b/tests/github/interactive_api_director/experiments/tensorflow_mnist/experiment.py index 1e687f6475..ec7bed09da 100644 --- a/tests/github/interactive_api_director/experiments/tensorflow_mnist/experiment.py +++ b/tests/github/interactive_api_director/experiments/tensorflow_mnist/experiment.py @@ -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: