-
Notifications
You must be signed in to change notification settings - Fork 97
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
Avoid use of deprecated function in distro module. #248
Conversation
Recent versions of the distro module have deprecated the `distro.linux_distribution()` which is a compatibility shim for the `platform.linux_distribution()` function removed in python 3.8. All versions of the distro library going back to at least 1.0.1[1] packaged in Ubuntu Bionic[2] provide the `id`, `version`, and `codename` methods which are recommended instead. `distro.id()` is used instead of `distro.name()` corresponding with the full_distribution_name=0 argument to `linux_distribution`. When updating the tests to support this change I noticed that the mocks were being added in such a way that the `dist` conditional branch would never actually be tested. I didn't actually look at how far back we'd have to go to find a platform module which did not support `linux_distribution` but it made sense to at least make testing that branch possible. We'll have to take care that the `codename` member of the tuple continues to match what our scripts expect downstream since the tests mock the distro return values we don't have full coverage of the actual results on contemporary platforms. [1]: https://github.com/python-distro/distro/blob/v1.0.1/ [2]: https://packages.ubuntu.com/bionic/python3-distro
319441f
to
8375657
Compare
I had to do some work in #241 (comment) to convince myself that aside from getting us away from a deprecated function this also fixes that issue. At least in all known situations it resolves that issue as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spearheading the development and testing on this one.
At @cottsay's prompting I went a little further back and found that there are some cases in older versions of distro where codename isn't what we want.
I ran an extra test using the packaged version of I'm going to update this PR to require distro>=1.4.0 which is when codename first started returning the symbolic name rather than the full nickname. |
The `distro.codename()` function in prior versions returned the "full nickname / codename" on Ubuntu. For example "Bionic Beaver" instead of "bionic". All supported distributions which package python3 >= 3.8 also package python3-distro >= 1.4.0 so this should not actually change anything and is added as a precaution.
Recent versions of the distro module have deprecated the
distro.linux_distribution()
which is a compatibility shim for theplatform.linux_distribution()
function removed in python 3.8.All versions of the distro library going back to at least 1.0.11 packaged in Ubuntu Bionic2 provide the
id
,version
, andcodename
methods which are recommended instead.distro.id()
is used instead ofdistro.name()
corresponding with the full_distribution_name=0 argument tolinux_distribution
.When updating the tests to support this change I noticed that the mocks were being added in such a way that the
dist
conditional branch would never actually be tested. I didn't actually look at how far back we'd have togo to find a platform module which did not support
linux_distribution
but it made sense to at least make testing that branch possible.We'll have to take care that the
codename
member of the tuple continues to match what our scripts expect downstream since the tests mock the distro return values we don't have full coverage of the actual results on contemporary platforms.Closes #241