Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all file-load code into iris.io.loading. #6199

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pp-mo
Copy link
Member

@pp-mo pp-mo commented Oct 28, 2024

Refactor to co-locate all the iris loading into a separate module, for simpler organisation + easier maintenance,
(including + mostly triggered by recent additions as per #6168)

@pp-mo pp-mo linked an issue Oct 28, 2024 that may be closed by this pull request
@pp-mo pp-mo marked this pull request as ready for review October 28, 2024 18:22
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

Attention: Patch coverage is 94.64286% with 9 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@dd29017). Learn more about missing BASE report.
Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
lib/iris/io/loading.py 94.57% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6199   +/-   ##
=======================================
  Coverage        ?   89.88%           
=======================================
  Files           ?       89           
  Lines           ?    23319           
  Branches        ?     4338           
=======================================
  Hits            ?    20960           
  Misses          ?     1628           
  Partials        ?      731           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

LOAD_POLICY = LoadPolicy()


def _combine_cubes(cubes, options, merge_require_unique):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ultimately where we want the public function _combine_cubes to live? I could see an argument for some of this code belonging in a separate file like _merge.py or _concatenate.py.

Copy link
Member Author

@pp-mo pp-mo Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for separation of concerns we could do that. So we could separate out the 'combine' operation from iris.io.loading to create an iris.combine, if that seems preferable.
But as it's private for now, that doesn't really affect this PR.

Note that theiris._merge and iris._concatenate modules are private, so the public access to these is only through the CubeList methods.
The follow-on PR currently proposes to add CubeList.combine[_cubes] methods, but it does also publish the main function as iris.io.loading.combine_cubes.
We can change that, but I'd prefer to address it separately.
I don't think this would affect the new iris.io.loading module, : that would anyway still have a place, since it contains the main load_xxx functions (and supporting routines).

Copy link
Contributor

@stephenworsley stephenworsley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looking good, my main concern here is a question about the structure of iris.io.

#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Loading mechanism and functions."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this naming convention of iris.io.loading make sense with respect to the existing structure of iris.io? I notice that iris.io.__init__ contains several load functions (e.g. load_files). Would it make sense to move this code also into iris.io.loading or is there some module name which would better explain the separation of these functions?

@@ -36,7 +36,7 @@ def test_callable_function(self):
import iris

result = _qualname(iris.load)
self.assertEqual(result, "iris.load")
self.assertEqual(result, "iris.io.loading.load")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this has now been changed so that self.assertEqual(x, y) is replaced by assert x == y.

import os.path
import threading
from typing import Callable, Literal, Mapping
from typing import Callable, Literal

import iris._constraints
import iris.config
import iris.io
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice now that the only place iris.io is being called is the line save = iris.io.save. Would it not make more sense to replace this with from iris.io import save?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Move #6168 code to iris.io.loading submodule
2 participants