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

Added main module detection and cli construction, now should show the… #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KOLANICH
Copy link
Contributor

@KOLANICH KOLANICH commented Dec 5, 2017

… right name (instead of __main__.py) when called for modules

@coveralls
Copy link

coveralls commented Dec 5, 2017

Coverage Status

Coverage decreased (-1.5%) to 80.925% when pulling 5452a47 on KOLANICH:better_app_name_in_help into 605d068 on tomerfiliba:master.

@henryiii
Copy link
Collaborator

henryiii commented Dec 6, 2017

Needs Python 2 support and a test, do you think you could add those? (I might be able to do the Py2 support if you add a test.) If a test is not possible, then at least a little example would help.

@KOLANICH
Copy link
Contributor Author

KOLANICH commented Dec 6, 2017

Sorry, I'm not going to add them, I have no time for it. But I have tested that against my apps using plumbum.cli, they work as indended. If we strictly need tests, something like https://github.com/laffra/auger (an automatic tests generator) may be helpful.

@KOLANICH
Copy link
Contributor Author

KOLANICH commented Dec 6, 2017

About python2: how 'bout dropping support of it?

@henryiii
Copy link
Collaborator

henryiii commented Dec 6, 2017

For a end-user library, sure; but for something like Plumbum it can't be done, at least for a few more years. Plumbum needs to work anywhere a shell script works, and by default, CentOS7 and macOS still only provide Python 2. And I also work for LHCb, and they are not supporting Python 3 for another year or two. Rewriting 1M+ lines of code is not easy. I can't even drop Python 2.6 support yet since it is default on SL6 😢

@henryiii
Copy link
Collaborator

henryiii commented Dec 6, 2017

I'll look at adding tests then, but it will be a while before I have time.

@KOLANICH KOLANICH changed the title _Added main module detection and cli construction, now should show the… Added main module detection and cli construction, now should show the… Dec 6, 2017
@coveralls
Copy link

coveralls commented Dec 10, 2017

Coverage Status

Coverage decreased (-1.3%) to 80.925% when pulling ac5a391 on KOLANICH:better_app_name_in_help into 1650815 on tomerfiliba:master.

@coveralls
Copy link

coveralls commented Dec 12, 2017

Coverage Status

Coverage decreased (-1.4%) to 80.902% when pulling 6412f8a on KOLANICH:better_app_name_in_help into 1650815 on tomerfiliba:master.

@coveralls
Copy link

coveralls commented Dec 28, 2017

Coverage Status

Coverage decreased (-1.3%) to 79.921% when pulling 0224797 on KOLANICH:better_app_name_in_help into 46da89d on tomerfiliba:master.

@KOLANICH KOLANICH force-pushed the better_app_name_in_help branch 2 times, most recently from 7f7ee83 to 689cc58 Compare February 12, 2020 17:03
@KOLANICH KOLANICH force-pushed the better_app_name_in_help branch 2 times, most recently from efad6a8 to c120d2f Compare March 17, 2020 16:42
@henryiii henryiii closed this Jan 3, 2021
@henryiii henryiii reopened this Jan 3, 2021
plumbum/cli/application.py Outdated Show resolved Hide resolved
@henryiii
Copy link
Collaborator

henryiii commented Jan 3, 2021

Wouldn't it have been easier to address the Py2 + test request than to maintain this as a branch for 3+ years? Anyway, Python 2 support is working with one small change.

Currently the only problem is that this breaks the current tests on Windows - it seems it is replacing the program name with python -m __main__?

@KOLANICH
Copy link
Contributor Author

KOLANICH commented Jan 3, 2021

about python - to properly get a name of the executable I had to use ctypes.pythonapi:

import ctypes
import platform
impl = platform.python_implementation()
if impl == "cpython" or impl == "PyPy" :
  ctypes.pythonapi.Py_GetArgcArgv.restype = None
  ctypes.pythonapi.Py_GetArgcArgv.argtypes = [
    ctypes.POINTER(ctypes.c_int),
    ctypes.POINTER(ctypes.POINTER(ctypes.c_wchar_p))
  ]
  def realArgv():
    count = ctypes.c_int()
    args = ctypes.pointer(ctypes.c_wchar_p())
    ctypes.pythonapi.Py_GetArgcArgv(ctypes.byref(count), ctypes.byref(args))
    argc = count.value
    argv = [str(args[i]) for i in range(count.value)]
    return argv
print(realArgv())

but it is not a solution that can be used, since it would break for the impls without ctypes.pythonapi

@KOLANICH KOLANICH force-pushed the better_app_name_in_help branch 2 times, most recently from ae39984 to 6ea694f Compare January 12, 2021 15:33
@henryiii
Copy link
Collaborator

henryiii commented Jan 2, 2022

Could you add a test? I think it's safe to merge now that Py 2 is gone.

@henryiii
Copy link
Collaborator

henryiii commented Jan 2, 2022

Also you can use the original simpler solution, I think, now without Py 2. Is there still an issue on Windows?

@henryiii
Copy link
Collaborator

henryiii commented Oct 6, 2022

assert 'geet add' in "Usage:\n    python -m __main__

Seems to be doing the opposite on Windows?

@KOLANICH
Copy link
Contributor Author

KOLANICH commented Oct 6, 2022

I usually don't use Windows, and I don't know when I use it.
We surely need automated tests for that, and GH CI can be used to test on different platforms (though the code I have written is cross-platform). I'm sorry. To be honest I'm currently occupied by other things, I just saw your merge commit (it seems you cannot force-push into my repo) in notifications and so just rebased my commit over master and force-pushed, since it doesn't require much refocusing.

@henryiii
Copy link
Collaborator

henryiii commented Oct 7, 2022

Okay. I tried to get this working briefly before release, then saw the regression on Windows and left it. I don't use Windows much either, I'm just going from the GHA CI (we do have automated tests here). We also need a test showing the "working" behavior so we can verify it works there too. I'll eventually try to come back by and see if I can fix it, then.

… show the right name (instead of __main__.py) when called for modules

Co-Authored-By: Henry Fredrick Schreiner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants