fix(backend/mysql): load files through importlib

is required since package will be distributed as python egg
This commit is contained in:
Tiara Rodney 2022-04-03 04:02:08 +02:00
parent 4a1cf1d007
commit 809ce6522b
2 changed files with 5 additions and 2 deletions

View file

@ -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())

View file

@ -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())