Skip to content
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

Remove python 2.7 support (fix #498) #665

Merged
merged 11 commits into from
Aug 30, 2019
Merged

Conversation

DougBurke
Copy link
Contributor

@DougBurke DougBurke commented Aug 21, 2019

Summary

Remove support for Python 2.7 from Sherpa. The metadata used by pip now requires python 3.5 or higher (but not version 4), and an attempt to build with an earlier version of python will cause setup.py to exit with an error message. The documentation has been updated, including a link to the final Python 2.7-compatible release (Sherpa 4.11.1). The code has been cleaned up to remove the use of the six module (that provided backwards-compatible support) and other parts of the code that supported running under Python 2.7 and 3.5-or-later.

There has been no attempt to re-write the code to take advantage of capabilities present in Python 3.5 that were not in Python 2.7.

Details

Remove Python 2.7 support in Sherpa.

  • Rework documentation to point out 2.7 isn't supported
    • README.md
    • Sphinx docs
  • Remove python 2.7 support in setup.py
  • Remove python 2.7 support in tests
  • Remove python 2.7 support when building sphinx docs
  • Remove python 2.7 travis build (replaced with a python 3.7 / numpy 1.16 build)
  • remove 'import six' from all code
  • Python 2.7 clean up (not needed, but may as well do where appropriate)
    • remove fall through imports (when modules / functionality has moved)
    • remove object base class from objects
    • can we remove / fix up the future imports now?
    • anything else?
  • update the conda build recipies

One problem with testing the six removal is that it is still required by other modules we use, so it is currently hard - if not impossible - to ensure we have a "six free" environment.

I may make some more minor clean ups to address some of the Python 2.7 clean ups, but will not touch the conda recipies.

Questions

The metadata in setup.py has been updated to point out that Python 3.5 or later is needed (and does not support a hypothetical python 4). This means that 'pip' should not try to install it. However, it doesn't stop someone from trying to 'python setup.py install' a source-code installation, so I added an explicit check for that - you can see the output in #665 (comment)

Is this a sensible thing to do?

The sub-classing of the Mock object may still be useful, even though
it was added in the hope of getting a Python 2.7 documentation build.
This should be checked to see if it can be removed.
The setup.py script now fails if run with a python older than 3.5.

The package metadata has been updated to reflect that Sherpa is now
3.5 or later (with python_requires set to not include Python 4 or
later), so that pip installations will only work with a supported
Python version.

It is not clear from
https://packaging.python.org/guides/dropping-older-python-versions/#dropping-a-python-release
whether we really should have included python_requires in the 4.11.1
release, but I think we are okay as is.

The Travis tests should fail because I have not removed the
python 2.7 build.
@DougBurke
Copy link
Contributor Author

DougBurke commented Aug 21, 2019

The above commit - 47cf063 - should fail for the python 2.7 build on travis (but not the other builds).

edited to add

good, I see the expected error message from the 2.7 build and it is also the only test that fails.

$ python setup.py $INSTALL_TYPE
Sherpa 4.12 (and later) requires Python 3.5 or later.

Please use Sherpa 4.11.1 if you need to use Python 2.7

I have bumped the NumPy version to 1.16 from 1.11 as we have 1.15
well tested, and it doesn't seem to make much sense to use older
versions of NumPy.

An alternative would be to remove this bare-bones test.
The code conversion was pretty much mechanical.

I converted 'from six imprt string_types' to 'string_types = (str, )'
to make it easier to see where this was happening (in part because
we probably should review all these uses to see if there are better
changes).

There are also several minor "python 2.7 clean ups" in this commit,
e.g. replacing 'try: python27-code except: python3-code' by
python3-code.

There conda recipes still include six.
Python 3 now comes with mock, so we no longer need to install it
for testing. There were several places where both the Python 2.7
and 3 mock modules were imported which have been cleaned up.
This is not needed with Python 3+.
@DougBurke DougBurke changed the title WIP Remove python27 Remove python 2.7 support (fix #498) Aug 22, 2019
This updates the test that used to be Python 2.7 from NumPy 1.16 to
1.17.
@DougBurke
Copy link
Contributor Author

Apparently conda doesn't have numpy 1.17 yet - perhaps I should have checked before pushing 135d0f2! Oh well, it can be rebased out of existence.

@@ -1,6 +1,6 @@
from __future__ import absolute_import
#
# Copyright (C) 2011, 2016 Smithsonian Astrophysical Observatory
# Copyright (C) 2011, 201, 20196 Smithsonian Astrophysical Observatory
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in copyright dates- should be 2011, 2016, 2019

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Thanks for the update - was in a L3 meeting.

@DougBurke
Copy link
Contributor Author

@wmclaugh - do you want me to rebase this to avoid the "update to numpy 1.17, downgrade to 1.16" step, or are we happy to keep this in?

@wmclaugh
Copy link
Contributor

wmclaugh commented Aug 30, 2019 via email

@DougBurke
Copy link
Contributor Author

Sorry @wmclaugh I wasn't clear enough. This PR contains 135d0f2 and 337b26c which cancel each other out. I could rebase to remove these (and also take your copyright fix into an earlier commit), which gives a slightly-cleaner history, but do we care that much?

@wmclaugh
Copy link
Contributor

wmclaugh commented Aug 30, 2019 via email

wmclaugh added a commit that referenced this pull request Aug 30, 2019
Merge branch 'DougBurke-remove-python27'
@wmclaugh wmclaugh merged commit fd10693 into sherpa:master Aug 30, 2019
@DougBurke DougBurke deleted the remove-python27 branch August 30, 2019 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants