New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH-FIX: change distutils to setuptools and add flexible cythonization #949
Conversation
|
||
import distutils.dir_util | ||
import setuptools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, this could have been untouched as only thing it is used is to clean build folder.
Alternatively it could be from setuptools import distutis.dir_util
.
just first part...
dir_utils is in distutils which looks like is in setuptools, but setuptools have just a link to distutils, so ```from setuptools import distutils.dir_utils``` works
add temporary file to test the cython work-chain in building testing and CI environmnets
This does more than it advertises. In addition to re-switching to setup tools (this was done in #849, but possible it was reverted in a merge) this adds functions to cythonize cython extensions and a test to check that the cython extensions are correctly installed. That's fine, but could you edit the description of this PR to better reflex what it does? The cythonize functionality seems to WIP. Let us know when this is ready for review. |
subclased and add the check or force mechanism to (re)cythonize *.pyx files while python setup.py install; added optional --force-cythonization user flag
just upgraded the cythonization during installation:
I added dummy pyx in misc dir to check how cythonization works. It is either to be removed in the end of this feature development, or I could add some testing in tests, to see it works properly. |
try: | ||
from Cython.Build import cythonize | ||
except ImportError: | ||
print("""WARNING: cython required to generate fast c code is not found on this system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use a proper warning instead i.e. warnings.warn
Installing without Cython currently fails like this: jd29@SATELLITE-PRO-C850-10N:~/git/hyperspy$ ana3-python3.5 setup.py build_ext --inplace --force-cythonization
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: option --force-cythonization not recognized
fjd29@SATELLITE-PRO-C850-10N:~/git/hyperspy$ ana3-python3.5 setup.py install --force-cythonization
running install
cythonizing the *.pyx source
WARNING: cython required to generate fast c code is not found on this system.
Only slow pure python alternative functions will be available.
To use fast implementation of some functions writen in cython either:
a) install cython and re-run the installation,
b) try alternative source distribution containing cythonized C versions of fast code,
c) use binary distribution (i.e. wheels, egg).
Traceback (most recent call last):
File "setup.py", line 254, in <module>
"Topic :: Scientific/Engineering :: Physics",
File "/usr/lib/python3.5/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "setup.py", line 106, in run
orig_install.run()
TypeError: run() missing 1 required positional argument: 'self'
|
And with |
please, patience, it is still work in progress |
@francisco-dlp , so at this moment it should work. If you check the travis logs (under the 340b769 I can remove the test file in the end before the merge, or move it to tests. Now I want to be sure pyx files in hyperspy normal directories can be compiled. |
oh, and by the way, build_ext will not work at this moment as it is still not subclassed, just install is subclassed at this moment. Also |
I think that travis should indeed always cythonize. In this way, we'll know if a new version of Cython breaks something. Regarding the test, I think that it'll be best to move it to Probably it'll be also good to add an extra travis and appveyor build to install without the cython extensions to verify that everything goes well too in this case. Finally, I think that this requires an entry in the developers guide explaining best practices for including Cython code in HyperSpy and how to install in devel mode. Now that we have the |
To add thing to development guide is a very splendid idea. |
I agree that the documentation on this issue is not great. I like sklearn's approach: cythonize always except when |
ok, I am going to modify, the appveyor: instead of smoking up that file, I will rename it, and after rename it back (hopefully). I am testing stuff now on separate branch (as I am not good in powershell - lots of trial and error going there :) ). I will merge it back to this branch, so you could start reviewing changes and test it out how it works when compiler is not present (setup.py modified, and new minimal dummy c file created in /hyperspy/tests/misc/test_compilers.c), and in mean time I will try to do renaming of that file forward and back tricks (The winpython/ in appveyor stuff). |
Sounds good, just let me know when this is ready for review. |
add test to check for compiler presence
I merged the changes to setup.py and minimal c file, however appveyor winpython have problems if I leave the pysitutil.cfg file file. It behaves differently than linux wihout gcc, where on linux if extensions is empty list it will not try to use compiler, while on winpython it tries to use mingw compiler anyway, even if extensions is set to just empty list. Maybe it is winpythons modifications. I will try to change empty list to None, will see where it will lead (tried on linux it works same as with empty list, maybe winpython will take it) |
Installation will continue in 10 sec...""") | ||
extensions = [] | ||
from time import sleep | ||
sleep(10) #wait 10 secs for user to notice the message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why waiting 10 s? As the user has to take no action I would simply print the warning and continue...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if terminal used have some limit (often 1000 lines, by default) it "flies" away. this will wait for 10 sec only if compiler is missing. if it is here, no waiting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I have results from winpython... it is bad, no matter to what extensions are set (empty list or None) if keyword ext_modules
is provided to setup()
then winpython anyway tries to fire up compiler :/. So I don't know what to do now as it is "impossible" to trick winpython from touching compiler.
And I have results from winpython... it is bad, no matter to what extensions are set (empty list or None) if keyword |
I think that the easiest solution is to put all the keyword arguments in a dictionary and simply don't add the keyword_args = {}
setup(**keyword_args) May that work? |
:) exactly what I am trying to do now :D |
the revolution in setup.py didn't helped... I think problem is lying somethere else. I made abranch from master, adjusted the appveyor to fit for faster testing of winpython. master have no problems to get installed on winpython. I will add stuff step by step to find out where the problem is introduced. i.e. I skiped all conda stuff and tried to go straight to winpython steps, and it fails (many times trying to use compiler...), however if conda stuff is not comented it works (that why I suspect compiled stuff from conda is coppied to winpython? so basically, if somebody will want to install hyperspy on bare minimum winpython, it will fail with dependencies :/ |
add test_compilers.c
update with upstream
instead of delting rename before install the pydistutil.cfg and back after install in appveyor script
I didnt moved to keywords as it does not fix issue, however I think I fail to simulate compiler'less environment on appveyor winpython, due to it reusing condas stuff... unfortunately I have no winpython environment (windows) to test that now. If I comment conda stuff at appveyor script (at fresh master branch), then winpython behaves similary as python in ubuntu: it tries to compile traits, and fails. I guess with conda ennabled winpython reuse condas distutils which internally have msvc compiler presence coded, and so my test thinks compiler is present (I guess, it is hard to tell what is really going on) but then winpython forces to use mingw and so it gets messed. That of course do not influence building the nsis installer as I made the renaming of config before winpython installs hyperspy, and rename back just before nsis start building. So basically I think there is little I can do to this any more... I think it is time to merge |
@francisco-dlp , I just tested installation of master on fresh windows system (7) with freshly installed winpython. It fails to install because of traits needs to be compiled. So ubuntu for now is the only system where limited hyperspy version is actual (as there is python-traits binary package there available). Unfortunately installation of hyperspy as library on winpython requires compiler, and I just want to make 200% sure that winpython does not include any compiler! Also I think the points I stated yesterday is valid, and this can be merged. update3: I am not very happy about reduction dependancies in setup.py, just to get to know about them after installation trying out hyperspy: update4: tried installing bundle, so far so good. wait |
looks that installing from wheel have all dependencies needed. only traits have to be installed from gohlke's site. I think I will open new issue/pull request to improve instructions from this point |
so winpython could install minimal "pure" python version of hyperspy
@francisco-dlp , @to266 , finally I tested installing this branch in windows environment without any compiler present on winpython and it was a success (after some minor modifications which I just pushed, catching msvc missing). the weird thing is that on my machine ,differently than on appveoyr, distutil complained about msvc missing and not the mingw. Anyway this is now completely tested and safe to use. |
Thanks for all the effort and attention to detail that you've put into this! |
this code fixes two things:
first is straight forward, but second have to be discussed.
Firstly lets consider these points:
Considering above the setup should meet such criteria:
python setup.py recythonize
.special user option are added topython setup.py install --force-cythonization
(or todevelop
which will be used for testing env)TODO:
python setup.py install
works without compiler present (ubuntu live usb: passed; appveyor: too much interfered setup; windows 7 with fresh winpython + traits(from gohlke's place): passed)