sympy/sympy — pull request #2262 by certik (2013-07-08 04:23:36+00:00)
Title: [WIP] Call 2to3 automatically from setup.py

It seems to work, but there is a bug, that if you do:
```
python setup.py install --prefix=xx
```
it will install into `build/py3k-sympy/xx` instead to `xx` in the current directory. By following NumPy's 1.7.0 approach in setup.py, I tried to apply the following patch:
```diff
commit c6c40f0cdbc1a4774730d4acc093ed4716cb2761
Author: Ondřej Čertík
Date: Sun Jul 7 21:50:31 2013 -0600

Try to fix the directory change

diff --git a/setup.py b/setup.py
index 6142f7c..235c805 100755
--- a/setup.py
+++ b/setup.py
@@ -41,9 +41,12 @@

if sys.version_info[0] >= 3:
local_path = os.path.dirname(os.path.abspath(sys.argv[0]))
+ src_path = os.path.join(local_path, 'build', 'py3k')
os.system("bin/use2to3")
- os.chdir("py3k-sympy")
- sys.path.insert(0, os.path.join(local_path, 'py3k-sympy'))
+ os.system("mkdir -p build")
+ os.system("mv py3k-sympy %s" % src_path)
+ os.chdir(src_path)
+ sys.path.insert(0, src_path)

import sympy

```
and even this on top of it:
```diff
diff --git a/setup.py b/setup.py
index 235c805..580c7d4 100755
--- a/setup.py
+++ b/setup.py
@@ -45,6 +45,9 @@
os.system("bin/use2to3")
os.system("mkdir -p build")
os.system("mv py3k-sympy %s" % src_path)
+ global __file__
+ __file__ = os.path.join(os.curdir, os.path.basename(__file__))
+
os.chdir(src_path)
sys.path.insert(0, src_path)

```
But unfortunately neither fixes the problem. The core of the problem is that we change the current directory in setup.py (following the NumPy's approach), but for some reason NumPy works, but this code doesn't yet.

TODO:

* [ ] Fix the prefix path bug (see above)
* [ ] Update .travis.yml to test this
* [ ] Test this in all scenarios and make sure it always does the right thing