Full packaging review

This patch includes a lot of changes:

1. Split the `requirements.txt` file in multiple files. This change holds
   the required packages for OfflineIMAP in the `requirements.txt` file.
   The optional packages are included in the files `requirements-option.txt`
   files. Now the standard OfflineIMAP configuration does not include
   packages like `cygwin`. See for example issue #192.
2. The `setup.py` process includes a lot of files (see issue #110). This
   creates a problem in the setup process, because some libraries are not
   found (see #39, the problem still happends). For this reason we can
   read the variables from the `offlineimap/__init__py` to include them
   in the `setup.py` script, without import the `offlineimap` module. I
   used the method presented at `https://www.youtube.com/watch?v=fHNhhHMUW7k`.
   In the setup module we don't need the testing code (it creates the import
   problem too), so this code is removed. To read the variables, we use
   some regex search in the `offlineimap/__init__py` file, save the
   values as variables, and then use them in the `setup()` call.
3. `setup.py` uses requires and extra_requires libraries, aligned with
   the `requirements` files. We use four different options: `kerberos`,
   `keyring`, `cygwin`, `cygwin` and `testinternet`.
4. `pyproject.toml`. This file is fully rewritten. The file use now the
   right dependencies, includes the optional dependencies aligned with
   the requirements and the `setup.py` files. The file include other
   details, like classifiers, URLs,... This script uses now the the
   `project.scripts` option, with the module and the method to call when
   the setup file is created. Then, this script includes as module
   `offlineimap.init`, and the startup method is `main`. Because this
   method is new, this method and the `__main__` functions are created
   in the `offlineimap/init.py` file:

        ```python
        def main():
            oi = OfflineImap()
            oi.run()

        if __name__ == "__main__":
            main()
        ```
With these changes, the setup process works fine, with and without
optional modules. Finally, the folder `offlineimap.egg-info`,
created in the setup process is included in the `.gitignore` file.

It is possible check the creation using:

```python
python -m pip install .
```

And then use the command `offilineimap` to use the module. Finally, the
`bin/offlineimap` command is not used, so we probably can remove it.

Fix: #192, Fix: #110, Fix: #39, Fix: #90
This commit is contained in:
Rodolfo García Peñas (kix)
2024-08-26 16:48:34 +02:00
parent 47f74c4408
commit 4f5b2529e4
9 changed files with 123 additions and 42 deletions

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@
*.css
/docs/dev-doc/
/build/
offlineimap.egg-info/
*.pyc
offlineimap.1
offlineimapui.7

View File

@@ -567,3 +567,13 @@ class OfflineImap:
folders = localrepo.getfolders()
for f in folders:
f.migratefmd5(options.dryrun)
def main():
oi = OfflineImap()
oi.run()
if __name__ == "__main__":
main()

View File

@@ -1,10 +1,56 @@
[build-system]
requires = [
"setuptools>=18.5",
"wheel",
# These dependencies should be kept in sync with setup.py
[project]
dependencies = [
"distro",
"imaplib2>=3.5",
"rfc6555",
"urllib3~=1.25.9"
]
name = "offlineimap"
version = "8.0.0"
description = "IMAP synchronization tool"
authors = [
{ name = "John Goerzen & contributors", email = "jgoerzen@complete.org" }
]
license = { text = "GPL-2.0" }
readme = "README.md"
keywords = ["client", "imap", "cli", "email", "mail", "synchronization", "sync", "offline"]
requires-python = ">=3.6"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Office/Business :: Scheduling",
"Topic :: Utilities"
]
[project.urls]
homepage = "http://www.offlineimap.org"
documentation = "https://www.offlineimap.org/documentation.html"
issues = "https://github.com/OfflineIMAP/offlineimap3/issues"
repository = "https://github.com/OfflineIMAP/offlineimap3/"
[build-system]
requires = [
"setuptools>=18.5",
"wheel"
]
[project.optional-dependencies]
keyring = ["keyring"]
cygwin = ["portalocker[cygwin]"]
kerberos = ["gssapi[kerberos]"]
testinternet = ["certifi~=2020.6.20"]
[project.scripts]
offlineimap = "offlineimap.init:main"

1
requirements-certify.txt Normal file
View File

@@ -0,0 +1 @@
certifi~=2020.6.20

1
requirements-cygwin.txt Normal file
View File

@@ -0,0 +1 @@
portalocker[cygwin]

View File

@@ -0,0 +1 @@
gssapi[kerberos]

1
requirements-keyring.txt Normal file
View File

@@ -0,0 +1 @@
keyring

View File

@@ -1,10 +1,5 @@
# Requirements
gssapi[kerberos]
portalocker[cygwin]
rfc6555
distro;platform_system=="Linux" and python_version>"3.7"
keyring
distro; python_version > "3.6"
imaplib2>=3.5
urllib3~=1.25.9
certifi~=2020.6.20

View File

@@ -21,51 +21,76 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import re
try:
from setuptools import setup, Command
except:
from distutils.core import setup, Command
import offlineimap
import logging
from test.OLItest import TextTestRunner, TestLoader, OLITestLib
with open('offlineimap/__init__.py') as f:
version_grp = re.search(r"__version__ = ['\"](.+)['\"]", f.read())
if version_grp:
version = version_grp.group(1)
else:
version = "0.0.0"
class TestCommand(Command):
"""runs the OLI testsuite"""
description = """Runs the test suite. In order to execute only a single
test, you could also issue e.g. 'python -m unittest
test.tests.test_01_basic.TestBasicFunctions.test_01_olistartup' on the
command line."""
user_options = []
f.seek(0)
description_grp = re.search(r"__description__ = ['\"](.+)['\"]", f.read())
if description_grp:
description = description_grp.group(1)
else:
description = "Disconnected Universal IMAP Mail Synchronization/Reader Support"
def initialize_options(self):
pass
f.seek(0)
author_grp = re.search(r"__author__ = ['\"](.+)['\"]", f.read())
if author_grp:
author = author_grp.group(1)
else:
author = "John Goerzen"
def finalize_options(self):
pass
f.seek(0)
author_email_grp = re.search(r"__author_email__ = ['\"](.+)['\"]", f.read())
if author_email_grp:
author_email = author_email_grp.group(1)
else:
author_email = ""
def run(self):
logging.basicConfig(format='%(message)s')
# set credentials and OfflineImap command to be executed:
OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py')
suite = TestLoader().discover('./test/tests')
TextTestRunner(verbosity=2, failfast=True).run(suite)
f.seek(0)
homepage_grp = re.search(r"__homepage__ = ['\"](.+)['\"]", f.read())
if homepage_grp:
homepage = homepage_grp.group(1)
else:
homepage = "http://www.offlineimap.org"
f.seek(0)
copyright_grp = re.search(r"__copyright__ = ['\"](.+)['\"]", f.read())
if copyright_grp:
copyright = copyright_grp.group(1)
else:
copyright = ""
setup(name="offlineimap",
version=offlineimap.__version__,
description=offlineimap.__description__,
long_description=offlineimap.__description__,
author=offlineimap.__author__,
author_email=offlineimap.__author_email__,
url=offlineimap.__homepage__,
version=version,
description=description,
long_description=description,
author=author,
author_email=author_email,
url=homepage,
packages=['offlineimap', 'offlineimap.folder',
'offlineimap.repository', 'offlineimap.ui',
'offlineimap.utils'],
scripts=['bin/offlineimap'],
license=offlineimap.__copyright__ + ", Licensed under the GPL version 2",
cmdclass={'test': TestCommand},
install_requires=['distro', 'imaplib2>=3.5', 'rfc6555', 'gssapi[kerberos]', 'portalocker[cygwin]', 'urllib3~=1.25.9'],
extras_require={'keyring': ['keyring']},
setup_requires=['setuptools>=18.5', 'wheel', 'imaplib2'],
license=copyright + ", Licensed under the GPL version 2",
install_requires=['distro',
'imaplib2>=3.5',
'rfc6555',
'urllib3~=1.25.9'],
extras_require={'kerberos':'gssapi[kerberos]',
'keyring':'keyring[keyring]',
'cygwin':'portalocker[cygwin]',
'testinternet':'certifi~=2020.6.20'}
)