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

hardwareprofile: drop ancient python2 compatibility libraries: "future" and "simplejson" #838

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

eli-schwartz
Copy link
Contributor

Two commits:

  • hardwareprofile: remove external dependency on simplejson

This uses the requests module and converts requests responses to json using requests' own .json() method on responses. For incomprehensible reasons, requests has spent about a decade using either simplejson or the standard library's json module more or less at will, and returning either one or the other exception types. They don't know why they use simplejson, we don't know why they use simplejson. In requests 3 (which will be released in the Year Of The Linux Desktop or when pigs fly, whichever one comes later) simplejson is dropped entirely.

There are innumerable issues discussing the problem on the requests bugtracker, with the general consensus being that it's better to randomly return either one of two different libraries and two different library return types in errors -- because it was historically done that way and people might be depending on it. ??????

Bugs:
psf/requests#710
psf/requests#2516
psf/requests#3052
psf/requests#4169
psf/requests#4842
psf/requests#5794
psf/requests#6084

The awkward workaround is to guarantee that requests' silent behavior of using simplejson if it is installed is forcibly triggered by forcibly depending on simplejson, and then catching the simplejson exception.

The better solution here is pretty simple: do not rely on the requests module's automatic json conversion, this is as simple as using the already-imported json module and calling json.loads() on the retrieved content.

Fixes: 1df343e
Reimplements: bb154a8

  • hardwareprofile: remove ancient "future" compatibility library for python2

Ironically, for a package that was intended to provide portability between python2 and python3, it is broken with python 3.12. A better library to use in all cases is "six".

However, mythtv requires python 3.8 for a while now. Using "future.standard_library" is a no-op other than costing a pointless import and being troublesome to actually install.

The hacky copy of six.with_metaclass included in "future" is rewritten to use the pure python3 form of a metaclass.

Part of #824

This uses the requests module and converts requests responses to json
using requests' own `.json()` method on responses. For incomprehensible
reasons, requests has spent about a decade using either simplejson or
the standard library's json module more or less at will, and returning
either one or the other exception types. They don't know why they use
simplejson, we don't know why they use simplejson. In requests 3 (which
will be released in the Year Of The Linux Desktop or when pigs fly,
whichever one comes later) simplejson is dropped entirely.

There are innumerable issues discussing the problem on the requests
bugtracker, with the general consensus being that it's better to
randomly return either one of two different libraries and two different
library return types in errors -- because it was historically done that
way and people might be depending on it. ??????

Bugs:

psf/requests#710
psf/requests#2516
psf/requests#3052
psf/requests#4169
psf/requests#4842
psf/requests#5794
psf/requests#6084

The awkward workaround is to guarantee that requests' silent behavior of
using simplejson *if it is installed* is forcibly triggered by forcibly
depending on simplejson, and then catching the simplejson exception.

The better solution here is pretty simple: do not rely on the requests
module's automatic json conversion, this is as simple as using the
already-imported json module and calling json.loads() on the retrieved
content.

Fixes: 1df343e
Reimplements: bb154a8
…thon2

Ironically, for a package that was intended to provide portability
between python2 and python3, it is broken with python 3.12. A better
library to use in all cases is "six".

However, mythtv requires python 3.8 for a while now. Using
"future.standard_library" is a no-op other than costing a pointless
import and being troublesome to actually install.

The hacky copy of six.with_metaclass included in "future" is rewritten
to use the pure python3 form of a metaclass.
@eli-schwartz eli-schwartz changed the title Hardwareprofile stdlib hardwareprofile: drop ancient python2 compatibility libraries: "future" and "simplejson" Jan 8, 2024
@rcrdnalor rcrdnalor merged commit 4b5eac8 into MythTV:master Jan 8, 2024
8 checks passed
@eli-schwartz eli-schwartz deleted the hardwareprofile-stdlib branch January 8, 2024 19:10
gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Jan 9, 2024
In particular, "future" is terribly unfortunate python2 stuff that
blocks bumping PYTHON_COMPAT to python3_12.

Fixed upstream in MythTV/mythtv#838 and
backported here.

Closes: https://bugs.gentoo.org/888291
Signed-off-by: Eli Schwartz <[email protected]>
Signed-off-by: Sam James <[email protected]>
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