Skip to content

Commit

Permalink
Set __all__
Browse files Browse the repository at this point in the history
1. Avoids littering the namespace on star imports more than necessary
2. Simplifies cross-references to documentation,
   e.g., in addition to `petab_select.problem.Problem`, we can also
   now reference `petab_select.Problem`. This wasn't possible before.
  • Loading branch information
dweindl committed Dec 16, 2023
1 parent 7c71053 commit 89061fe
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 1 deletion.
8 changes: 8 additions & 0 deletions petab_select/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Model selection extension for PEtab."""

import sys

from .candidate_space import *
from .constants import *
from .criteria import *
Expand All @@ -9,3 +11,9 @@
from .model_subspace import *
from .problem import *
from .ui import *

__all__ = [
x
for x in dir(sys.modules[__name__])
if not x.startswith('_') and x != 'sys'
]
11 changes: 11 additions & 0 deletions petab_select/candidate_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
from .handlers import TYPE_LIMIT, LimitHandler
from .model import Model, default_compare

__all__ = [
'BackwardCandidateSpace',
'BidirectionalCandidateSpace',
'BruteForceCandidateSpace',
'CandidateSpace',
'FamosCandidateSpace',
'ForwardAndBackwardCandidateSpace',
'ForwardCandidateSpace',
'LateralCandidateSpace',
]


class CandidateSpace(abc.ABC):
"""A base class for collecting candidate models.
Expand Down
10 changes: 10 additions & 0 deletions petab_select/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for the PEtab Select package."""
import sys
from enum import Enum
from pathlib import Path
from typing import Dict, List, Literal, Union
Expand Down Expand Up @@ -164,3 +165,12 @@ class Criterion(str, Enum):
Method.FORWARD,
Method.FORWARD_AND_BACKWARD,
]


__all__ = [
x
for x in dir(sys.modules[__name__])
if not x.startswith('_')
and x not in ('sys', "Enum", "Path", "Dict", "List", "Literal", "Union")
]
print(__all__)
7 changes: 6 additions & 1 deletion petab_select/criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

from .constants import PETAB_PROBLEM, Criterion # LH,; LLH,; NLLH,

# from .model import Model
__all__ = [
'calculate_aic',
'calculate_aicc',
'calculate_bic',
'CriterionComputer',
]


# use as attribute e.g. `Model.criterion_computer`?
Expand Down
10 changes: 10 additions & 0 deletions petab_select/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
TYPE_PARAMETER_OPTIONS,
)

__all__ = [
'hashify',
'hash_parameter_dict',
'hash_parameter_options',
'hash_str',
'hash_list',
'snake_case_to_camel_case',
'parameter_string_to_value',
]


def hashify(x: Any) -> str:
"""Generate a hash.
Expand Down
7 changes: 7 additions & 0 deletions petab_select/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
)
from .petab import PetabMixin

__all__ = [
'Model',
'default_compare',
'models_from_yaml_list',
'models_to_yaml_list',
]


class Model(PetabMixin):
"""A (possibly uncalibrated) model.
Expand Down
7 changes: 7 additions & 0 deletions petab_select/model_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
from .model import Model
from .model_subspace import ModelSubspace

__all__ = [
"ModelSpace",
"get_model_space_df",
"read_model_space_file",
"write_model_space_df",
]


def read_model_space_file(filename: str) -> TextIO:
"""Read a model space file.
Expand Down
4 changes: 4 additions & 0 deletions petab_select/model_subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from .model import Model
from .petab import PetabMixin

__all__ = [
'ModelSubspace',
]


class ModelSubspace(PetabMixin):
"""Efficient representation of exponentially large model subspaces.
Expand Down
4 changes: 4 additions & 0 deletions petab_select/petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

from .constants import PETAB_ESTIMATE_FALSE, TYPE_PARAMETER_DICT, TYPE_PATH

__all__ = [
'PetabMixin',
]


class PetabMixin:
"""Useful things for classes that contain a PEtab problem.
Expand Down
4 changes: 4 additions & 0 deletions petab_select/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from .model import Model, default_compare
from .model_space import ModelSpace

__all__ = [
'Problem',
]


class Problem(abc.ABC):
"""Handle everything related to the model selection problem.
Expand Down
8 changes: 8 additions & 0 deletions petab_select/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
from .model import Model, default_compare
from .problem import Problem

__all__ = [
'candidates',
'model_to_petab',
'models_to_petab',
'best',
'write_summary_tsv',
]


def candidates(
problem: Problem,
Expand Down

0 comments on commit 89061fe

Please sign in to comment.