classification
Title: Replace optparse with argparse in setup.py
Type: enhancement Stage: resolved
Components: Build Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Chi Hsuan Yen, brett.cannon, haypo, serhiy.storchaka, skrah, xdegaye
Priority: normal Keywords: patch

Created on 2017-02-04 07:26 by Chi Hsuan Yen, last changed 2017-02-19 19:29 by brett.cannon.

Pull Requests
URL Status Linked Edit
PR 139 open Chi Hsuan Yen, 2017-02-16 16:10
Messages (14)
msg286922 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-04 07:26
The change is clear and self-explained. See the patch.

Motivations:

1. The hack "To prevent optparse from raising an exception..." works for single letter flags (-I, -L, etc.) only. I plan to add --sysroot related codes for Android builds and I don't want more hacks. Apparently argparse does not need this hack as it can parse all known flags before throwing an error
2. optparse is deprecated

Add the developer that introduced this hack. Also Serhiy, who sseems interested in removing optparse from the code base. (issue18973, issue18971)
msg286977 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-02-04 16:55
I didn't look at this one, but some "hacks" are necessary in setup.py (example: usage of os.system() in some places).
msg287691 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-13 13:33
I've found a simpler patch set for supporting Android builds, so I don't need this patch anymore. If you don't think it's necessary, just close it.

> usage of os.system() in some places

I'm indeed sick with them :D
msg287696 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-02-13 14:27
It's not a matter of *necessary*, you simply cannot use argparse in setup.py.  Try to build with your patch and you'll see.
msg287700 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-13 15:04
I have used my old patch several days on Android, and it seems quite fine. Anyway that's not important anymore.
msg287702 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-02-13 15:09
On Mon, Feb 13, 2017 at 03:04:09PM +0000, Chi Hsuan Yen wrote:
> 
> Chi Hsuan Yen added the comment:
> 
> I have used my old patch several days on Android, and it seems quite fine. Anyway that's not important anymore.

I find that very surprising:

./python -E -S -m sysconfig --generate-posix-vars ;\
        if test $? -ne 0 ; then \
                echo "generate-posix-vars failed" ; \
                rm -f ./pybuilddir.txt ; \
                exit 1 ; \
        fi
Traceback (most recent call last):
  File "./setup.py", line 4, in <module>
    import sys, os, importlib.machinery, re, argparse
  File "/home/stefan/althome/pydev/commit-master-LATEST/Lib/argparse.py", line 93, in <module>
    from gettext import gettext as _, ngettext
  File "/home/stefan/althome/pydev/commit-master-LATEST/Lib/gettext.py", line 49, in <module>
    import locale, copy, io, os, re, struct, sys
  File "/home/stefan/althome/pydev/commit-master-LATEST/Lib/struct.py", line 13, in <module>
    from _struct import *
ModuleNotFoundError: No module named '_struct'

Yes, it is important, because you called the original a "dirty hack", which
some core devs do not appreciate.
msg287705 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-13 15:46
You're right. argparse has indirect dependency on dynamic modules so it can't be used in setup.py. Cross builds use prebuilt Python binaries so there's no problem. Sorry for those noises.

I still think it's a dirty hack as it limits scalability and brings lots of problems when adding new features, but I can't find a good way to remove it :(
msg287855 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-15 13:59
Aha the fix is simple => issue29567
msg287956 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-16 16:13
Now I have a working patch at PR 139, and dropping optparse is still the way to go, so I reopen it.

I'm not familiar with CPython conventions. Sorry if reopening an issue is impolite.
msg287964 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-02-16 17:48
It's okay to reopen if some conditions have changed (which is the case here).
msg288125 - (view) Author: Xavier de Gaye (xdegaye) * (Python committer) Date: 2017-02-19 10:42
> I'm not familiar with CPython conventions. Sorry if reopening an issue is impolite.

IMO asking if it's ok to reopen this issue by using the word 'impolite' is a clear reference to the fact that Stefan had told you previously that you are being insulting by saying "it's a dirty hack ". Not only did not you take the opportunity given by Stefan at that time to express your apologies as expected, but instead you repeated it, and here your are making fun of him by using the word 'impolite' when you could have asked if it is correct or allowed to reopen an issue.

Few months ago you uttered the same kind of insults then directed at me in msg264605, a post addressed to Guido van Rossum in issue 26858.

Please do read the CPython Code of Conduct and try to remember that the people that take the time to answer your posts do it on their own free time and that you should be nice to them.

I am nosying Brett Cannon, the CPython maintainer and core dev in charge of the respect of the CoC.
msg288127 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-02-19 11:14
I see your points. Indeed in many times I didn't think carefully before leaving a comment, and not even noticing that my comments can be offensive afterwards. I apologize for all those cases and I'll be more careful when interacting with others in the future.

@Xavier: I'm gratitude for your patience on taking so much time explaining what I've done wrong. It's an invaluable course.

Let me change the title of this issue first. That will make it more moderate and also clearer.
msg288132 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-19 13:18
> (example: usage of os.system() in some places)

See similar issue7438.
msg288159 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2017-02-19 19:29
I just wanted to acknowledge that I read this thread. I accept Chi's acknowledgement of his actions and I hope there aren't future missteps, but please also realize that there has been a warning about how you communicate here, Chi.
History
Date User Action Args
2017-02-19 19:29:21brett.cannonsetmessages: + msg288159
2017-02-19 13:18:19serhiy.storchakasetmessages: + msg288132
2017-02-19 11:14:50Chi Hsuan Yensetmessages: + msg288127
title: Use argparse and drop dirty optparse hacks in setup.py -> Replace optparse with argparse in setup.py
2017-02-19 10:42:26xdegayesetnosy: + brett.cannon, xdegaye, haypo
messages: + msg288125
2017-02-16 17:48:17skrahsetmessages: + msg287964
2017-02-16 16:13:36Chi Hsuan Yensetfiles: - setup-argparse.patch
2017-02-16 16:13:17Chi Hsuan Yensetstatus: closed -> open
resolution: not a bug ->
messages: + msg287956
2017-02-16 16:10:05Chi Hsuan Yensetpull_requests: + pull_request99
2017-02-15 13:59:17Chi Hsuan Yensetmessages: + msg287855
2017-02-13 15:46:04Chi Hsuan Yensetmessages: + msg287705
2017-02-13 15:09:41skrahsetmessages: + msg287702
2017-02-13 15:04:09Chi Hsuan Yensetmessages: + msg287700
2017-02-13 14:51:43skrahsetstatus: open -> closed
resolution: not a bug
stage: resolved
2017-02-13 14:27:04skrahsetmessages: + msg287696
2017-02-13 13:33:32Chi Hsuan Yensetmessages: + msg287691
2017-02-05 22:15:26brett.cannonsetnosy: - brett.cannon
2017-02-04 16:55:21skrahsetnosy: + skrah
messages: + msg286977
2017-02-04 07:26:28Chi Hsuan Yencreate