Skip to content

Conversation

@sadielbartholomew
Copy link
Member

When running test modules e.g. test_Data under pytest (as can be done via $ pytest <test module> even though we don't strictly use pytest but unittest), I get multiple deprecation warnings on several uses of distutils.version.LooseVersion, all in cf/__init__.py:

DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    g["version"][version] = LooseVersion(version)

I have updated these here to packaging.version.Version; it actually wasn't at all clear in any of the relevant documentation as to which class from that module would be the appropriate replacement, but from doing a full-GitHub search on relevant keywords I found the following comments (this and this) and corresponding PR to xarray, along with a few other similar PRs on major libraries, to confirm that Version is the best one to go with.

Unfortunately packaging isn't a built-in, so this change prompted by the deprecation warning does necessitate another dependency, which I have added to the requirements list and documentation of those.

@davidhassell can I check with you that it is OK to add this new dependency? (I am not too pleased that an entire new dependency is required to upgrade deprecated API usage, but this is what the warning prompts us to use. If you can think of an alternative approach, do let me know...)

Copy link
Collaborator

@davidhassell davidhassell left a comment

Choose a reason for hiding this comment

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

All looks good. Thanks, Sadie.

I agree with you that we have to accept this new import. I see that it is even recommended by PEP 632, which I can hope means that it will soon be part of the standard library ...?

@sadielbartholomew
Copy link
Member Author

sadielbartholomew commented Feb 28, 2022

Thanks for confirming. I'll merge this now.

I see that it is even recommended by PEP 632, which I can hope means that it will soon be part of the standard library ...?

I'm not sure whether it will either (it was hard to find anything concrete on that from a quick-ish search) but I hope so too! I guess we'll find out eventually...

@sadielbartholomew sadielbartholomew merged commit 4f1be43 into NCAS-CMS:master Feb 28, 2022
@sadielbartholomew sadielbartholomew deleted the pytest-deprecation-warnings branch February 28, 2022 14:04
@davidhassell davidhassell added this to the 3.13.0 milestone Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants