Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Deprecate imp (#9718)
Browse files Browse the repository at this point in the history
Fixes #9642.

Signed-off-by: Cristina Muñoz <hi@xmunoz.com>
  • Loading branch information
xmunoz authored Mar 31, 2021
1 parent ac99774 commit 6705644
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/9718.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace deprecated `imp` module with successor `importlib`. Contributed by Cristina Muñoz.
11 changes: 8 additions & 3 deletions synapse/storage/prepare_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import imp
import importlib.util
import logging
import os
import re
Expand Down Expand Up @@ -454,8 +454,13 @@ def _upgrade_existing_database(
)

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)
module.run_create(cur, database_engine) # type: ignore
if not is_empty:
Expand Down

0 comments on commit 6705644

Please sign in to comment.