ESMCI / cime

Common Infrastructure for Modeling the Earth
http://esmci.github.io/cime
Other
162 stars 207 forks source link

Pylint failure #4576

Closed CollinsEM closed 6 months ago

CollinsEM commented 9 months ago

While attempting to install CESM 2.1.* on the Orion cluster at Mississippi State University, I would run the regression test script and noticed that all of the pylint checks were failing with a message similar to the following:

======================================================================
FAIL: test_pylint_src_components_xcpl_comps_xglc_cime_config_buildnml (__main__.B_CheckCode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/apps/contrib/cesm/2.1.5/cime/scripts/tests/scripts_regression_tests.py", line 2758, in test
    self.assertTrue(result == "", msg=result)
AssertionError: False is not true : 
Traceback (most recent call last):
  File "/apps/python-3.9.2/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/apps/python-3.9.2/lib/python3.9/site-packages/pylint/__init__.py", line 36, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/apps/python-3.9.2/lib/python3.9/site-packages/pylint/lint/run.py", line 140, in __init__
    args = _preprocess_options(self, args)
  File "/apps/python-3.9.2/lib/python3.9/site-packages/pylint/config/utils.py", line 273, in _preprocess_options
    cb(run, value)
  File "/apps/python-3.9.2/lib/python3.9/site-packages/pylint/config/utils.py", line 169, in _init_hook
    exec(value)  # pylint: disable=exec-used
  File "<string>", line 1, in <module>
NameError: name 'sys' is not defined

This seemed like a strange error to have since the sys module is fundamental to the python library and should be included in the default search path. After digging into it for a while, I finally isolated the offending line of code: Line 30 of cime/scripts/lib/CIME/code_checker.py

30: cmd_options += " --init-hook='sys.path.extend((\"%s\",\"%s\",\"%s\"))'"%\

For some reason, this call to sys.path could not be resolved. The work-around for this was to add import sys; to the beginning of the string provided as the argument to --init-hook.

30: cmd_options += " --init-hook='import sys; sys.path.extend((\"%s\",\"%s\",\"%s\"))'"%\

With this one change, the pylint checks in the regression tests began passing.

I hope this helps. Please reach out if you need any additional information.

jedwards4b commented 9 months ago

It's actually because newer versions of python have changed this behavior.
To use cesm2.1 we recommend a virtual environment with python 3.8 and pylint 2.12.

CollinsEM commented 9 months ago

Python 3.8 is not available on Orion. It seems like recommending a downgrade is a bit counter-productive. I'm sure that I'm not the only one that will notice this issue as more systems are upgraded to python 3.9. Would you consider making the change to the python script if I submitted a pull request?

jedwards4b commented 9 months ago

Yes a PR would be very welcome.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 6 months ago

This issue was closed because it has been stalled for 5 days with no activity.