Skip to content

Commit

Permalink
Dehack the setup.py syspath + moved py2conv
Browse files Browse the repository at this point in the history
setup was doing something really ugly with the sys path to load version.py
without loading errbot.

This fixes it by loading the file independently.

It also moves py2conv.py to tools as it is not part of errbot itself.
  • Loading branch information
gbin committed Jun 7, 2016
1 parent a9452e0 commit 5f906be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
if PY3 and py_version < (3, 3):
raise RuntimeError('On Python 3, Errbot requires Python 3.3 or later')

VERSION_FILE = os.path.join('errbot', 'version.py')

deps = ['webtest',
'setuptools',
'bottle',
Expand Down Expand Up @@ -82,15 +84,30 @@
deps += ['daemonize']

src_root = os.curdir
sys.path.insert(0, os.path.join(src_root, 'errbot')) # hack to avoid loading err machinery from the errbot package


def read_version():
"""
Read directly the errbot/version.py and gives the version without loading Errbot.
:return: errbot.version.VERSION
"""

variables = {}
if PY2:
execfile(VERSION_FILE, variables)
else:
with open(VERSION_FILE) as f:
exec(compile(f.read(), 'version.py', 'exec'), variables)
return variables['VERSION']


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


if __name__ == "__main__":
from version import VERSION

VERSION = read_version()

args = set(sys.argv)

Expand All @@ -105,7 +122,7 @@ def read(fname):
# under python2 if we want to make a source distribution,
# don't pre-convert the sources, leave them as py3.
if PY2 and args & {'install', 'develop', 'bdist_wheel'}:
from py2conv import convert_to_python2
from tools.py2conv import convert_to_python2
convert_to_python2()

setup(
Expand Down Expand Up @@ -156,6 +173,3 @@ def read(fname):
src_root=src_root,
platforms='any',
)

# restore the paths
sys.path.remove(os.path.join(src_root, 'errbot'))
Empty file added tools/__init__.py
Empty file.
File renamed without changes.

0 comments on commit 5f906be

Please sign in to comment.