From 8bb35348a0daea884a4cd06991fffeba2f252fbd Mon Sep 17 00:00:00 2001 From: bxdd Date: Thu, 11 Jan 2024 23:38:58 +0800 Subject: [PATCH] [MNT] add all in all init module --- .flake8 | 7 ------- .pre-commit-config.yaml | 4 ++-- learnware/client/__init__.py | 2 ++ learnware/market/__init__.py | 21 +++++++++++++++++++ learnware/market/anchor/__init__.py | 2 ++ learnware/market/easy/__init__.py | 13 ++++++++++++ learnware/market/evolve/__init__.py | 2 ++ learnware/market/evolve_anchor/__init__.py | 2 ++ learnware/market/heterogeneous/__init__.py | 2 ++ .../organizer/hetero_map/__init__.py | 3 +++ learnware/model/__init__.py | 2 ++ learnware/reuse/__init__.py | 11 ++++++++++ learnware/reuse/hetero/__init__.py | 2 ++ learnware/specification/__init__.py | 17 +++++++++++++++ learnware/specification/regular/__init__.py | 9 ++++++++ .../specification/regular/image/__init__.py | 2 ++ .../specification/regular/table/__init__.py | 2 ++ .../specification/regular/text/__init__.py | 2 ++ learnware/specification/system/__init__.py | 2 ++ learnware/tests/__init__.py | 2 ++ learnware/utils/__init__.py | 13 +++++++++++- learnware/utils/import_utils.py | 2 +- 22 files changed, 113 insertions(+), 11 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b91a117..0000000 --- a/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -max-line-length = 120 -ignore = - E203,E501,F841,W503 -per-file-ignores = - __init__.py: F401 - ./learnware/utils/import_utils.py: F401 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8443a1..0585f94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: args: ["-l 120"] - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 6.1.0 hooks: - id: flake8 - args: ["--count", "--select=E9,F63,F7,F82", "--show-source", "--statistics"] \ No newline at end of file + args: ["--ignore=E203,E501,F841,W503"] \ No newline at end of file diff --git a/learnware/client/__init__.py b/learnware/client/__init__.py index 9849835..696e6c7 100644 --- a/learnware/client/__init__.py +++ b/learnware/client/__init__.py @@ -1 +1,3 @@ from .learnware_client import LearnwareClient, SemanticSpecificationKey + +__all__ = ["LearnwareClient", "SemanticSpecificationKey"] diff --git a/learnware/market/__init__.py b/learnware/market/__init__.py index fba3552..6e9e718 100644 --- a/learnware/market/__init__.py +++ b/learnware/market/__init__.py @@ -6,3 +6,24 @@ from .evolve import EvolvedOrganizer from .evolve_anchor import EvolvedAnchoredOrganizer from .heterogeneous import HeteroMapTableOrganizer, HeteroSearcher from .module import instantiate_learnware_market + +__all__ = [ + "AnchoredOrganizer", + "AnchoredSearcher", + "AnchoredUserInfo", + "BaseChecker", + "BaseOrganizer", + "BaseSearcher", + "BaseUserInfo", + "LearnwareMarket", + "CondaChecker", + "EasyOrganizer", + "EasySearcher", + "EasySemanticChecker", + "EasyStatChecker", + "EvolvedOrganizer", + "EvolvedAnchoredOrganizer", + "HeteroMapTableOrganizer", + "HeteroSearcher", + "instantiate_learnware_market", +] diff --git a/learnware/market/anchor/__init__.py b/learnware/market/anchor/__init__.py index c453220..8125050 100644 --- a/learnware/market/anchor/__init__.py +++ b/learnware/market/anchor/__init__.py @@ -10,3 +10,5 @@ if not is_torch_available(verbose=False): logger.error("AnchoredSearcher is not available because 'torch' is not installed!") else: from .searcher import AnchoredSearcher + +__all__ = ["AnchoredOrganizer", "AnchoredUserInfo", "AnchoredSearcher"] diff --git a/learnware/market/easy/__init__.py b/learnware/market/easy/__init__.py index e2d58e5..bbedeef 100644 --- a/learnware/market/easy/__init__.py +++ b/learnware/market/easy/__init__.py @@ -8,7 +8,20 @@ if not is_torch_available(verbose=False): EasySearcher = None EasySemanticChecker = None EasyStatChecker = None + EasyExactSemanticSearcher = None + EasyFuzzSemanticSearcher = None + EasyStatSearcher = None logger.error("EasySeacher and EasyChecker are not available because 'torch' is not installed!") else: from .checker import EasySemanticChecker, EasyStatChecker from .searcher import EasyExactSemanticSearcher, EasyFuzzSemanticSearcher, EasySearcher, EasyStatSearcher + +__all__ = [ + "EasyOrganizer", + "EasySemanticChecker", + "EasyStatChecker", + "EasyExactSemanticSearcher", + "EasyFuzzSemanticSearcher", + "EasySearcher", + "EasyStatSearcher", +] diff --git a/learnware/market/evolve/__init__.py b/learnware/market/evolve/__init__.py index e0069c5..3f88349 100644 --- a/learnware/market/evolve/__init__.py +++ b/learnware/market/evolve/__init__.py @@ -1 +1,3 @@ from .organizer import EvolvedOrganizer + +__all__ = ["EvolvedOrganizer"] diff --git a/learnware/market/evolve_anchor/__init__.py b/learnware/market/evolve_anchor/__init__.py index a83cc4b..9380268 100644 --- a/learnware/market/evolve_anchor/__init__.py +++ b/learnware/market/evolve_anchor/__init__.py @@ -1 +1,3 @@ from .organizer import EvolvedAnchoredOrganizer + +__all__ = ["EvolvedAnchoredOrganizer"] diff --git a/learnware/market/heterogeneous/__init__.py b/learnware/market/heterogeneous/__init__.py index 0252b0a..4162f1d 100644 --- a/learnware/market/heterogeneous/__init__.py +++ b/learnware/market/heterogeneous/__init__.py @@ -10,3 +10,5 @@ if not is_torch_available(verbose=False): else: from .organizer import HeteroMapTableOrganizer from .searcher import HeteroSearcher + +__all__ = ["HeteroMapTableOrganizer", "HeteroSearcher"] diff --git a/learnware/market/heterogeneous/organizer/hetero_map/__init__.py b/learnware/market/heterogeneous/organizer/hetero_map/__init__.py index 47978cf..dad56c6 100644 --- a/learnware/market/heterogeneous/organizer/hetero_map/__init__.py +++ b/learnware/market/heterogeneous/organizer/hetero_map/__init__.py @@ -646,3 +646,6 @@ class TransformerMultiLayer(nn.Module): for i, mod in enumerate(self.transformer_encoder): outputs = mod(outputs, src_key_padding_mask=attention_mask) return outputs + + +__all__ = ["HeteroMap", "Trainer"] diff --git a/learnware/model/__init__.py b/learnware/model/__init__.py index 7a14cda..d237fd1 100644 --- a/learnware/model/__init__.py +++ b/learnware/model/__init__.py @@ -1 +1,3 @@ from .base import BaseModel + +__all__ = ["BaseModel"] diff --git a/learnware/reuse/__init__.py b/learnware/reuse/__init__.py index 7a8d185..ed06a70 100644 --- a/learnware/reuse/__init__.py +++ b/learnware/reuse/__init__.py @@ -21,3 +21,14 @@ else: from .feature_augment import FeatureAugmentReuser from .hetero import FeatureAlignLearnware, HeteroMapAlignLearnware from .job_selector import JobSelectorReuser + +__all__ = [ + "AlignLearnware", + "BaseReuser", + "AveragingReuser", + "EnsemblePruningReuser", + "FeatureAugmentReuser", + "FeatureAlignLearnware", + "HeteroMapAlignLearnware", + "JobSelectorReuser", +] diff --git a/learnware/reuse/hetero/__init__.py b/learnware/reuse/hetero/__init__.py index 6f8ad23..ec98d64 100644 --- a/learnware/reuse/hetero/__init__.py +++ b/learnware/reuse/hetero/__init__.py @@ -1,2 +1,4 @@ from .feature_align import FeatureAlignLearnware from .hetero_map import HeteroMapAlignLearnware + +__all__ = ["FeatureAlignLearnware", "HeteroMapAlignLearnware"] diff --git a/learnware/specification/__init__.py b/learnware/specification/__init__.py index 6f50627..82246ff 100644 --- a/learnware/specification/__init__.py +++ b/learnware/specification/__init__.py @@ -24,3 +24,20 @@ else: generate_semantic_spec, generate_stat_spec, ) + +__all__ = [ + "BaseStatSpecification", + "Specification", + "RegularStatSpecification", + "RKMEImageSpecification", + "RKMEStatSpecification", + "RKMETableSpecification", + "RKMETextSpecification", + "HeteroMapTableSpecification", + "rkme_solve_qp", + "generate_rkme_image_spec", + "generate_rkme_table_spec", + "generate_rkme_text_spec", + "generate_semantic_spec", + "generate_stat_spec", +] diff --git a/learnware/specification/regular/__init__.py b/learnware/specification/regular/__init__.py index 6227607..51c7921 100644 --- a/learnware/specification/regular/__init__.py +++ b/learnware/specification/regular/__init__.py @@ -2,3 +2,12 @@ from .base import RegularStatSpecification from .image import RKMEImageSpecification from .table import RKMEStatSpecification, RKMETableSpecification, rkme_solve_qp from .text import RKMETextSpecification + +__all__ = [ + "RegularStatSpecification", + "RKMEImageSpecification", + "RKMEStatSpecification", + "RKMETableSpecification", + "rkme_solve_qp", + "RKMETextSpecification", +] diff --git a/learnware/specification/regular/image/__init__.py b/learnware/specification/regular/image/__init__.py index 9d4374f..d043176 100644 --- a/learnware/specification/regular/image/__init__.py +++ b/learnware/specification/regular/image/__init__.py @@ -8,3 +8,5 @@ if not is_torch_available(verbose=False): logger.error("RKMEImageSpecification is not available because 'torch' is not installed!") else: from .rkme import RKMEImageSpecification + +__all__ = ["RKMEImageSpecification"] diff --git a/learnware/specification/regular/table/__init__.py b/learnware/specification/regular/table/__init__.py index 47b4aaa..d5ba01d 100644 --- a/learnware/specification/regular/table/__init__.py +++ b/learnware/specification/regular/table/__init__.py @@ -12,3 +12,5 @@ if not is_torch_available(verbose=False): ) else: from .rkme import RKMEStatSpecification, RKMETableSpecification, rkme_solve_qp + +__all__ = ["RKMEStatSpecification", "RKMETableSpecification", "rkme_solve_qp"] diff --git a/learnware/specification/regular/text/__init__.py b/learnware/specification/regular/text/__init__.py index e92360e..18f2c2d 100644 --- a/learnware/specification/regular/text/__init__.py +++ b/learnware/specification/regular/text/__init__.py @@ -8,3 +8,5 @@ if not is_torch_available(verbose=False): logger.error("RKMETextSpecification is not available because 'torch' is not installed!") else: from .rkme import RKMETextSpecification + +__all__ = ["RKMETextSpecification"] diff --git a/learnware/specification/system/__init__.py b/learnware/specification/system/__init__.py index 4c286b9..d89292a 100644 --- a/learnware/specification/system/__init__.py +++ b/learnware/specification/system/__init__.py @@ -9,3 +9,5 @@ if not is_torch_available(verbose=False): logger.error("HeteroMapTableSpecification is not available because 'torch' is not installed!") else: from .hetero_table import HeteroMapTableSpecification + +__all__ = ["SystemStatSpecification", "HeteroMapTableSpecification"] diff --git a/learnware/tests/__init__.py b/learnware/tests/__init__.py index 7ba38d5..898b2fe 100644 --- a/learnware/tests/__init__.py +++ b/learnware/tests/__init__.py @@ -1 +1,3 @@ from .utils import parametrize + +__all__ = ["parametrize"] diff --git a/learnware/utils/__init__.py b/learnware/utils/__init__.py index bde7f09..cc12acc 100644 --- a/learnware/utils/__init__.py +++ b/learnware/utils/__init__.py @@ -5,7 +5,6 @@ from .file import convert_folder_to_zipfile, read_yaml_to_dict, save_dict_to_yam from .gpu import allocate_cuda_idx, choose_device, setup_seed from .import_utils import is_torch_available from .module import get_module_by_module_path -from ..config import SystemType, get_platform def zip_learnware_folder(path: str, output_name: str): @@ -16,3 +15,15 @@ def zip_learnware_folder(path: str, output_name: str): if file.endswith(".pyc") or os.path.islink(full_path): continue zip_ref.write(full_path, arcname=os.path.relpath(full_path, path)) + + +__all__ = [ + "convert_folder_to_zipfile", + "read_yaml_to_dict", + "save_dict_to_yaml", + "allocate_cuda_idx", + "choose_device", + "setup_seed", + "is_torch_available", + "get_module_by_module_path", +] diff --git a/learnware/utils/import_utils.py b/learnware/utils/import_utils.py index 449b727..778a1a0 100644 --- a/learnware/utils/import_utils.py +++ b/learnware/utils/import_utils.py @@ -5,7 +5,7 @@ logger = get_module_logger("import_utils") def is_torch_available(verbose=False): try: - import torch + import torch # noqa: F401 except ModuleNotFoundError as err: if verbose is True: logger.warning("ModuleNotFoundError: torch is not installed, please install pytorch!")