4523: Migrate to pathlib.Path#7087
Conversation
There was a problem hiding this comment.
Templating
This PR includes changes that may be worth sharing via templating. For each file listed below, please either:
- Action the suggestion via a pull request editing/adding the relevant file in the SciTools/.github
templates/directory. 1 - Raise an issue against the SciTools/.github repo for the above action if you really don't have 10mins spare right now. Include an assignee, to avoid it being forgotten.
- Dismiss the suggestion if the changes are not suitable for templating.
You will need to dismiss this review before this PR can be merged. Recommend the reviewer does this as their final action before merging, as this text will continually update as commits come in.
Template candidates
The following changed files are not currently templated, but their parent directories suggest they may be good candidates for a new template to be created:
Footnotes
-
Include this text in the PR body to avoid any notifications about applying the template changes back to the source repo!
@scitools-templating: please no update notification on: iris↩
|
I also wanted to get some insight on the comment on templating. I'm not sure whether |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7087 +/- ##
=======================================
Coverage 90.12% 90.13%
=======================================
Files 91 91
Lines 24951 24956 +5
Branches 4683 4684 +1
=======================================
+ Hits 22488 22495 +7
+ Misses 1684 1683 -1
+ Partials 779 778 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ukmo-ccbunney
left a comment
There was a problem hiding this comment.
Hi @SgtVarmint
Thanks very much for all the hard work converting os.path to pathlib.Path 🙏🏼
I've reviewed you changes and have a few suggested changes.
| except for mo_pack. | ||
| (:issue:`6832`, :pull:`6976`) | ||
|
|
||
| #. `@SgtVarmint` _ migrated codebase from os.path to pathlib.Path where possible |
There was a problem hiding this comment.
A few syntax corrections:
| #. `@SgtVarmint` _ migrated codebase from os.path to pathlib.Path where possible | |
| #. `@SgtVarmint`_ migrated codebase from ``os.path`` to ``pathlib.Path`` where possible |
| # Given a filepath string/path : create a dataset from that | ||
| try: | ||
| self.filepath = os.path.abspath(filename) | ||
| self.filepath = Path(filename) |
There was a problem hiding this comment.
Prefer absolute path here?
| self.filepath = Path(filename) | |
| self.filepath = Path(filename).absolute() |
| if file_source.startswith("https:"): | ||
| self._filename = file_source |
There was a problem hiding this comment.
Why were these lines added?
There was a problem hiding this comment.
There was a test (lib/iris/tests/test_load.py::TestOPeNDAP::test_net_cdf_dataset_call) that runs using a web URL. Since Path() strips all double-slashes from the input string, any web URLs would fail. The lines I added were just a check whether or not the input string was a URL and set self._filename accordingly.
I'm open to any suggestions or modifications to this logic or to learning whether my assumption there is wrong.
| # len == 23 | ||
| path = "0000000000000000jan0000" | ||
|
|
||
| msg = "ABFField expects a filename of 24 characters: {}".format(path) |
There was a problem hiding this comment.
Prefer f-strings:
| msg = "ABFField expects a filename of 24 characters: {}".format(path) | |
| msg = f"ABFField expects a filename of 24 characters: {path}" |
| fromfile.assert_called_once_with(path, dtype=">u1") | ||
| assert read.call_count == 1 | ||
|
|
||
| def test_invalid_name_length(self, mocker): |
There was a problem hiding this comment.
Thanks for the extra test 👍🏼
Closes #4523 in migrating uses of os.path to pathlib.Path where possible.