commit 4ee02d05f266a0fd60f470d28992026f6a6d49d6 Author: Damian Johnson atagar@torproject.org Date: Wed Mar 27 09:37:58 2013 -0700
Avoiding stem imports in setup.py
Our setup.py may be ran under python 2.x or 3.x. Because of this the file and anything it imports needs to run under both python serieses *without* a 2to3 conversion.
We were importing basic module information from __init__ which in turn brought in the enum and str_tools utils...
atagar@morrigan:~/Desktop/stem$ python3 setup.py install Traceback (most recent call last): File "setup.py", line 5, in <module> from stem import __version__, \ File "/home/atagar/Desktop/stem/stem/__init__.py", line 504, in <module> "ERR", File "/home/atagar/Desktop/stem/stem/util/enum.py", line 64, in UppercaseEnum return Enum(*[(v, v) for v in args]) File "/home/atagar/Desktop/stem/stem/util/enum.py", line 77, in __init__ if isinstance(entry, (bytes, unicode)): NameError: global name 'unicode' is not defined
Bug caught by Dererk. --- setup.py | 41 +++++++++++++++++++++++++++++++---------- 1 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/setup.py b/setup.py index 23902b1..c2ce4d2 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,35 @@ # Copyright 2012-2013, Damian Johnson # See LICENSE for licensing information
-from stem import __version__, \ - __author__, \ - __contact__, \ - __url__, \ - __license__ +# We cannot import anything from the stem module since this would risk +# importing code that does not work under python 3 *without* being converted. +# +# I hate to do this, but reading our module file's information directly.
+import os +import re from distutils.core import setup
+STAT_LINE = re.compile(r"^__(.+)__ = '(.+)'$") + +def get_module_info(): + # reads the basic __stat__ strings from our module's init + + result = {} + cwd = os.path.sep.join(__file__.split(os.path.sep)[:-1]) + + with open(os.path.join(cwd, 'stem', '__init__.py')) as init_file: + for line in init_file.readlines(): + line_match = STAT_LINE.match(line) + + if line_match: + keyword, value = line_match.groups() + result[keyword] = value + + return result + +module_info = get_module_info() + DESCRIPTION = """\ Stem is a python controller library for Tor https://www.torproject.org/. Like its predecessor, TorCtl, it uses Tor's control protocol to help @@ -21,12 +42,12 @@ except ImportError: from distutils.command.build_py import build_py
setup(name = 'stem', - version = __version__, + version = module_info['version'], description = DESCRIPTION, - license = __license__, - author = __author__, - author_email = __contact__, - url = __url__, + license = module_info['license'], + author = module_info['author'], + author_email = module_info['contact'], + url = module_info['url'], packages = ['stem', 'stem.descriptor', 'stem.response', 'stem.util'], provides = ['stem'], cmdclass = {'build_py': build_py},
tor-commits@lists.torproject.org