Remove Python2 support #11881

pull jnewbery wants to merge 2 commits into bitcoin:master from jnewbery:remove_python2 changing 13 files +80 −87
  1. jnewbery commented at 7:53 pm on December 12, 2017: member

    Following discussion here: #11843 (comment)

    It’s easier for maintainers if all python tools/scripts support only a single version of Python. There are only a few scripts that aren’t explicitly python3 at this point, so this PR changes those remaining scripts to explicitly require python3.

  2. practicalswift commented at 8:37 pm on December 12, 2017: contributor

    Strong concept ACK!

    Pros:

    • Less work required to maintain the Python scripts
    • Avoids potential bugs due to subtle Python 2/3 incompatibilities

    Cons:

    • ?
  3. MarcoFalke commented at 9:25 pm on December 12, 2017: member
    ACK for devtools. Not sure about unit tests and user facing scripts such as rpcauth.py, see also discussion in #11433
  4. fanquake added the label Brainstorming on Dec 12, 2017
  5. jnewbery commented at 10:10 pm on December 12, 2017: member

    Marco, your comment from #11433:

    I am not against deprecating py2, but we should do it properly such that ./configure fails early and warns about it. Also it should be mentioned in the release notes.

    Would you support this PR for all Python files including user-facing scripts and tests if it met those conditions?

  6. droark commented at 11:10 pm on December 12, 2017: contributor

    Concept ACK. I’m not aware of any major projects still on Py2 and intending to stay there. AFAIK, just about everything that’s still Py2 is due to legacy and/or manpower issues. Here’s how I’d like to see things handled.

    • Make the decision to go Py3-only.
    • Add something in release notes for the next major version (0.16 or 0.17, I assume) indicating that Py2 will no longer be usable in the following version.
    • Make the changes, and force any config/make materials reliant on Python to ensure that Py3 is present.
  7. MarcoFalke commented at 11:27 pm on December 12, 2017: member
    @jnewbery I’d be -0 on that. The reason that the functional tests run at 3.4+ only, is because it would be nearly impossible to have them compatible with both 2.7 and 3.4. However, the python code used for the unit tests and the few scripts meant for users is rather condensed and hopefully not much refactored in the future. So by not touching them, they should keep their compatibility. Note that the loose scripts are not (regularly) tested on py2 nor py3, so just declaring that they no longer function with py2 isn’t a huge improvement. (Or making them merly incompatible with py2 isn’t a huge improvement either, imo). As long as they are not rewritten in a large-ish way, I don’t see why we should change the dependency requirements…
  8. laanwj commented at 8:02 am on December 19, 2017: member

    ACK on the idea to go Py3-only long-term. There’s a burden on supporting multiple versions of python and that burden will only become larger as Python 3 progresses, by locking us out of new features and better ways to do things.

    (this is a similar argument as that for going to C++11)

    The only problematic case are scripts that depend on libraries that only support Python2. These are rare, but I vaguely remember some of the macdeploy scripts do, so please test those carefully.

    As long as they are not rewritten in a large-ish way, I don’t see why we should change the dependency requirements…

    I also agree with this, though. There’s no urgent reason to make this change at once, certainly for scripts that are hardly touched.

  9. droark commented at 8:14 am on December 19, 2017: contributor

    @laanwj - I haven’t tried the scripts yet but I think macdeploy’s libraries all support Py3. It looks like there are three external packages: biplist, ds_store, and mac_alias. The commit lists seem to indicate that there’s a reasonable chance all of them have Py3 support, or at least enough to get macdeploy to run. I’ll give macdeploy a spin soon and submit upstream patches if necessary.

    EDIT: Wrong biplist link.

  10. fanquake commented at 8:41 am on December 19, 2017: member
    We are still patching biplist and mac_alias, so you could definitely send those patches upstream.
  11. laanwj commented at 10:07 am on December 19, 2017: member
    OTOH the situation of having some things work in py2 but not others is confusing. It doesn’t really benefit anyone, and there’s also an overhead explaining it to contributors. That’s one argument for doing this at once.
  12. droark commented at 9:05 pm on December 19, 2017: contributor
    @fanquake - Yep, mac_alias doesn’t have those fixes. I’ll submit upstream. I’ll also try with biplist but I don’t know how that’ll go, since it’s not a Py3 fix.
  13. droark commented at 10:49 pm on December 19, 2017: contributor
    Have submitted PRs for biplist (not Py3) and mac_alias. It’s a start!
  14. in contrib/devtools/optimize-pngs.py:40 in bbe67bdd82 outdated
    36@@ -37,7 +37,7 @@ def content_hash(filename):
    37     for file in os.listdir(absFolder):
    38         extension = os.path.splitext(file)[1]
    39         if extension.lower() == '.png':
    40-            print("optimizing "+file+"..."),
    41+            print("optimizing "+file+"...")
    


    ryanofsky commented at 4:03 pm on December 20, 2017:

    Trailing comma in python2 outputs space instead of newline. I think equivalent in python3 would be

    0print("optimizing {}...".format(file), end=' ')
    

    jnewbery commented at 3:33 pm on February 27, 2018:
    thanks. Fixed

    MarcoFalke commented at 2:00 pm on March 19, 2018:
    Was this fixed?
  15. in contrib/devtools/optimize-pngs.py:68 in bbe67bdd82 outdated
    69                 sys.exit(1)
    70 
    71             fileMetaMap['psize'] = os.path.getsize(file_path)
    72             outputArray.append(fileMetaMap)
    73-            print("done\n"),
    74+            print("done\n")
    


    ryanofsky commented at 4:09 pm on December 20, 2017:
    equivalent would be print("done")

    jnewbery commented at 3:33 pm on February 27, 2018:
    thanks. Fixed

    MarcoFalke commented at 2:01 pm on March 19, 2018:
    Same here
  16. in contrib/macdeploy/macdeployqtplus:729 in bbe67bdd82 outdated
    724             retcode = process.poll()
    725             if retcode:
    726                 cmd = kwargs.get("args")
    727                 if cmd is None:
    728                     cmd = popenargs[0]
    729-                raise CalledProcessError(retcode, cmd)
    


    ryanofsky commented at 4:13 pm on December 20, 2017:
    This was just broken before, I guess? I don’t see how it could have worked.

    jnewbery commented at 3:33 pm on February 27, 2018:
    indeed
  17. ryanofsky commented at 4:21 pm on December 20, 2017: member
    utACK bbe67bdd82925cc72a868bb3de1896e61cae79db. Since this marked WIP, it might be good to update the PR description to say what other changes are underway or planned.
  18. laanwj added this to the milestone 0.17.0 on Feb 23, 2018
  19. laanwj commented at 4:37 pm on February 23, 2018: member
    Needs rebase, I think we should do this for 0.17.
  20. droark commented at 5:19 pm on February 23, 2018: contributor
    Just for cross-referencing, the mac_alias patch made it into the mainline and was removed from Core here. I pinged the biplist maintainer. He said he’d been busy and would take a look at my PR eventually.
  21. practicalswift commented at 10:12 pm on February 23, 2018: contributor
    @laanwj Excellent! Let’s get rid of Python 2!
  22. droark commented at 3:54 am on February 26, 2018: contributor

    Hi. Andrew (the biplist maintainer) reviewed the Core patch and rejected it. Here’s his rationale. Any thoughts? I admit that I’m not super familiar with the biplist codebase, so it would take a little time for me to come up with a coherent response.

    (Technically, this isn’t a Py3 issue, but since I brought it up here earlier….)

    I looked into this, and it looks like v1.0.2 added sorting of sets and dictionary keys when writing, which is the change needed for reproducible builds. The patch from Bitcoin Core targets biplist v0.9, which didn’t have this sorting.

    The below two changes from the Bitcoin Core patch seem to have any effect when writing plists, AFAICT (please correct me if I am wrong). One is wrapping the root dict in a hashable wrapper, so sorting the keys doesn’t matter. The other is for computing some values in the file trailer related to how many unique objects there are in the file and how many bytes it takes to represent the offsets to those objects within the file.

    That said, this is under-tested, so I added a test for what I expect the output to be.

    Thanks!

    EDIT 1: I think the “two changes” comment had to do with this commit, which is the 1.0.2 commit that supposedly adds sorting.

    EDIT 2: biplist has been sorted out.

  23. jnewbery force-pushed on Feb 27, 2018
  24. jnewbery commented at 3:36 pm on February 27, 2018: member

    Rebased and addressed @ryanofsky’s review comments.

    Since this marked WIP, it might be good to update the PR description to say what other changes are underway or planned.

    This is marked as WIP since I was looking for initial feedback and haven’t tested or carefully reviewed my suggested changes. Since there seems to be some enthusiasm for removing python2 support, I’ll clean this PR up.

  25. jtimon commented at 9:25 pm on February 27, 2018: contributor
    Concept ACK
  26. jnewbery force-pushed on Feb 28, 2018
  27. jnewbery force-pushed on Feb 28, 2018
  28. eklitzke commented at 9:03 am on March 11, 2018: contributor

    Concept ACK.

    wrt the comments from @droark, it’s easy to wrap iterator types using sorted() or types like collections.OrderedDict(). If reproducibility is an issue then we should handle that, but that’s possible to achieve in Py3 (and if Py2 code relies on it, that code is broken anyway).

  29. ryanofsky commented at 10:22 pm on March 12, 2018: member
    utACK 4f3238250bc01eedee7c60b4d6681d3e21c6783c. Changes since last review were porting check-doc.py, fixing newlines for prints with trailing commas, updating copyright years.
  30. practicalswift commented at 10:27 pm on March 12, 2018: contributor
    utACK 4f3238250bc01eedee7c60b4d6681d3e21c6783c
  31. MarcoFalke renamed this:
    [WIP] [concept] Remove Python2 support
    [contrib] Remove Python2 support
    on Mar 13, 2018
  32. in contrib/macdeploy/macdeployqtplus:206 in 4f3238250b outdated
    201@@ -203,7 +202,7 @@ def getFrameworks(binaryPath, verbose):
    202     if verbose >= 3:
    203         print("Inspecting with otool: " + binaryPath)
    204     otoolbin=os.getenv("OTOOL", "otool")
    205-    otool = subprocess.Popen([otoolbin, "-L", binaryPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    206+    otool = subprocess.Popen([otoolbin, "-L", binaryPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
    207     o_stdout, o_stderr = otool.communicate()
    


    MarcoFalke commented at 4:28 pm on March 13, 2018:

    You changed this to universal_newlines, so the type should be str.

    Thus, the decode a couple of lines down will fail.


    jnewbery commented at 12:55 pm on March 19, 2018:
    Thanks. Fixed
  33. MarcoFalke added the label Scripts and tools on Mar 13, 2018
  34. MarcoFalke removed the label Brainstorming on Mar 13, 2018
  35. MarcoFalke commented at 4:29 pm on March 13, 2018: member
    • Changed title-tag.
    • Needs feedback addressed.
  36. jnewbery commented at 11:23 pm on March 15, 2018: member
    Thanks all for review. Will address feedback next week.
  37. jnewbery force-pushed on Mar 19, 2018
  38. jnewbery force-pushed on Mar 19, 2018
  39. in contrib/devtools/check-doc.py:33 in 439245301f outdated
    32@@ -33,12 +33,12 @@ def main():
    33   args_need_doc = args_used.difference(args_docd)
    


    MarcoFalke commented at 9:12 pm on March 23, 2018:

    One line above this:

    You are switching this file to python3, so check_output will return byte-strings instead of text strings. Thus, you can not apply a regex on them.


    ryanofsky commented at 9:44 pm on March 23, 2018:
    Should be fixable if you switch the patterns to bytestrings b'pattern'
  40. jnewbery force-pushed on Mar 26, 2018
  41. Change all python files to use Python3 bc6fdf2d15
  42. jnewbery force-pushed on Mar 26, 2018
  43. jnewbery commented at 8:52 pm on March 26, 2018: member

    I’ve gone through and reviewed/tested my changes, and I think they’re good. Ready for wider review.

    The only python file that is not now explicitly Python3 is gen_base58_test_vectors.py. It would require some substantial modifications to work in Python3 (since it’s using string/bytes manipulation which changed completely between Python2 and Python3). That file is not modified or used very much, so I’ve left it as Python2, adding an explicit note to the doc string saying that it’s Python2 only.

  44. jnewbery renamed this:
    [contrib] Remove Python2 support
    Remove Python2 support
    on Mar 26, 2018
  45. in doc/release-notes.md:123 in bc6fdf2d15 outdated
    116@@ -117,6 +117,11 @@ deprecated in V0.15.1, and has now been removed. Miners should use the
    117 `-blockmaxweight` option if they want to limit the weight of their blocks'
    118 weights.
    119 
    120+Python Support
    121+--------------
    122+
    123+Support for Python 2 has been discontinued for all test files and tools.
    


    MarcoFalke commented at 9:11 pm on March 26, 2018:
    NACK based on my earlier feedback in this pull request.

    jnewbery commented at 7:44 pm on March 27, 2018:

    I disagree. We should remove support for a legacy language which will soon not be maintained, and which may hide subtle bugs due to incompatibilities with the new language.

    What do we gain by claiming to support python2?


    MarcoFalke commented at 11:10 pm on March 27, 2018:
    I am not saying we should claim to support python2, but we should not claim that python2 support has been discontinued for “all test files” (specifically util tests, since the functional tests are already on python3). I think it is reasonable to support python2 util tests until we need to switch off of it because it would otherwise be a burden to continue to support python2. I don’t see why we should put effort into making the util tests incompatible with python2 when we might as well leave them supported on a best effort basis.

    droark commented at 0:08 am on March 28, 2018:
    @MarcoFalke - Honestly, supporting on a “best effort basis” seems like a nightmare waiting to happen. Person A introduces a commit that breaks Py2 compatibility, Person B complains that unit tests are failing, Persons C-? have to deal with the whole thing. I think having 2 & 3 supported is good for transition purposes, and making sure that nothing is broken during a switch. Beyond that, I’m with @jnewbery and don’t see any real gain from claiming to support Py2. At most, I’d be okay with a statement mentioning that, while Py2 compatibility is best effort, people must use Py3 before complaining that unit tests fail.

    MarcoFalke commented at 0:53 am on March 28, 2018:
    I think it is not worth arguing about that.
  46. MarcoFalke commented at 9:12 pm on March 26, 2018: member

    Concept ACK on the diff (excluding change to doc/release-notes.md)

    Will review after revert.

  47. laanwj commented at 7:17 pm on March 27, 2018: member

    That file is not modified or used very much, so I’ve left it as Python2, adding an explicit note to the doc string saying that it’s Python2 only.

    I might port it over some time - agree it’s not relevant to this PR (as it’s never called by the test framework, build system, nor any other script.)

  48. MarcoFalke commented at 0:53 am on March 28, 2018: member
    utACK bc6fdf2d15648a5fc68df8021d9186737de6fe7b
  49. eklitzke commented at 2:07 am on March 28, 2018: contributor
    ACK bc6fdf2d15648a5fc68df8021d9186737de6fe7b @jnewbery @MarcoFalke cherry-pick https://github.com/eklitzke/bitcoin/commit/563b4f5e398ca8824d42fe271d1485eb3934ed41 if you would like to make the base58 code work on python3
  50. Make base58 python contrib code work with python3 18740586ba
  51. jnewbery force-pushed on Mar 28, 2018
  52. jnewbery commented at 1:21 pm on March 28, 2018: member
    Thanks @eklitzke - I’ve cherry-picked your commit (updating the hashbang and docstring).
  53. practicalswift commented at 2:00 pm on March 28, 2018: contributor
    utACK 18740586baee546064cba9286e2d681a849ae443
  54. laanwj merged this on Mar 28, 2018
  55. laanwj closed this on Mar 28, 2018

  56. laanwj referenced this in commit 624bee9659 on Mar 28, 2018
  57. jnewbery deleted the branch on Mar 28, 2018
  58. ken2812221 commented at 5:24 pm on March 28, 2018: contributor

    gitian build fails on security-check.py

  59. jnewbery commented at 5:36 pm on March 28, 2018: member
    huh. That’s confusing. All the other calls to subprocess.Popen expect stdout to be bytes, but line 124 expects stdout to be a string. Will open a fixup PR.
  60. jnewbery commented at 5:38 pm on March 28, 2018: member
    @ken2812221 thanks for reporting this. Can you try again with https://github.com/jnewbery/bitcoin/tree/python3_fixup and let me know if it resolves your issue?
  61. ken2812221 commented at 6:17 pm on March 28, 2018: contributor

    @jnewbery After apply your commit

  62. ken2812221 commented at 6:21 pm on March 28, 2018: contributor
  63. jnewbery commented at 6:35 pm on March 28, 2018: member
    Thanks @ken2812221 . I’ve pushed a new commit. Can you retry?
  64. ken2812221 commented at 7:07 pm on March 28, 2018: contributor
  65. jnewbery commented at 7:51 pm on March 28, 2018: member
    New branch pushed. Can you try again?
  66. in contrib/devtools/optimize-pngs.py:46 in 18740586ba
    46-            pngCrushOutput = ""
    47             try:
    48-                pngCrushOutput = subprocess.check_output(
    49-                        [pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
    50-                        stderr=subprocess.STDOUT).rstrip('\n')
    51+                subprocess.call([pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
    


    MarcoFalke commented at 8:10 pm on March 28, 2018:
    Post-merge nit: Should probably use check_call instead.
  67. ken2812221 commented at 8:26 pm on March 28, 2018: contributor
    Building windows is OK, but buiding linux still fail at check-symbols as I post on gist
  68. jnewbery commented at 8:59 pm on March 28, 2018: member
    Please retry check-symbols.py with latest commit.
  69. ken2812221 commented at 2:21 am on March 29, 2018: contributor

    This commit really works. Thanks.

    John Newbery notifications@github.com 於 2018年3月29日 週四 上午5:00 寫道:

    Please retry check-symbols.py with latest commit.

    — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/pull/11881#issuecomment-377034521, or mute the thread https://github.com/notifications/unsubscribe-auth/AKoyxmr-s3wbujdQem_HsInxNN1Agzk7ks5ti_nagaJpZM4Q_imm .

  70. laanwj referenced this in commit 082e26c08b on Mar 29, 2018
  71. jnewbery commented at 2:18 pm on March 29, 2018: member
    @ken2812221 , thanks so much for your patience and help here. I’ve opened a PR to fix symbol-check and security-check: #12829
  72. practicalswift commented at 2:31 pm on March 29, 2018: contributor
    Goodbye Python 2. Welcome Python 3!
  73. laanwj referenced this in commit 252c1b0fae on Mar 29, 2018
  74. codablock referenced this in commit 79f578ae17 on Aug 13, 2018
  75. codablock referenced this in commit efda0ccf71 on Aug 13, 2018
  76. UdjinM6 referenced this in commit 7cf9572c26 on Aug 13, 2018
  77. jonasschnelli referenced this in commit 1c4e1aa8a9 on Oct 11, 2018
  78. MarcoFalke referenced this in commit acbbb7bf0d on Mar 17, 2019
  79. CryptoCentric referenced this in commit 7fd2c46693 on Apr 25, 2019
  80. PastaPastaPasta referenced this in commit 2aee09c5ab on Dec 16, 2020
  81. PastaPastaPasta referenced this in commit a2d0a288c4 on Dec 18, 2020
  82. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me