Skip to content
Snippets Groups Projects
Unverified Commit 67056444 authored by Cristina's avatar Cristina Committed by GitHub
Browse files

Deprecate imp (#9718)


Fixes #9642.

Signed-off-by: default avatarCristina Muñoz <hi@xmunoz.com>
parent ac99774d
No related branches found
No related tags found
No related merge requests found
Replace deprecated `imp` module with successor `importlib`. Contributed by Cristina Muñoz.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import imp import importlib.util
import logging import logging
import os import os
import re import re
...@@ -454,8 +454,13 @@ def _upgrade_existing_database( ...@@ -454,8 +454,13 @@ def _upgrade_existing_database(
) )
module_name = "synapse.storage.v%d_%s" % (v, root_name) module_name = "synapse.storage.v%d_%s" % (v, root_name)
with open(absolute_path) as python_file:
module = imp.load_source(module_name, absolute_path, python_file) # type: ignore spec = importlib.util.spec_from_file_location(
module_name, absolute_path
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore
logger.info("Running script %s", relative_path) logger.info("Running script %s", relative_path)
module.run_create(cur, database_engine) # type: ignore module.run_create(cur, database_engine) # type: ignore
if not is_empty: if not is_empty:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment