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

clarify and update import style #1060

Open
mvesin opened this issue Mar 26, 2024 · 0 comments
Open

clarify and update import style #1060

mvesin opened this issue Mar 26, 2024 · 0 comments
Labels
candidate an individual developer submits a work request to the team (extension proposal, bug, other request)

Comments

@mvesin
Copy link
Member

mvesin commented Mar 26, 2024

As a developer want a clear and homogeneous import style in the library

  • document in CODING_RULES.md styles A. and B. are the prefered coding style for imports + remind import order
  • update the library to match these styles (cases 1. 2. 3. except optimizers.declearn that seems to be purposely written as a submodule)

See details below


We currently have a lack of homogeneity in the way we do imports from fedbiomed.

In the majority of cases we do:

A. when importing from a different module (including a submodule) use full path and "public" file names (not starting with _) to use the module's __init__.py eg

# a file not in the `logger` module
from fedbiomed.common.logger import logger

B. when importing from same module, use relative path and private file eg

# a file in fedbiomed.common.data
from ._torch_data_manager import TorchDataManager

Styles A. and B. look fine IMO, but we maybe lack a written trace in CODING_RULES.md

The thing is that we sometimes have different import styles:

  1. using full path for import from same module eg
# a file in fedbiomed.researcher.federated_workflows
from fedbiomed.researcher.federated_workflows._federated_workflow \
    import exp_exceptions, FederatedWorkflow
  1. using public files for module files when we probably intend to use private file (aggregator, strategy) eg
# in strategy/__init__.py => config to import as strategy.Strategy
__all__ = [
    "DefaultStrategy",
    "Strategy",
]
# but file is named strategy/strategy.py to import as strategy.strategy.Strategy

... and we use sometimes as submodules, sometimes not.

  1. specific case of fedbiomed.common.optimizers. Seems to be a mix of intended submodule (declearn.py) and un intended one (generic_optimizers.py optimizers.py)

Also regarding import orders we should always use:

1 - builtins
2 - third party
3 - from library source (from fedbiomed)
4 - and from module directory like from ._module

@mvesin mvesin added the candidate an individual developer submits a work request to the team (extension proposal, bug, other request) label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate an individual developer submits a work request to the team (extension proposal, bug, other request)
Projects
None yet
Development

No branches or pull requests

1 participant