Skip to content

Conversation

@segevfiner
Copy link
Contributor

This makes isympy available on Windows. And isympy is now also accessible as python -m sympy.

Fixes #13008

This makes isympy available on Windows. And isympy is now also
accessible as `python -m sympy`.

Fixes sympy#13008
@ylemkimon
Copy link
Member

ylemkimon commented Aug 25, 2017

/sympy/utilities/tests/test_code_quality.py checks for implicit imports which is used in isympy.

diff --git a/sympy/utilities/tests/test_code_quality.py b/sympy/utilities/tests/test_code_quality.py
index b3641ea06..f73fcd401 100644
--- a/sympy/utilities/tests/test_code_quality.py
+++ b/sympy/utilities/tests/test_code_quality.py
@@ -213,8 +213,8 @@ def test_this_file(fname, test_file):
         "%(sep)spolys%(sep)sdomains%(sep)s__init__.py" % sepd,
         # interactive sympy executes ``from sympy import *``:
         "%(sep)sinteractive%(sep)ssession.py" % sepd,
-        # isympy executes ``from sympy import *``:
-        "%(sep)sbin%(sep)sisympy" % sepd,
+        # __main__(was isympy) executes ``from sympy import *``:
+        "%(sep)ssympy%(sep)s__main__.py" % sepd,
         # these two are import timing tests:
         "%(sep)sbin%(sep)ssympy_time.py" % sepd,
         "%(sep)sbin%(sep)ssympy_time_cache.py" % sepd,

@@ -0,0 +1,357 @@
#!/usr/bin/env python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should not be here. The __main__.py file shouldn't be executed directly (it generally won't work).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add a comment to the top of this file indicating that this is the isympy script.

@asmeurer
Copy link
Member

This looks fine. Just the one comment. We'll have to see at release time if this breaks our release process.

@asmeurer
Copy link
Member

The local isympy script doesn't work

$./bin/isympy
Traceback (most recent call last):
  File "./bin/isympy", line 4, in <module>
    from sympy.__main__ import main
ImportError: No module named 'sympy.__main__'

sympy_dir = os.path.join(sympy_top, 'sympy')

if os.path.isdir(sympy_dir):
sys.path.insert(0, sympy_top)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to keep these lines in here (and conversely, they shouldn't be in __main__.py). They let ./bin/isympy import from the local version.

if os.path.isdir(sympy_dir):
sys.path.insert(0, sympy_top)

# DO NOT IMPORT SYMPY HERE!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the original reason for this comment #7048. Let's double check that the -t python flag works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked and it doesn't work (the ground types are set to gmpy). I think it is not possible to make this work with python -m sympy, because Python already imports sympy first when that is run. So we might have to do some hacks to make the -t flag work.

@asmeurer
Copy link
Member

OK, I didn't notice this breaks the -t flag (same issue as #7048). Not sure how we can continue to make that work, as it has to be set before sympy is imported.

@asmeurer
Copy link
Member

One suggestion would be to package isympy as a separate module, so that python -m isympy can run without importing sympy, but it can still be used as a setuptools entrypoint on Windows. I'm also open to other suggestions. I haven't researched the problem much so there may be other solutions.

@segevfiner
Copy link
Contributor Author

@asmeurer I pushed some commits some time ago to try and handle the issues, just in case you missed them 😉.

Copy link
Member

@ylemkimon ylemkimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Windows 10 64-bit, Python 2.7/3.6, with/without setuptools. It successfully installs isympy.exe with setuptools.

@ylemkimon ylemkimon merged commit f57fe3f into sympy:master Oct 18, 2017
@ylemkimon
Copy link
Member

Thank you!

@asmeurer
Copy link
Member

Did you test that the -t python flag works correctly when gmpy2 is installed?

@segevfiner
Copy link
Contributor Author

Did you test that the -t python flag works correctly when gmpy2 is installed?

image

Checked again to be sure. Looks like it does.

@segevfiner segevfiner deleted the setuptools-console-scripts branch October 18, 2017 19:47
@asmeurer
Copy link
Member

Great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package isympy using setuptools console_scripts for Windows support

3 participants