Merge ~lvoytek/ubuntu/+source/requests:remove-charset-normalizer into ubuntu/+source/requests:ubuntu/devel

Proposed by Lena Voytek
Status: Merged
Approved by: git-ubuntu bot
Approved revision: not available
Merged at revision: 44faf7c346de59d3f5917aef108d077d7946bcbf
Proposed branch: ~lvoytek/ubuntu/+source/requests:remove-charset-normalizer
Merge into: ubuntu/+source/requests:ubuntu/devel
Diff against target: 120 lines (+99/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/remove-charset-normalizer-dependency.patch (+91/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Christian Ehrhardt (community) Approve
git-ubuntu bot Approve
Bryce Harrington (community) Approve
Canonical Server Pending
Review via email: mp+423203@code.launchpad.net

Description of the change

Added charset-normalizer as an alternative dependency to chardet so it won't be included with dh_python3 / ${python3:Depends}. Since charset-normalizer is in universe it was blocking the new version of requests in main. Luckily it is just used as a backup for chardet which is in main, so making it an alternative doesn't break request's functionality.

PPA: ppa:lvoytek/requests-remove-charset-normalizer

Tested with:

# lxc launch images:ubuntu/kinetic test-requests
# lxc exec test-requests bash
# apt update && apt dist-upgrade -y
# apt install python3-requests
# apt install software-properties-common
# add-apt-repository ppa:lvoytek/requests-remove-charset-normalizer
# apt update && apt upgrade -y

To post a comment you must log in.
Revision history for this message
Christian Ehrhardt (paelzer) wrote :

Hi,
an inline suggestion and an idea at an - hopefully easier to maintain, maybe even upstreamable - alternative:

AFAIU this is added by dh_python as it is referenced in the code.

Have you tried adding them explicitly with an or (without any code change).
The assumption (needs to be tested) would be that by being listed already they'd not be re-added.
And by being an alternate dependency starting with the one in universe it should be ok.

like d/control with the only change being:
Depends: python3-charset | python3-charset-normalizer

Revision history for this message
Lena Voytek (lvoytek) wrote :

The ppa finally finished building and I was able to confirm that your suggestion works properly. Thanks @paelzer!

Revision history for this message
Bryce Harrington (bryce) wrote :

I notice the changelog mentions "d/p/remove-charset-normalizer-dependency.patch" but there are no patches; should this rather be "d/control: " or was there supposed to be a patch?

Also, one thing I'm unclear on is the changelog description says it's removing python3-charset-normalizer, yet the diff actually is adding it as an alternative dependency. Not that it's wrong technically, just the description of the change and the actual change seem inconsistent?

review: Needs Fixing
Revision history for this message
Lena Voytek (lvoytek) wrote :

Ah thanks for catching that, I completely forgot to change the file name. I'll update the description too. Both were just leftovers from my previous iteration of the fix.

Revision history for this message
Bryce Harrington (bryce) wrote :

Ok, looks good. Do you want to wait for Christian to get back, to get his approval as well?
If not, and you need sponsorship I can handle that today, just let me know.

review: Approve
Revision history for this message
Lena Voytek (lvoytek) :
Revision history for this message
Christian Ehrhardt (paelzer) wrote :

Do you already have a PPA or a buildlog of a local build that shows the "no more auto-added" dependencies?

Revision history for this message
Christian Ehrhardt (paelzer) wrote :

This is not what I meant :-)
The current proposal is to add this to the build-depends which should have no direct influence onto the final dependencies of the binary package.

The package in main is "python3-requests"

And after build with this change I still see:
...
python3-requests_2.27.1+dfsg-1ubuntu2~kineticppa1_all.deb
...
Depends: python3-certifi, python3-charset-normalizer (>= 2.0.0), python3-idna, python3-urllib3 (>= 1.21.1), python3:any, ca-certificates, python3-chardet (>= 3.0.2)

There is no change, the package still depends on python3-charset-normalizer.
I tried a few more things in the place where I had hoped it would work.

We know that it comes from dh_python into ${python3:Depends} and you can list a dependency only once. So the idea was to move down the substvar and list it before as an alternative.

Something like:
@@ -28,12 +28,13 @@ Package: python3-requests
 Architecture: all
 Multi-Arch: foreign
 Depends:
- ${misc:Depends},
- ${python3:Depends},
  ca-certificates,
  python3-certifi,
  python3-chardet (>= 3.0.2),
  python3-urllib3 (>= 1.21.1),
+ python3-chardet (>= 3.0.2) | python3-charset-normalizer (>= 2.0.0),
+ ${python3:Depends},
+ ${misc:Depends},
 Suggests:
  python3-cryptography,
  python3-idna (>= 2.5),

But even that didn't work, so I guess dh_python does not want to be tricked here.
It really means you should go back to your initial approach of disabling it for real :-/

But out of this - the fact to check after build are:
- the final binary python3-requests shall no more depend on python3-charset-normalizer
- python3-requests shall still work fine and not suffer from only having one of those packages

Revision history for this message
git-ubuntu bot (git-ubuntu-bot) wrote :

Approvers: bryce, lvoytek
Uploaders: bryce
MP auto-approved

review: Approve
Revision history for this message
Lena Voytek (lvoytek) wrote :

re-added the patch file, confirmed the dependency is gone using
ppa:lvoytek/requests-remove-charset-normalizer

# lxc launch images:ubuntu/kinetic test-requests
# lxc exec test-requests bash
# apt update && apt dist-upgrade -y
# apt install python3-requests
# apt install software-properties-common
# add-apt-repository ppa:lvoytek/requests-remove-charset-normalizer
# apt update && apt upgrade -y
# apt depends python3-requests
python3-requests
  Depends: python3-certifi
  Depends: python3-chardet (>= 3.0.2)
  Depends: python3-idna
  Depends: python3-urllib3 (>= 1.21.1)
  Depends: <python3:any>
    python3
  Depends: ca-certificates
  Breaks: awscli (<< 1.11.139)
  Suggests: python3-cryptography
  Suggests: python3-idna (>= 2.5)
  Suggests: python3-openssl
  Suggests: python3-socks
  Suggests: python-requests-doc

Revision history for this message
Christian Ehrhardt (paelzer) wrote :

The package isn't updated too often (for example I & J have the same version).
Nevertheless with this change this converts into regular work to merge.

Approving and uploading ... for now.
Since ubuntu1 is stuck in proposed I've uploaded with -v2.27.1+dfsg-1

Uploading requests_2.27.1+dfsg-1ubuntu2.dsc
Uploading requests_2.27.1+dfsg-1ubuntu2.debian.tar.xz
Uploading requests_2.27.1+dfsg-1ubuntu2_source.buildinfo
Uploading requests_2.27.1+dfsg-1ubuntu2_source.changes

I first wanted to ask you if you want to try submitting an "if ubuntu then ..." variant to Debian.
But then I realized the versions on the upstream code:

+- 'charset_normalizer~=2.0.0; python_version >= "3"',
+- 'chardet>=3.0.2,<5; python_version < "3"',
++ 'chardet>=3.0.2,<5',

That is usually a sign of a transition that will stay e.g. for py3 we want to use the newer more than the older. I checked upstream and it showed me:

https://github.com/psf/requests/commit/2ed84f55b22f19a1e1e8eea2e50963dce62052d3

Ok, this added charset_normalizer but with the fallback which we are now utilizing.
But then there is also:

https://github.com/psf/requests/commit/8bce583b9547c7b82d44c8e97f37cf9a16cbe758

Which makes it normalizer only for the coming version 2.28.
I think the proposed fix is fine as a stop-gap for now on 2.27.
But mid term we will need charset-normalizer in main, so we should start the MIR process right away to be ready.

Sadly there are other dependencies that will keep chardet in main at the same time.
So far it was python3-bs4 + python3-debian + python3-requests.
And AFAICS neither bs4 not pdebian seem to move, so despite the similarity we might end up needing both in main OR keep delta on either bs4+pdebian or requests.

Please track the migration of the upload, but also consider starting the MIR unless we find a better way.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 92eed73..8ccbead 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+requests (2.27.1+dfsg-1ubuntu2) kinetic; urgency=medium
7+
8+ * d/p/remove-charset-normalizer-dependency.patch: Remove charset-normalizer
9+ as a dependency of requests (LP: #1975541)
10+
11+ -- Lena Voytek <lena.voytek@canonical.com> Mon, 23 May 2022 15:06:07 -0700
12+
13 requests (2.27.1+dfsg-1ubuntu1) kinetic; urgency=medium
14
15 * Fix autopkgtest when http_proxy, https_proxy or no_proxy variable is set
16diff --git a/debian/patches/remove-charset-normalizer-dependency.patch b/debian/patches/remove-charset-normalizer-dependency.patch
17new file mode 100644
18index 0000000..5d4a598
19--- /dev/null
20+++ b/debian/patches/remove-charset-normalizer-dependency.patch
21@@ -0,0 +1,91 @@
22+Description: Remove charset-normalizer package as a backup to chardet
23+ Since requests can use either chardet or charset-normalizer for character set
24+ interpretations, and charset-normalizer is in universe, remove it as a
25+ dependency to keep requests in main without issues.
26+Forwarded: not-needed
27+X-Not-Forwarded-Reason: charset-normalizer being in universe is Ubuntu-specific
28+Author: Lena Voytek <lena.voytek@canonical.com>
29+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/requests/+bug/1975541
30+Last-Update: 2022-05-23
31+---
32+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
33+--- a/requests/packages.py
34++++ b/requests/packages.py
35+@@ -1,12 +1,5 @@
36+ import sys
37+-
38+-try:
39+- import chardet
40+-except ImportError:
41+- import charset_normalizer as chardet
42+- import warnings
43+-
44+- warnings.filterwarnings('ignore', 'Trying to detect', module='charset_normalizer')
45++import chardet
46+
47+ # This code exists for backwards compatibility reasons.
48+ # I don't like it either. Just look the other way. :)
49+--- a/requests/compat.py
50++++ b/requests/compat.py
51+@@ -8,11 +8,7 @@
52+ Python 3.
53+ """
54+
55+-try:
56+- import chardet
57+-except ImportError:
58+- import charset_normalizer as chardet
59+-
60++import chardet
61+ import sys
62+
63+ # -------
64+--- a/setup.py
65++++ b/setup.py
66+@@ -41,8 +41,7 @@
67+ packages = ['requests']
68+
69+ requires = [
70+- 'charset_normalizer~=2.0.0; python_version >= "3"',
71+- 'chardet>=3.0.2,<5; python_version < "3"',
72++ 'chardet>=3.0.2,<5',
73+ 'idna>=2.5,<3; python_version < "3"',
74+ 'idna>=2.5,<4; python_version >= "3"',
75+ 'urllib3>=1.21.1,<1.27',
76+--- a/requests/help.py
77++++ b/requests/help.py
78+@@ -11,10 +11,7 @@
79+
80+ from . import __version__ as requests_version
81+
82+-try:
83+- import charset_normalizer
84+-except ImportError:
85+- charset_normalizer = None
86++charset_normalizer = None
87+
88+ try:
89+ import chardet
90+@@ -113,7 +110,7 @@
91+ 'implementation': implementation_info,
92+ 'system_ssl': system_ssl_info,
93+ 'using_pyopenssl': pyopenssl is not None,
94+- 'using_charset_normalizer': chardet is None,
95++ 'using_charset_normalizer': False,
96+ 'pyOpenSSL': pyopenssl_info,
97+ 'urllib3': urllib3_info,
98+ 'chardet': chardet_info,
99+--- a/requests/__init__.py
100++++ b/requests/__init__.py
101+@@ -44,10 +44,7 @@
102+ import warnings
103+ from .exceptions import RequestsDependencyWarning
104+
105+-try:
106+- from charset_normalizer import __version__ as charset_normalizer_version
107+-except ImportError:
108+- charset_normalizer_version = None
109++charset_normalizer_version = None
110+
111+ try:
112+ from chardet import __version__ as chardet_version
113diff --git a/debian/patches/series b/debian/patches/series
114index 5bde12d..81e1af9 100644
115--- a/debian/patches/series
116+++ b/debian/patches/series
117@@ -1,2 +1,3 @@
118 0001-Remove-remote-images-traking-code-and-ads.patch
119 0002-Fix-tests-with-HTTP-proxy.patch
120+remove-charset-normalizer-dependency.patch

Subscribers

People subscribed via source and target branches