HomeDevCentral

Avoid importlib.machinery.SourceFileLoader load_module use

Description

Avoid importlib.machinery.SourceFileLoader load_module use

Summary:
Currently, unit tests for Salt module and for scripts used the SourceFileLoader
class to manually load a specific script. The class load_module() method has
been deprecated for a while and won't be available in Python 3.12+.

Instead, we now use two strategies to import Python code:

  • treat _modules/ as a package folder by passing the path as PYTHONPATH
  • still use importlib for scripts, with compatible code

To import scripts directly with import can be a challenge, as roles like
"paas-docker" use dashes. The scripts filenames themselves contain dashes.

This fixes the following issue:
<frozen importlib._bootstrap>:283: DeprecationWarning: the load_module() method
is deprecated and slated for removal in Python 3.12; use exec_module() instead

Test Plan:
On the T2123-improve-tests-suite branch to avoid distractions, make test
show every test pass without the deprecation warning.

Reviewers: DorianWinty

Reviewed By: DorianWinty

Maniphest Tasks: T2123

Differential Revision: https://devcentral.nasqueron.org/D3685

Details

Provenance
derecksonAuthored on Wed, Sep 17, 16:34
derecksonPushed on Tue, Oct 14, 17:05
Reviewer
DorianWinty
Differential Revision
D3685: Avoid importlib.machinery.SourceFileLoader load_module use
Parents
rOPS730cde1196bd: Prune unused webserver-content index generator
Branches
Unknown
Tags
Unknown
Tasks
T2123: Fix tests for operations repository