E3SM-Project / polaris

Testing and analysis for OMEGA, MPAS-Ocean, MALI and MPAS-Seaice
BSD 3-Clause "New" or "Revised" License
6 stars 13 forks source link

Fix deprecated calls to `importlib.resources` #22

Closed xylar closed 1 year ago

xylar commented 1 year ago

To save a little trouble, an import shortcut has been added to polaris.io for imp_res that handles both different imports for python <=3.8 and the complaints that mypy has about these imports.

This merge also includes an update to mache 1.13.0 and to polaris 0.1.0-alpha.2.

Checklist

xylar commented 1 year ago

Testing

I ran the cosine_bell test suite on Chrysalis with Intel and OpenMPI:

/lcrc/group/e3sm/ac.xylar/polaris_0.1/chrysalis/test_20230303/cosine_bell_fix_imp_req

But when I use python 3.8, I see:

$ polaris list
Traceback (most recent call last):
  File "/gpfs/fs1/home/ac.xylar/chrysalis/mambaforge/envs/polaris_test_py38/bin/polaris", line 33, in <module>
    sys.exit(load_entry_point('polaris', 'console_scripts', 'polaris')())
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/__main__.py", line 62, in main
    commands[args.command]()
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/list.py", line 151, in main
    list_cases(test_expr=args.test_expr, number=args.number,
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/list.py", line 26, in list_cases
    components = get_components()
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/components.py", line 19, in get_components
    Ocean(),
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/ocean/__init__.py", line 16, in __init__
    self.add_test_group(GlobalConvergence(component=self))
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/ocean/tests/global_convergence/__init__.py", line 18, in __init__
    self.add_test_case(CosineBell(test_group=self,
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/ocean/tests/global_convergence/cosine_bell/__init__.py", line 52, in __init__
    self._setup_steps(config)
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/ocean/tests/global_convergence/cosine_bell/__init__.py", line 145, in _setup_steps
    self.add_step(QuasiUniformSphericalMeshStep(
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/mesh/spherical.py", line 206, in __init__
    super().__init__(test_case=test_case, name=name, subdir=subdir)
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/mesh/spherical.py", line 46, in __init__
    super().__init__(test_case, name=name, subdir=subdir)
  File "/gpfs/fs1/home/ac.xylar/e3sm_work/polaris/fix_importlib_resources/polaris/step.py", line 230, in __init__
    self.machine_info = MachineInfo(machine='default')
  File "/gpfs/fs1/home/ac.xylar/chrysalis/mambaforge/envs/polaris_test_py38/lib/python3.8/site-packages/mache/machine_info.py", line 86, in __init__
    self.config = self._get_config()
  File "/gpfs/fs1/home/ac.xylar/chrysalis/mambaforge/envs/polaris_test_py38/lib/python3.8/site-packages/mache/machine_info.py", line 233, in _get_config
    importlib_resources.files('mache.machines') / f'{machine}.cfg'
AttributeError: module 'importlib.resources' has no attribute 'files'

So some work still to do.

xylar commented 1 year ago

I'm able to verify that this works with a test version of mache with https://github.com/E3SM-Project/mache/pull/110, so we'll need a new mache release to fix this.

xylar commented 1 year ago

Tested again with a spack environment build for mache 1.13.0 and polaris 0.1.0-alpha.2.