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

Retire cmp() function #498

Merged
merged 13 commits into from
Aug 4, 2020
Merged

Retire cmp() function #498

merged 13 commits into from
Aug 4, 2020

Conversation

Anthchirp
Copy link
Member

I rewrote all places where cmp is used and removed the cmp import.

In the interest of maximum compatibility I did not remove the declarations of the following functions that are now no longer needed, but are declared in public namespaces:

def pair_sort_function(pair_a, pair_b):
# Deprecated. Do not use

def match_sort_function(match_a, match_b):
# Deprecated. Do not use

def compare_cb_op_as_hkl(a, b):
# Deprecated. Do not use.

def compare_redundancies(a, b):
# Deprecated. Do not use

Background:

The cmp function is gone. Importing it from past (which is part of the future package) is causing deprecation warnings all over the place due to PythonCharmers/python-future#551. The imp module will be removed in Python 3.10.

This also -as far as I can tell- would allow retiring the dependency on the future package. This is a good thing as the future package is a bit special.

Closes #493

@Anthchirp Anthchirp added the housekeeping Things which would make cctbx tidier - and easier to understand for regular Python programmers label Jul 11, 2020
@Anthchirp
Copy link
Member Author

If there are no concerns I'll merge this on the coming weekend

@nksauter
Copy link
Contributor

nksauter commented Jul 15, 2020 via email

@Anthchirp
Copy link
Member Author

Dear Nick,

good to hear from you. I have raised this issue previously (#493) however as I haven't had any response I went ahead and prepared this patchset, as suggested by our official CCTBX contribution guidelines, https://github.com/cctbx/cctbx_project/blob/master/CONTRIBUTING.md.

In fact, you will find I followed those to the letter. I followed local code styles and did not touch anything unrelated to the issue at hand. I explicitly preserved even the (most certainly unused) leftover helper functions, as pointed out in the pull request, to avoid any interface breakages.

All 95 test suites were successfully run on the pull request - as indicated by the 95 green ticks. So please forgive me when I am a bit confused about where you see any potential issues.
Would you be able to narrow down your concerns? Then I could move changes to any modules that you are concerned about into separate pull requests. This is easy enough - as you can see I intentionally laid out the pull request to have a single commit per module.

Obviously I'm happy for you to review and validate my changes and await your constructive and timely feedback. I would of course also gladly review any alternative pull requests.

Best wishes

-Markus

@bkpoon
Copy link
Member

bkpoon commented Jul 16, 2020

I'll have more time next week to look through this, but here are a few points based on a cursory look.

  1. There is code duplication where the cmp function is implemented several times (if/else blocks that return -1, 0, or 1). Please put the standard implementation of cmp that does not use if/else in libtbx/math_utils.py. The round2 function is there, so might as well put cmp in there too.
  2. Currently, the mmtbx tests are not being run on Azure Pipelines, so they have to be run manually. I'll run them in a phenix build. @olegsobolev can you take a look as well?
  3. Some of the lambda functions can be replaced with itemgetter or attrgetter from the operator module. This was already done for some other sorting calls that used lambda functions.

@Anthchirp
Copy link
Member Author

I've made the requested changes.

It would be great to get this in because the deprecation warnings are making it difficult to spot real issues:

image

@phyy-nx
Copy link
Contributor

phyy-nx commented Jul 31, 2020

Rebasing onto master should fix the XFEL CI tests.

@phyy-nx
Copy link
Contributor

phyy-nx commented Jul 31, 2020

Ah, I see the XFEL CI tests are run twice, once on the branch which is behind master, and once on the merged code (near the bottom of the list) where they are passing. No worries then.

mmtbx/validation/clashscore.py Outdated Show resolved Hide resolved
mmtbx/validation/clashscore.py Outdated Show resolved Hide resolved
cctbx/sgtbx/__init__.py Outdated Show resolved Hide resolved
mmtbx/ions/identify.py Outdated Show resolved Hide resolved
mmtbx/ions/identify.py Outdated Show resolved Hide resolved
scitbx/graph/tardy_tree.py Outdated Show resolved Hide resolved
scitbx/graph/tardy_tree.py Outdated Show resolved Hide resolved
Copy link
Member

@bkpoon bkpoon left a comment

Choose a reason for hiding this comment

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

There are still a few duplicate cmp implementations.

@bkpoon
Copy link
Member

bkpoon commented Aug 4, 2020

Looks good, thanks!

@Anthchirp Anthchirp merged commit c06ac0a into master Aug 4, 2020
@Anthchirp
Copy link
Member Author

Thank you for the review!

@Anthchirp Anthchirp deleted the cmp branch August 4, 2020 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Things which would make cctbx tidier - and easier to understand for regular Python programmers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove 'from past.builtins import cmp'
4 participants