Skip to content

Commit 1288566

Browse files
authoredFeb 7, 2021
FIX for "No module named 'public'" during installation (#242)
* Move __version__ to __init__.py This should solve issue #241, in which setuptools < 46.4.0 tries to naively import smtp.py (due to version being specified as "attr: aiosmtpd.smtp.__version__" and barfs when encountering "from public import public" Moving __version__ to __init__.py seems to be the wisest -- and most semantically accurate -- decision. Not only can setuptools < 46.4.0 simply do a naive import of __init__.py (which contains no deps), but this signifies the version number applies to the _whole_ aiosmtpd package instead of just the smtp.py module. This impacts the following files * setup.cfg -- scan inside aiosmtpd instead of aiosmtpd.smtp * smtp.py -- it now needs to import * conf.py -- no longer scan smtp.py; import from __init__ instead * Add Compatibility Test In this case, ensure __version__ from __init__.py is exact same object as __version__ from smtp.py * Update NEWS.rst
1 parent 7849502 commit 1288566

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed
 

‎aiosmtpd/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2014-2021 The aiosmtpd Developers
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
__version__ = "1.3.0a4"

‎aiosmtpd/docs/NEWS.rst

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Fixed/Improved
1919
* ``authenticator`` system improves on ``auth_callback`` by enabling the called function
2020
to see the SMTP Session and other info.
2121
(``auth_callback`` will be deprecated in 2.0)
22+
* ``__version__`` is now an attribute in ``__init__.py``,
23+
and can be imported from the 'plain' ``aiosmtpd`` module.
24+
(It gets reimported to ``aiosmtpd.smtp``,
25+
so programs relying on ``aiosmtpd.smtp.__version__`` should still work.)
26+
(Closes #241)
2227

2328

2429
1.2.4 (2021-01-24)

‎aiosmtpd/docs/conf.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import sys
16-
import re
1715
import datetime
18-
16+
import re
17+
import sys
1918
from pathlib import Path
2019

20+
from aiosmtpd import __version__
21+
2122
try:
2223
# noinspection PyPackageRequirements
23-
from colorama import ( # pytype: disable=import-error
24-
init as colorama_init,
25-
)
24+
from colorama import init as colorama_init # pytype: disable=import-error
2625

2726
colorama_init()
2827
except ImportError:
@@ -77,15 +76,6 @@
7776
# |version| and |release|, also used in various other places throughout the
7877
# built documents.
7978
#
80-
__version__ = None
81-
with open("../smtp.py") as fp:
82-
for line in fp:
83-
m = RE__VERSION.match(line.strip())
84-
if m:
85-
__version__ = m.group("ver")
86-
break
87-
if __version__ is None:
88-
raise RuntimeError("No __version__ found in aiosmtpd/smtp.py!")
8979
release = __version__
9080
version = __version__
9181

‎aiosmtpd/smtp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import collections
1414
import asyncio.sslproto as sslproto
1515

16+
from aiosmtpd import __version__
1617
from base64 import b64decode, b64encode
1718
from email._header_value_parser import get_addr_spec, get_angle_addr
1819
from email.errors import HeaderParseError
@@ -66,8 +67,8 @@ class _DataState(enum.Enum):
6667
"AuthCallbackType",
6768
"AuthMechanismType",
6869
"MISSING",
70+
"__version__",
6971
] # Will be added to by @public
70-
__version__ = '1.3.0a3'
7172
__ident__ = 'Python SMTP {}'.format(__version__)
7273
log = logging.getLogger('mail.log')
7374

‎aiosmtpd/tests/test_server.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import socket
99
import unittest
1010

11+
from aiosmtpd import __version__ as init_version
1112
from aiosmtpd.controller import asyncio, Controller, _FakeServer
1213
from aiosmtpd.handlers import Sink
13-
from aiosmtpd.smtp import SMTP as Server
14+
from aiosmtpd.smtp import SMTP as Server, __version__ as smtp_version
1415
from contextlib import ExitStack
1516
from functools import wraps
1617
from smtplib import SMTP
@@ -203,3 +204,9 @@ def hijacker(*args, **kwargs):
203204
self.assertIsNone(cont._thread_exception)
204205
excm = str(cm.exception)
205206
self.assertEqual("Unknown Error, failed to init SMTP server", excm)
207+
208+
209+
class TestCompat(unittest.TestCase):
210+
211+
def test_version(self):
212+
assert smtp_version is init_version

‎setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = aiosmtpd
3-
version = attr: aiosmtpd.smtp.__version__
3+
version = attr: aiosmtpd.__version__
44
description = aiosmtpd - asyncio based SMTP server
55
long_description =
66
This is a server for SMTP and related protocols, similar in utility to the

0 commit comments

Comments
 (0)
Please sign in to comment.