From 809ce6522ba0937c82737195d69ac00c3b2d965b Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Sun, 3 Apr 2022 04:02:08 +0200 Subject: [PATCH] fix(backend/mysql): load files through importlib is required since package will be distributed as python egg --- src/httpaste/backend/mysql/paste.py | 4 +++- src/httpaste/backend/mysql/user.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/httpaste/backend/mysql/paste.py b/src/httpaste/backend/mysql/paste.py index 5e4057f..efa5f0e 100644 --- a/src/httpaste/backend/mysql/paste.py +++ b/src/httpaste/backend/mysql/paste.py @@ -1,5 +1,7 @@ from os import path from time import time +from importlib.resources import open_text + try: from mysql.connector.connection import MySQLConnection @@ -92,7 +94,7 @@ def init(connection: MySQLConnection): cursor = connection.cursor() - with open(path.join(path.dirname(__file__), 'paste.sql'), 'r') as fh: + with open_text('httpaste.backend.mysql', 'paste.sql') as fh: cursor.execute(fh.read()) diff --git a/src/httpaste/backend/mysql/user.py b/src/httpaste/backend/mysql/user.py index 7efebfc..a7148ff 100644 --- a/src/httpaste/backend/mysql/user.py +++ b/src/httpaste/backend/mysql/user.py @@ -1,4 +1,5 @@ from os import path +from importlib.resources import open_text try: from mysql.connector.connection import MySQLConnection except ImportError as e: @@ -83,7 +84,7 @@ def init(connection: MySQLConnection): cursor = connection.cursor() - with open(path.join(path.dirname(__file__), 'user.sql'), 'r') as fh: + with open_text('httpaste.backend.mysql', 'user.sql') as fh: cursor.execute(fh.read())