ESMCI / git-fleximod

MIT License
2 stars 2 forks source link

Need to trap python not being new enough #23

Closed cacraigucar closed 3 months ago

cacraigucar commented 3 months ago

I'm moving this from the ESCOMP/CAM PR. I should point out that @jtruesdal also tripped across this on izumi, so I'm sure others will as well.


I'm pretty sure I won't be the only user to trip on this on izumi. I'm not sure why it is happening. I have two requests: 1) Trap and write out a meaningful message if python is not new enough to support git-fleximod - if that is what this error message means. 2) Figure out why when I set python in my .profile and then use git-fleximod it doesn't work. But when I load it manually, it does. This is on izumi, and I suspect other users on izumi may have the same problem. See the listing below:

izumi$ bin/git-fleximod -h
ImportError: No module named site
izumi$ module list
Currently Loaded Modulefiles:
 1)lang/python/3.11.5
izumi$ module load lang/python/3.11.5
module-info mode load in progress
    Unloading python module: lang/python/3.11.5
izumi$ bin/git-fleximod -h
usage: git-fleximod [-h] [-C PATH] [-g [GITMODULES]] [-x [EXCLUDE ...]] [-f] [-o] [-v] [-V] [--backtrace] [-d]
                    {update,status,test} [components ...]  *** The rest of the help message was written out 
jedwards4b commented 3 months ago

I don't think that there is an issue here that I can address. I am using the default python 3.7.0 on izumi and it works fine. The command line you print out above shows module lang/python/3.11.5 is loaded and then loaded a second time?

module list
No Modulefiles Currently Loaded.
[jedwards@izumi cesm2_3_alpha17c_rme]$ python --version
Python 3.7.0
[jedwards@izumi cesm2_3_alpha17c_rme]$ bin/git-fleximod -h
usage: git-fleximod [-h] [-C PATH] [-g [GITMODULES]]
                    [-x [EXCLUDE [EXCLUDE ...]]] [-f] [-o] [-v] [-V]
                    [--backtrace] [-d]
                    {update,status,test} [components [components ...]]

    git-fleximod manages checking out groups of gitsubmodules with addtional support for Earth System Models

positional arguments:
  {update,status,test}  Subcommand of git-fleximod, choices are ['update',
                        'status']
  components            Specific component(s) to checkout. By default, all
                        required submodules are checked out.

optional arguments:
  -h, --help            show this help message and exit
  -C PATH, --path PATH  Toplevel repository directory. Defaults to top git
                        directory relative to current.
  -g [GITMODULES], --gitmodules [GITMODULES]
                        The submodule description filename. Default:
                        .gitmodules.
  -x [EXCLUDE [EXCLUDE ...]], --exclude [EXCLUDE [EXCLUDE ...]]
                        Component(s) listed in the gitmodules file which
                        should be ignored.
  -f, --force           Override cautions and update or checkout over locally
                        modified repository.
  -o, --optional        By default only the required submodules are checked
                        out. This flag will also checkout the optional
                        submodules relative to the toplevel directory.
  -v, --verbose         Output additional information to the screen and log
                        file. This flag can be used up to two times,
                        increasing the verbosity level each time.
  -V, --version         Print version and exit.
  --backtrace           DEVELOPER: show exception backtraces as extra
                        debugging output
  -d, --debug           DEVELOPER: output additional debugging information to
                        the screen and log file.
[jedwards@izumi cesm2_3_alpha17c_rme]$ module load lang/python/3/11/5
ModuleCmd_Load.c(213):ERROR:105: Unable to locate a modulefile for 'lang/python/3/11/5'
[jedwards@izumi cesm2_3_alpha17c_rme]$ module load lang/python/3.11.5
module-info mode load in progress
[jedwards@izumi cesm2_3_alpha17c_rme]$ bin/git-fleximod -h
usage: git-fleximod [-h] [-C PATH] [-g [GITMODULES]] [-x [EXCLUDE ...]] [-f] [-o] [-v] [-V] [--backtrace] [-d]
                    {update,status,test} [components ...]

    git-fleximod manages checking out groups of gitsubmodules with addtional support for Earth System Models

positional arguments:
  {update,status,test}  Subcommand of git-fleximod, choices are ['update', 'status']
  components            Specific component(s) to checkout. By default, all required submodules are checked out.

options:
  -h, --help            show this help message and exit
  -C PATH, --path PATH  Toplevel repository directory. Defaults to top git directory relative to current.
  -g [GITMODULES], --gitmodules [GITMODULES]
                        The submodule description filename. Default: .gitmodules.
  -x [EXCLUDE ...], --exclude [EXCLUDE ...]
                        Component(s) listed in the gitmodules file which should be ignored.
  -f, --force           Override cautions and update or checkout over locally modified repository.
  -o, --optional        By default only the required submodules are checked out. This flag will also checkout the optional
                        submodules relative to the toplevel directory.
  -v, --verbose         Output additional information to the screen and log file. This flag can be used up to two times,
                        increasing the verbosity level each time.
  -V, --version         Print version and exit.
  --backtrace           DEVELOPER: show exception backtraces as extra debugging output
  -d, --debug           DEVELOPER: output additional debugging information to the screen and log file.
cacraigucar commented 3 months ago

Let me rephrase the issue. If a user does not have python loaded, they get:

izumi$ bin/git-fleximod update
Traceback (most recent call last):
  File "bin/git-fleximod", line 5, in <module>
    from git_fleximod.git_fleximod import main
  File "/home/cacraig/cam4_remove_manage_externals/.lib/git-fleximod/git_fleximod/git_fleximod.py", line 156
    print(f"Successfully checked out {name:>20} at {tag}")
                                                        ^
SyntaxError: invalid syntax

I suggest that this should be trapped as it does not indicate that they need to have python installed. I did module unload to simulate this

jedwards4b commented 3 months ago

Please run python --version in the state when you get that error and report the result.

cacraigucar commented 3 months ago

How does the user know that this a python error? They typed in bin/git-fleximod and got this error that say "invalid syntax". Their immediate thought might be "what did I type in wrong".

I looked at what cime is doing (as it works with python unloaded) vs. git-fleximod and I see that cime is specifying python3 whereas git-fleximod is just specifying python. When I add "3" onto the end of the first #! line, it works fine with python unloaded. Perhaps this is the fix?

jedwards4b commented 3 months ago

@cacraigucar do you agree that this issue has been resolved and can be closed?

cacraigucar commented 3 months ago

Yes, I can run on izumi with no modules loaded, and the command works fine.