Skip to content

Conversation

@VeckoTheGecko
Copy link
Contributor

@VeckoTheGecko VeckoTheGecko commented Aug 12, 2024

Since Parcels uses wildcard imports in __init__.py files to bring items up to the top level namespace, the __all__ variable becomes important to limit what items are available at this level.

Some files which were wildcard imported didn't have this variable, leading to all variables not beginning with _ to bubble up to the parcels namespace.

This PR adds these __all__ variables where missing, choosing contents based on expected usecase. This PR also excludes code generation utilities from the top level namespace.

Now if we do dir(parcels) we get:

>>> dir(parcels) ['AdvectionAnalytical', 'AdvectionDiffusionEM',
'AdvectionDiffusionM1', 'AdvectionEE', 'AdvectionRK4', 'AdvectionRK45',
'AdvectionRK4_3D', 'AllParcelsErrorCodes', 'AsymmetricAttraction', 'BaseKernel',
'CGrid', 'CurvilinearSGrid', 'CurvilinearZGrid', 'DiffusionUniformKh', 'Field',
'FieldOutOfBoundError', 'FieldSamplingError', 'FieldSet', 'Geographic',
'GeographicPolar', 'GeographicPolarSquare', 'GeographicSquare', 'Grid',
'GridCode', 'GridSet', 'GridType', 'InteractionKernel', 'JITParticle', 'Kernel',
'KernelError', 'MergeWithNearestNeighbor', 'NearestNeighborWithinRange',
'NestedField', 'ParcelsRandom', 'ParticleFile', 'ParticleSet',
'RectilinearSGrid', 'RectilinearZGrid', 'ScipyInteractionParticle',
'ScipyParticle', 'StatusCode', 'TimeConverter', 'TimeExtrapolationError',
'UnitConverter', 'Variable', 'VectorField', 'XarrayDecodedFilter',
'__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__',
'__package__', '__path__', '__spec__', '__version__', '_version', 'advection',
'advectiondiffusion', 'application_kernels', 'cleanup_remove_files',
'cleanup_unload_lib', 'compilation', 'convert_to_flat_array',
'convert_xarray_time_units', 'converters', 'download_example_dataset',
'exampledata_utils', 'field', 'fieldfilebuffer', 'fieldset', 'get_cache_dir',
'get_data_home', 'get_package_dir', 'global_statics', 'grid', 'gridset',
'interaction', 'interactionkernel', 'interpolation_utils', 'kernel',
'list_example_datasets', 'logger', 'loggers', 'particle', 'particledata',
'particlefile', 'particleset', 'rng', 'statuscodes', 'timer', 'tools',
'unitconverters_map', 'version']

In v4 of parcels, we should consider whether to rework how we handle imports and what's available in this top level namespace (e.g., perhaps limiting whats available in the top level namespace to match how the tutorials use it).

Fixes #1643

@VeckoTheGecko VeckoTheGecko marked this pull request as ready for review August 12, 2024 14:02
@VeckoTheGecko VeckoTheGecko merged commit 7d2f37e into master Aug 13, 2024
@VeckoTheGecko VeckoTheGecko deleted the clean-imports branch August 13, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Cleaning up top level parcels namespace

3 participants