From 346010f1db7260dd7696444cdfbc76da26c15330 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Mon, 30 Mar 2020 15:12:23 +0200 Subject: [PATCH] Declare public interfaces explicitly As suggested by pep8: https://www.python.org/dev/peps/pep-0008/#public-and-internal-interfaces Not doing so trips up flake8's F401, since the imports are not used. Imports are an implementation detail and should not directly be relied upon to declare the public API. Two exceptions to this are csrank/__init__.py and csrank/dataset_reader/__init__.py, where the API is too big. This will likely change in the future. See #105. --- csrank/__init__.py | 17 ++++++---- csrank/choicefunction/__init__.py | 12 +++++++ csrank/core/__init__.py | 11 +++++++ csrank/dataset_reader/__init__.py | 17 ++++++---- .../choicefunctions/__init__.py | 7 ++++ .../dataset_reader/discretechoice/__init__.py | 10 ++++++ csrank/dataset_reader/dyadranking/__init__.py | 4 +++ .../dataset_reader/labelranking/__init__.py | 5 +++ .../dataset_reader/objectranking/__init__.py | 11 +++++++ csrank/discretechoice/__init__.py | 17 ++++++++++ csrank/objectranking/__init__.py | 33 +++++++++++++------ 11 files changed, 120 insertions(+), 24 deletions(-) diff --git a/csrank/__init__.py b/csrank/__init__.py index 30eaacc8..45f9bbd0 100644 --- a/csrank/__init__.py +++ b/csrank/__init__.py @@ -1,9 +1,12 @@ __version__ = "1.1.0" -from .choicefunction import * -from .core import * -from .dataset_reader import * -from .discretechoice import * -from .objectranking import * -from .tunable import Tunable -from .tuning import ParameterOptimizer +# We should re-evaluate if we really want to re-export everything here and then +# use __all__ properly. + +from .choicefunction import * # noqa: F401 +from .core import * # noqa: F401 +from .dataset_reader import * # noqa: F401 +from .discretechoice import * # noqa: F401 +from .objectranking import * # noqa: F401 +from .tunable import Tunable # noqa: F401 +from .tuning import ParameterOptimizer # noqa: F401 diff --git a/csrank/choicefunction/__init__.py b/csrank/choicefunction/__init__.py index d3d8d3e4..41b4aff4 100644 --- a/csrank/choicefunction/__init__.py +++ b/csrank/choicefunction/__init__.py @@ -7,3 +7,15 @@ from .generalized_linear_model import GeneralizedLinearModel from .pairwise_choice import PairwiseSVMChoiceFunction from .ranknet_choice import RankNetChoiceFunction + +__all__ = [ + "AllPositive", + "CmpNetChoiceFunction", + "FATEChoiceFunction", + "FATELinearChoiceFunction", + "FETAChoiceFunction", + "FETALinearChoiceFunction", + "GeneralizedLinearModel", + "PairwiseSVMChoiceFunction", + "RankNetChoiceFunction", +] diff --git a/csrank/core/__init__.py b/csrank/core/__init__.py index f823c9d3..de98ffb3 100644 --- a/csrank/core/__init__.py +++ b/csrank/core/__init__.py @@ -5,3 +5,14 @@ from .feta_network import FETANetwork from .pairwise_svm import PairwiseSVM from .ranknet_core import RankNetCore + +__all__ = [ + "CmpNetCore", + "FATELinearCore", + "FATENetwork", + "FATENetworkCore", + "FETALinearCore", + "FETANetwork", + "PairwiseSVM", + "RankNetCore", +] diff --git a/csrank/dataset_reader/__init__.py b/csrank/dataset_reader/__init__.py index 8aed914a..9da124c6 100644 --- a/csrank/dataset_reader/__init__.py +++ b/csrank/dataset_reader/__init__.py @@ -1,7 +1,10 @@ -from .choicefunctions import * -from .discretechoice import * -from .dyadranking import * -from .expedia_dataset_reader import ExpediaDatasetReader -from .labelranking import * -from .objectranking import * -from .synthetic_dataset_generator import SyntheticIterator +# We should re-evaluate if we really want to re-export everything here and then +# use __all__ properly. + +from csrank.dataset_reader.choicefunctions import * # noqa: F401 +from csrank.dataset_reader.discretechoice import * # noqa: F401 +from csrank.dataset_reader.dyadranking import * # noqa: F401 +from csrank.dataset_reader.expedia_dataset_reader import ExpediaDatasetReader # noqa: F401 +from csrank.dataset_reader.labelranking import * # noqa: F401 +from csrank.dataset_reader.objectranking import * # noqa: F401 +from csrank.dataset_reader.synthetic_dataset_generator import SyntheticIterator # noqa: F401 diff --git a/csrank/dataset_reader/choicefunctions/__init__.py b/csrank/dataset_reader/choicefunctions/__init__.py index 8ab4162b..91ed6c1a 100644 --- a/csrank/dataset_reader/choicefunctions/__init__.py +++ b/csrank/dataset_reader/choicefunctions/__init__.py @@ -2,3 +2,10 @@ from .expedia_choice_dataset_reader import ExpediaChoiceDatasetReader from .letor_ranking_choice_dataset_reader import LetorRankingChoiceDatasetReader from .mnist_choice_dataset_reader import MNISTChoiceDatasetReader + +__all__ = [ + "ChoiceDatasetGenerator", + "ExpediaChoiceDatasetReader", + "LetorRankingChoiceDatasetReader", + "MNISTChoiceDatasetReader", +] diff --git a/csrank/dataset_reader/discretechoice/__init__.py b/csrank/dataset_reader/discretechoice/__init__.py index d29cbf8a..1aa32010 100644 --- a/csrank/dataset_reader/discretechoice/__init__.py +++ b/csrank/dataset_reader/discretechoice/__init__.py @@ -11,3 +11,13 @@ from .tag_genome_discrete_choice_dataset_reader import ( TagGenomeDiscreteChoiceDatasetReader, ) + +__all__ = [ + "DiscreteChoiceDatasetGenerator", + "ExpediaDiscreteChoiceDatasetReader", + "LetorListwiseDiscreteChoiceDatasetReader", + "LetorRankingDiscreteChoiceDatasetReader", + "MNISTDiscreteChoiceDatasetReader", + "SushiDiscreteChoiceDatasetReader", + "TagGenomeDiscreteChoiceDatasetReader", +] diff --git a/csrank/dataset_reader/dyadranking/__init__.py b/csrank/dataset_reader/dyadranking/__init__.py index 107cc75e..c0bf9bd0 100644 --- a/csrank/dataset_reader/dyadranking/__init__.py +++ b/csrank/dataset_reader/dyadranking/__init__.py @@ -1 +1,5 @@ from .sushi_dyad_ranking_dataset_reader import SushiDyadRankingDatasetReader + +__all__ = [ + "SushiDyadRankingDatasetReader", +] diff --git a/csrank/dataset_reader/labelranking/__init__.py b/csrank/dataset_reader/labelranking/__init__.py index 10f9eea6..bc96e66b 100644 --- a/csrank/dataset_reader/labelranking/__init__.py +++ b/csrank/dataset_reader/labelranking/__init__.py @@ -1,2 +1,7 @@ from .intelligent_system_group_dataset_reader import IntelligentSystemGroupDatasetReader from .survey_dataset_reader import SurveyDatasetReader + +__all__ = [ + "IntelligentSystemGroupDatasetReader", + "SurveyDatasetReader", +] diff --git a/csrank/dataset_reader/objectranking/__init__.py b/csrank/dataset_reader/objectranking/__init__.py index 0a392d06..c2dd5767 100644 --- a/csrank/dataset_reader/objectranking/__init__.py +++ b/csrank/dataset_reader/objectranking/__init__.py @@ -10,3 +10,14 @@ from .tag_genome_object_ranking_dataset_reader import ( TagGenomeObjectRankingDatasetReader, ) + +__all__ = [ + "DepthDatasetReader", + "ImageDatasetReader", + "LetorListwiseObjectRankingDatasetReader", + "SentenceOrderingDatasetReader", + "ObjectRankingDatasetGenerator", + "RCVDatasetReader", + "SushiObjectRankingDatasetReader", + "TagGenomeObjectRankingDatasetReader", +] diff --git a/csrank/discretechoice/__init__.py b/csrank/discretechoice/__init__.py index 1388f6b3..cb5ca873 100644 --- a/csrank/discretechoice/__init__.py +++ b/csrank/discretechoice/__init__.py @@ -12,3 +12,20 @@ from .paired_combinatorial_logit import PairedCombinatorialLogit from .pairwise_discrete_choice import PairwiseSVMDiscreteChoiceFunction from .ranknet_discrete_choice import RankNetDiscreteChoiceFunction + +__all__ = [ + "RandomBaselineDC", + "CmpNetDiscreteChoiceFunction", + "FATEDiscreteChoiceFunction", + "FATELinearDiscreteChoiceFunction", + "FETADiscreteChoiceFunction", + "FETALinearDiscreteChoiceFunction", + "GeneralizedNestedLogitModel", + "MixedLogitModel", + "ModelSelector", + "MultinomialLogitModel", + "NestedLogitModel", + "PairedCombinatorialLogit", + "PairwiseSVMDiscreteChoiceFunction", + "RankNetDiscreteChoiceFunction", +] diff --git a/csrank/objectranking/__init__.py b/csrank/objectranking/__init__.py index 8eeaab74..81da70c1 100644 --- a/csrank/objectranking/__init__.py +++ b/csrank/objectranking/__init__.py @@ -1,10 +1,23 @@ -from .cmp_net import CmpNet -from .expected_rank_regression import ExpectedRankRegression -from .fate_object_ranker import FATEObjectRanker -from .fatelinear_object_ranker import FATELinearObjectRanker -from .feta_object_ranker import FETAObjectRanker -from .fetalinear_object_ranker import FETALinearObjectRanker -from .list_net import ListNet -from .rank_net import RankNet -from .rank_svm import RankSVM -from .baseline import RandomBaselineRanker +from .cmp_net import CmpNet +from .expected_rank_regression import ExpectedRankRegression +from .fate_object_ranker import FATEObjectRanker +from .fatelinear_object_ranker import FATELinearObjectRanker +from .feta_object_ranker import FETAObjectRanker +from .fetalinear_object_ranker import FETALinearObjectRanker +from .list_net import ListNet +from .rank_net import RankNet +from .rank_svm import RankSVM +from .baseline import RandomBaselineRanker + +__all__ = [ + "CmpNet", + "ExpectedRankRegression", + "FATEObjectRanker", + "FATELinearObjectRanker", + "FETAObjectRanker", + "FETALinearObjectRanker", + "ListNet", + "RankNet", + "RankSVM", + "RandomBaselineRanker", +]