[PATCH] introduce a virtual imaplib2 (was: Separate imaplib2 from offlineimap)

Nicolas Sebrecht nicolas.s-dev at laposte.net
Sat Jun 4 01:04:07 BST 2016


On Fri, Jun 03, 2016 at 08:26:07PM +0200, Łukasz Żarnowiecki wrote:

> Hi Nicolas,

Hi Łukasz,

> I was searching through mailing listing archive and I could not find a
> subject that would raised that kind of an issue.
> 
> The idea is to separate imaplib2 from offlineimap.  The only real
> advantage is that we do not need to update offlineimap repository to
> reflect changes in imaplib2.

This is a little advantage. imaplib2 is moving slowly. At least, not as
fast as offlineimap.

There are serious downsides, though:

- Offlineimap can run without outside dependency since the beginning and
  I know users expect it to work like this: download the zip and run.

- This will require us to handle bugs for different imaplib2 versions.
  This means more maintenance tasks.

>                               I am going to introduce some compatibility
> patches in the near future.

So, you need a feature to work on your own local imaplib2 library.

>                              Also it could be beneficial for distros as
> the users could use that library for some other things without need to
> polling it and having installed twice.

I'm not aware of only one other software packaged in distributions and
using imaplib2 in most distributions.

>                                         Of course it would initially
> require some more work for maintainers, despite the fact that packaging
> imaplib2 would be probably very easy.

Distributions wanting to package imaplib2 outside of offlineimap already
do this. Until now, this job has not been as good as what we provide in
this area.

> If you are interested I will send you patches.

I think we can find a consensus with the following patch. I understand
people wanting offlineimap to work with any external imaplib2 should be
allowed to do it.

The following changes since commit d848141b391c3480745392f68c9bfd5d5fcf472b:

  mark Python 3 supported and experimental (2016-06-03 20:07:15 +0200)

are available in the git repository at:

  https://github.com/nicolas33/offlineimap.git virtual_imaplib2

for you to fetch changes up to ec18b0a8a320cb7d930e30ad294ef64ee1c5fc24:

  introduce a virtual imaplib2 (2016-06-04 01:41:23 +0200)

----------------------------------------------------------------
Nicolas Sebrecht (1):
      introduce a virtual imaplib2


-- %< --
From: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
Date: Sat, 4 Jun 2016 00:49:57 +0200
Subject: [PATCH] introduce a virtual imaplib2

The virtual imaplib2 first try to import imaplib2 when provided by the system.
If not provided or if the version is not supported, fallback on the bundled
imaplib2 version.

Distributions maintainers can now easily remove the bundled imaplib2 version if
they want to get it packged outside of offlineimap.

We still want to provide imaplib2 by default because:
- this library is neither in Python core nor packaged by a lot of distributions;
- users expect to be able to run offlineimap by just downloading the tarball or
  after a git clone.

In order to avoid supporting different versions of imaplib2, we restrict the
supported versions of this librabry.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---

 offlineimap/{imaplib2.py => bundled_imaplib2.py} |  0
 offlineimap/folder/IMAP.py                       |  7 ++--
 offlineimap/imaplibutil.py                       |  8 ++---
 offlineimap/init.py                              |  4 +--
 offlineimap/virtual_imaplib2.py                  | 44 ++++++++++++++++++++++++
 5 files changed, 53 insertions(+), 10 deletions(-)
 rename offlineimap/{imaplib2.py => bundled_imaplib2.py} (100%)
 create mode 100644 offlineimap/virtual_imaplib2.py

diff --git a/offlineimap/imaplib2.py b/offlineimap/bundled_imaplib2.py
similarity index 100%
rename from offlineimap/imaplib2.py
rename to offlineimap/bundled_imaplib2.py
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 7dac137..11a3a2a 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -1,5 +1,5 @@
 # IMAP folder support
-# Copyright (C) 2002-2012 John Goerzen & contributors
+# Copyright (C) 2002-2016 John Goerzen & contributors
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -20,14 +20,13 @@ import binascii
 import re
 import os
 import time
+import six
 from sys import exc_info
 
 from .Base import BaseFolder
 from offlineimap import imaputil, imaplibutil, emailutil, OfflineImapError
 from offlineimap import globals
-from offlineimap.imaplib2 import MonthNames
-
-import six
+from offlineimap.virtual_imaplib2 import MonthNames
 
 
 # Globals
diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index 32448b7..4d6f64e 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -1,5 +1,5 @@
 # imaplib utilities
-# Copyright (C) 2002-2015 John Goerzen & contributors
+# Copyright (C) 2002-2016 John Goerzen & contributors
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
 #    the Free Software Foundation; either version 2 of the License, or
@@ -23,12 +23,12 @@ import threading
 from hashlib import sha1
 import socket
 import errno
+import zlib
+import six
 
 from offlineimap.ui import getglobalui
 from offlineimap import OfflineImapError
-from offlineimap.imaplib2 import IMAP4, IMAP4_SSL, zlib, InternalDate, Mon2num
-
-import six
+from offlineimap.virtual_imaplib2 import IMAP4, IMAP4_SSL, zlibInternalDate, Mon2num
 
 
 class UsefulIMAPMixIn(object):
diff --git a/offlineimap/init.py b/offlineimap/init.py
index c4dc611..88ef3aa 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -1,5 +1,5 @@
 # OfflineIMAP initialization code
-# Copyright (C) 2002-2015 John Goerzen & contributors
+# Copyright (C) 2002-2016 John Goerzen & contributors
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
 import os
 import sys
 import threading
-import offlineimap.imaplib2 as imaplib
+import offlineimap.virtual_imaplib2 as imaplib
 import signal
 import socket
 import logging
diff --git a/offlineimap/virtual_imaplib2.py b/offlineimap/virtual_imaplib2.py
new file mode 100644
index 0000000..2107775
--- /dev/null
+++ b/offlineimap/virtual_imaplib2.py
@@ -0,0 +1,44 @@
+# Copyright (C) 2016-2016 Nicolas Sebrecht & contributors
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+# WARNING: any internal use of imaplib2 must be done through this
+# virtual_imaplib2 or we might go into troubles.
+_SUPPORTED_RELEASE = 2
+_SUPPORTED_REVISION = 53
+
+try:
+    # Try any imaplib2 in PYTHONPATH first. This allows both maintainers of
+    # distributions and developers to not work with the bundled imaplib2.
+    from imaplib2 import *
+    import imaplib2 as imaplib
+
+    if int(imaplib.__release__) < _SUPPORTED_RELEASE \
+            or int(imaplib.__revision__) < _SUPPORTED_REVISION:
+        raise ImportError("The provided imaplib2 version '%s' is not supported"%
+            imaplib.__version__)
+except (ImportError, NameError) as e:
+    try:
+        from offlineimap.bundled_imaplib2 import *
+        import offlineimap.bundled_imaplib2 as imaplib
+    except:
+        print("Error while trying to import system imaplib2: %s"% e)
+        raise
+
+# We should really get those exposed by upstream. Same goes for __version__,
+# __release__ and __revision__.
+InternalDate = imaplib.InternalDate
+Mon2num = imaplib.Mon2num
+MonthNames = imaplib.MonthNames
-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list