[issue22240] argparse support for "python -m module" in help

Nils Kattenbeck report at bugs.python.org
Fri Jul 23 12:08:12 EDT 2021


Nils Kattenbeck <nilskemail at gmail.com> added the comment:

I expanded the patch from tebeka to also work with invocations like `python3 -m serial.tools.miniterm` where `miniterm.py` is a file and not a directory with a `__main__.py`. This was able to handle everything I threw at it.

However due to the import of zipfile which itself imports binascii the build of CPython itself fails at the `sharedmods` stage...


```text
 CC='gcc -pthread' LDSHARED='gcc -pthread -shared    ' OPT='-DNDEBUG -g -fwrapv -O3 -Wall' 	_TCLTK_INCLUDES='' _TCLTK_LIBS='' 	./python -E ./setup.py  build
Traceback (most recent call last):
  File "/home/septatrix/Documents/programming/cpython/./setup.py", line 3, in <module>
    import argparse
    ^^^^^^^^^^^^^^^
  File "/home/septatrix/Documents/programming/cpython/Lib/argparse.py", line 93, in <module>
    from zipfile import is_zipfile as _is_zipfile
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/septatrix/Documents/programming/cpython/Lib/zipfile.py", line 6, in <module>
    import binascii
    ^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'binascii'
make: *** [Makefile:639: sharedmods] Error 1
```

I guess this is because binascii is a c module and not yet build at that point in time. Does anyone who knows more about the build system have an idea how to resolve this?

---

Resolving this bug would also allow the removal of several workarounds for this in the stdlib:

* https://github.com/python/cpython/blob/83d1430ee5b8008631e7f2a75447e740eed065c1/Lib/unittest/__main__.py#L4
* https://github.com/python/cpython/blob/83d1430ee5b8008631e7f2a75447e740eed065c1/Lib/json/tool.py#L19
* https://github.com/python/cpython/blob/83d1430ee5b8008631e7f2a75447e740eed065c1/Lib/venv/__init__.py#L426

----------
Added file: https://bugs.python.org/file50174/patch.diff

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue22240>
_______________________________________


More information about the Python-bugs-list mailing list