Skip to content

Commit

Permalink
Ensuring all classes are accessible after importing only the main PyS…
Browse files Browse the repository at this point in the history
…DM package. Closes #1124 (#1135)
  • Loading branch information
slayoo authored Sep 10, 2023
1 parent 4eb7151 commit dd31069
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
5 changes: 3 additions & 2 deletions PySDM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
PySDM offers a set of building blocks for development of atmospheric cloud
simulation systems revolving around the particle-based microphysics modelling concept
and the Super-Droplet Method algorithm ([Shima et al. 2009](http://doi.org/10.1002/qj.441))
and the Super-Droplet Method algorithm ([Shima et al. 2009](https://doi.org/10.1002/qj.441))
for numerically tackling the probabilistic representation of particle coagulation.
For an overview of PySDM, see [Bartman, Arabas et al. 2021](https://arxiv.org/abs/2103.17238).
Expand All @@ -14,7 +14,7 @@
[README.md file](https://github.com/open-atmos/PySDM/blob/master/README.md)
which also includes basic usage examples in **Python**, **Julia** and **Matlab**.
A set of more elaborate examples engineered in Python and accompanied with Jupyter
A set of more elaborate examples engineered in Python and accompanied by Jupyter
notebooks are maintained in the
[PySDM-examples package](https://github.com/open-atmos/PySDM-examples).
Expand All @@ -24,6 +24,7 @@

from pkg_resources import DistributionNotFound, VersionConflict, get_distribution

from . import environments, exporters, products
from .builder import Builder
from .formulae import Formulae
from .particulator import Particulator
Expand Down
2 changes: 2 additions & 0 deletions PySDM/dynamics/collisions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
breakup fragmentations `PySDM.dynamics.collisions.breakup_fragmentations`
"""
from PySDM.dynamics.collisions.collision import Breakup, Coalescence, Collision

from . import collision_kernels
1 change: 1 addition & 0 deletions PySDM/environments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
`PySDM.environments.parcel.Parcel`, ...
"""
from .box import Box
from .kinematic_1d import Kinematic1D
from .kinematic_2d import Kinematic2D
from .parcel import Parcel
3 changes: 3 additions & 0 deletions PySDM/initialisation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
initialisation logic, particle size spectra, sampling methods and
wet radii equilibration
"""
from . import sampling, spectra
from .discretise_multiplicities import discretise_multiplicities
from .equilibrate_wet_radii import equilibrate_wet_radii
from .init_fall_momenta import init_fall_momenta

from . import aerosol_composition # isort:skip
47 changes: 47 additions & 0 deletions tests/unit_tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
""" test ensuring that all needed __init__.py entries are in place """
import pytest

import PySDM

CLASSES = (
"Builder",
"Formulae",
"Particulator",
"attributes.chemistry.Acidity",
"attributes.physics.DryVolume",
"backends.CPU",
"backends.GPU",
"dynamics.Condensation",
"dynamics.collisions.breakup_fragmentations.AlwaysN",
"dynamics.collisions.coalescence_efficiencies.LowList1982Ec",
"dynamics.collisions.collision_kernels.Golovin",
"dynamics.terminal_velocity.RogersYau",
"environments.Box",
"environments.Kinematic1D",
"environments.Kinematic2D",
"environments.Parcel",
"exporters.VTKExporter",
"initialisation.aerosol_composition.DryAerosolMixture",
"initialisation.init_fall_momenta",
"initialisation.sampling.spectral_sampling.DeterministicSpectralSampling",
"initialisation.spectra.Lognormal",
"physics.constants_defaults",
"physics.diffusion_thermics.LoweEtAl2019",
"physics.si",
"products.size_spectral.EffectiveRadius",
)


class TestImports:
@staticmethod
@pytest.mark.parametrize("obj_path", CLASSES)
def test_imports(obj_path):
"""one can import PySDM and then access classes from submodules,
like PySDM.environments.Box, etc"""
obj = PySDM
for attr in obj_path.split("."):
obj = getattr(obj, attr)

@staticmethod
def test_classes_sorted():
assert tuple(sorted(CLASSES)) == CLASSES

0 comments on commit dd31069

Please sign in to comment.