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
Code is both Python 2.7 and 3.5 compliant #229
Conversation
@olaurino are you looking for comments at this stage, or is more work needed before a review is needed? |
Comments are always welcome, especially in this case where the PR is going to be massive. You already caught an unintended change, so that's good :) |
try: | ||
import stk | ||
except: | ||
logger.warning("could not import stk library. CIAO stack files and syntax will be disabled") |
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.
Is the idea here that, because the only use of the stk
module is already within a try/except block, there is no need to create a "replacement" routine for stk.build()
in the except clause? I thought that the change looked odd, until I checked into how the stk
module was used here. Do we need to document this (e.g. in a comment) for anyone who wants to use stk,build
in this module? Or am I being over sensitive?
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.
That is exactly what I had in mind. Yes, we could improve the documentation (as a matter of fact I had a comment that explained that but apparently I dropped it after changing the try..catch
block). If the stack library is not present and you use the stack syntax (e.g. @filename
) you'll get a file not found error, which paired with the warning should be reasonable enough.
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.
I noted that there looked to be similar-ish logic in the sherpa/astro/datastack/utils.py
module. I didn't look closely enough to see if the code was close enough to be able to remove one of them. That is, set Datastack.load_pha
to load_wrapper(ui.load_pha)
.
Perhaps there's something obviously different that I'm just missing (as I'm only skimming through the code).
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.
You are absolutely right, I noticed that too. I have the temptation to fix things like this as I go along, but I don't want that to be in the way of the python 3 migration, and the clock is ticking. There does not seem to be any reason for the duplication, but there is some complexity in the way the wrapping is done, so that might hide a trap... or I just forgot to remove a method when I did the refactoring for #22. Either way, I would rather spend the time required to figure this out adding test coverage where we are missing it. In any case I appreciate the level of your review, so please keep making these kinds of comments :)
I see that the python 2.7 tests are now back to passing (yay), but the stk and group tests are skipped. Is the idea to leave these for now and concentrate on the main code (which looks like replacing lots of use of izip!) and then come back to these later (in part because these are OTS from our view, so we are waiting for other teams to update them)? |
@DougBurke that's the idea. |
@@ -19,6 +19,8 @@ addons: | |||
|
|||
# We use matrix include so that xspec builds (which are more complicated and long) are started first | |||
matrix: | |||
allow_failures: | |||
- python: "3.5" |
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 be exactly the same as the build you want to allow to fail, so here I guess:
- env: XSPECVER="12.9.0i" FITS="astropy" INSTALL_TYPE=develop TEST=submodule MATPLOTLIBVER=1.5
python: "3.5"
sudo: required
dist: trusty
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.
Thanks @bsipocz. Not sure why I kept the allow_failures
line, since I am happy with the build to be red until all the tests pass. I'll remove that line altogether, rather than fixing it.
I think, once we've got the python 3.5 travis builds green we should add in tests for python versions 3.3. and 3.4. Ideally we'd be able to support all versions, but if not, it would be good to know which ones we don't support. |
@olaurino - I've played around with a few fixes but you may not want them (I am just relying on the existing tests rather than checking if new tests are needed). You can find them at https://github.com/DougBurke/sherpa/tree/python3 and they are basically StringIO, basestring, and xrange fixes. edit I've added a few more: I was focussing on improving the serialize tests, which lead to getting |
@olaurino - OOPS. I did not mean to push those changes! I'm not sure what the best way to fix this is, so I'm going to leave it for now. |
@DougBurke you can leave them here, thanks! I wonder where the conflicts are coming from, I'll look into that and rebase. |
I added several tests to make sure some of the trickier aspects of the conversion were tested. The replacement of getargspec by signature in export_method does not seem to be necessary, in that the old version did not cause deprecation warnings to be displayed. It is not clear to me why that is, so this commit may not be needed. It also isn't clear to me what export_method is doing to need a version of the function with the default values removed, but I don't want to investigate this any further at this time.
This also changes the case of one of the copyright statements. Note that files in extern/ are not changed in this commit, and there is no copyright statement or license in sherpa/include/capsulethunk.h (I assume it's the same as the Python version).
I've just added PR #250 which removes the capsulethunk file. It was surprisingly easy (yay for encapsulation, I guess), so maybe I missed something? |
Should we note that this has been deprecated by #252 (or close this in favor of 252)? |
I am about to merge this and rebase #252! |
Thank you!!! I'll add a Python 3 build for Gammapy in the next days. Will there be a Python 3-compatible Sherpa conda package for testing soon, or only after the next stable Sherpa release? |
@cdeil the conda package will most likely come in a few weeks with the 4.8.2 release. However, the conda recipes are included in this repo, so you could produce them yourself. They may require bumping versions and other adjustments to the dependencies every now and then (in this case you certainly need to update the python version), but if you can build Sherpa from sources, it should be a straightforward process. If that's not true, or you have issues or questions, please let me know. I have quite a packed schedule, but if I find some time I'll publish some test cut of the python 3 conda package. I just can't promise, so please don't hold your breath 😉 |
By the way, I created a |
Congratulations on this tremendous accomplishment!! 🎉 This removes the last real blocker from Chandra operations tools migrating to Python 3. |
Description
Resolve #76.
Introduce support for Python 3 while keeping code base compatible with Python 2.7.
Introduced a Python 3.5 travis build, but we can target more Python 3.x versions later.
This PR also tries and introduce new unit and integration tests.
As a side effect, this PR also fixes #186.