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

Standardize linting and formatting #980

Merged
merged 10 commits into from
Jun 7, 2024
Merged

Standardize linting and formatting #980

merged 10 commits into from
Jun 7, 2024

Conversation

MasterSkepticista
Copy link
Collaborator

@MasterSkepticista MasterSkepticista commented May 30, 2024

Note: This PR only impacts openfl.experimental namespace, and should be a non-breaking change.

Changes:

  • Sorted imports using isort
  • Formatted files using black
  • Linted using flake8

Configuration for isort and black is included in pyproject.toml. flake8 continues to use setup.cfg

For future development:

  • Lint using ./shell/lint.sh
  • Format using ./shell/format.sh
  • Use absolute imports as discussed here.

Copy link
Contributor

@psfoley psfoley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MasterSkepticista. Looks like there's just a couple remaining lint issues before approval. Will the namex changes be included in a future PR?

@MasterSkepticista
Copy link
Collaborator Author

Yes, this PR is for non-breaking formatting changes. namex will impact API surface, and may impact project structure. That will be for a future PR.

Signed-off-by: Shah, Karan <[email protected]>
@MasterSkepticista
Copy link
Collaborator Author

@psfoley Added relevant ignores in setup.cfg

Could not get rid of F821 without invoking other warnings. noqa: # does not seem to work with multi-line code.
How does ModelHeader and TensorProto not throw an error when code reaches there? The error is valid, no definitions for those are imported anywhere in the file.

from .federated_runtime import FederatedRuntime

from .local_runtime import LocalRuntime
from .runtime import Runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the import order is leading to this circular import error (confirmed this by changing the order manually locally on develop, which is passing). This should either be reverted or fixed: https://github.com/securefederatedai/openfl/actions/runs/9381169993/job/25829824994?pr=980#step:5:19

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since __init__.py files are useful for API exports, until we transition to API export decorators, we need to:

  • Export classes using absolute paths:
# Before (order-sensitive, fails)
from .federated_runtime import FederatedRuntime
from .local_runtime import LocalRuntime
from .runtime import Runtime
__all__ = ["FederatedRuntime", "LocalRuntime", "Runtime"]

# After (order-agnostic)
from openfl.experimental.runtime.federated_runtime import FederatedRuntime
from openfl.experimental.runtime.local_runtime import LocalRuntime
from openfl.experimental.runtime.runtime import Runtime
  • Use absolute imports in source code:
# Before (order sensitive, fails)
from openfl.experimental.runtime import Runtime

# After (order-agnostic)
from openfl.experimental.runtime.runtime import Runtime

This gives the intended behavior: users can access imported objects without long paths in user code, and order of imports within source code does not lead to errors.

This fix will be used for all subsequent tests.

@MasterSkepticista
Copy link
Collaborator Author

Fixed imports in the entire openfl.experimental interface.

@psfoley psfoley merged commit d00db45 into securefederatedai:develop Jun 7, 2024
23 of 26 checks passed
manuelhsantana pushed a commit that referenced this pull request Jul 10, 2024
* [openfl.experimental] Sort imports

Signed-off-by: Shah, Karan <[email protected]>

* [openfl.experimental] Format using flake8

Signed-off-by: Shah, Karan <[email protected]>

* [openfl.experimental] Sort imports in black profile

Signed-off-by: Shah, Karan <[email protected]>

* [openfl.experimental] Format using black and lint with flake8

Signed-off-by: Shah, Karan <[email protected]>

* [openfl.experimental] Add scripts for lint and format

Signed-off-by: Shah, Karan <[email protected]>

* Update flake8 ignores

Signed-off-by: Shah, Karan <[email protected]>

* Update contribution guidelines

Signed-off-by: Shah, Karan <[email protected]>

* Ignore flake8 unused import warnings in __init__.py

Signed-off-by: Shah, Karan <[email protected]>

* Fix circular import using absolute imports

Signed-off-by: Shah, Karan <[email protected]>

* [openfl.experimental] Use absolute imports

Signed-off-by: Shah, Karan <[email protected]>

---------

Signed-off-by: Shah, Karan <[email protected]>
@MasterSkepticista MasterSkepticista deleted the karansh1/documentation branch July 10, 2024 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants