Skip to content

Commit

Permalink
certifi: Patch to work under Python 2.
Browse files Browse the repository at this point in the history
certifi being only Python3 breaks a lot of Python 2 packages via the
requests packages. Patch the library to work under Python 2.
  • Loading branch information
clefru committed Jul 3, 2021
1 parent f537707 commit 57e65ad
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkgs/development/python-modules/certifi/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ lib
, buildPythonPackage
, isPy27
, fetchFromGitHub
, pytestCheckHook
}:
Expand All @@ -9,15 +8,17 @@ buildPythonPackage rec {
pname = "certifi";
version = "2021.05.30";

disabled = isPy27;

src = fetchFromGitHub {
owner = pname;
repo = "python-certifi";
rev = version;
sha256 = "1i4ljsc47iac6kl1w4w6x0qia08s9z394z9lbyzc05pm7y8a3cmj";
};

patches = [
./reenable-python2.diff
./read-file-for-python2.diff
];
checkInputs = [
pytestCheckHook
];
Expand Down
20 changes: 20 additions & 0 deletions pkgs/development/python-modules/certifi/read-file-for-python2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/certifi/core.py b/certifi/core.py
index 5d2b8cd..3261f82 100644
--- a/certifi/core.py
+++ b/certifi/core.py
@@ -45,8 +45,13 @@ except ImportError:
# so won't address issues with environments like PyOxidizer that don't set
# __file__ on modules.
def read_text(_module, _path, encoding="ascii"):
- with open(where(), "r", encoding=encoding) as data:
- return data.read()
+ try:
+ with open(where(), "r", encoding=encoding) as data:
+ return data.read()
+ except TypeError:
+ # Read under Python2.7
+ with open(where(), "r") as data:
+ return data.read()

# If we don't have importlib.resources, then we will just do the old logic
# of assuming we're on the filesystem and munge the path directly.
33 changes: 33 additions & 0 deletions pkgs/development/python-modules/certifi/reenable-python2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/README.rst b/README.rst
index 182b511..9704bcb 100644
--- a/README.rst
+++ b/README.rst
@@ -21,12 +21,12 @@ built-in function::
>>> import certifi

>>> certifi.where()
- '/usr/local/lib/python3.7/site-packages/certifi/cacert.pem'
+ '/usr/local/lib/python2.7/site-packages/certifi/cacert.pem'

Or from the command line::

$ python -m certifi
- /usr/local/lib/python3.7/site-packages/certifi/cacert.pem
+ /usr/local/lib/python2.7/site-packages/certifi/cacert.pem

Enjoy!

diff --git a/setup.py b/setup.py
index 69ec098..cadf7ff 100755
--- a/setup.py
+++ b/setup.py
@@ -54,6 +54,9 @@ setup(
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Natural Language :: English',
'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',

0 comments on commit 57e65ad

Please sign in to comment.