refactor(setuptools): include sql schema

fix(backend/sqlite): load files through importlib

is required since package will be distributed as python egg

chore: upgrade version
This commit is contained in:
Tiara Rodney 2022-04-03 03:48:18 +02:00
parent fedd42933c
commit bdefd7e592
4 changed files with 12 additions and 8 deletions

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = httpaste-victorykit name = httpaste-victorykit
version = 1.0.4-alpha version = 1.0.5-alpha
author = Tiara Rodney author = Tiara Rodney
author_email = t.rodney@victoryk.it author_email = t.rodney@victoryk.it
description = a versatile HTTP pastebin description = a versatile HTTP pastebin
@ -39,4 +39,5 @@ console_scripts =
where = src where = src
[options.package_data] [options.package_data]
schema = src/httpaste/schema/httpaste.openapi.json openapi_schema = src/httpaste/schema/httpaste.openapi.json
sql_schema = *.sql

View file

@ -2,6 +2,7 @@
""" """
import argparse import argparse
import os import os
from importlib.resources import open_text
def _this_dir(basename: str) -> str: def _this_dir(basename: str) -> str:
@ -20,7 +21,7 @@ def _path_output(path, echo: bool = False) -> str:
return path return path
else: else:
with open(path, 'r') as fh: with open_text('httpaste', path) as fh:
return fh.read() return fh.read()
@ -51,21 +52,21 @@ def command_wsgi(**kwargs):
"""get WSGI script """get WSGI script
""" """
print(_path_output(_this_dir('wsgi.py'), kwargs.get('echo'))) print(_path_output('wsgi.py', kwargs.get('echo')))
def command_cgi(**kwargs): def command_cgi(**kwargs):
"""get CGI script """get CGI script
""" """
print(_path_output(_this_dir('cgi.py'), kwargs.get('echo'))) print(_path_output('cgi.py', kwargs.get('echo')))
def command_fcgi(**kwargs): def command_fcgi(**kwargs):
"""get FastCGI script """get FastCGI script
""" """
print(_path_output(_this_dir('fcgi.py'), kwargs.get('echo'))) print(_path_output('fcgi.py', kwargs.get('echo')))
def command_default_config(**kwargs): def command_default_config(**kwargs):

View file

@ -3,6 +3,7 @@
from os import path from os import path
from sqlite3 import Connection from sqlite3 import Connection
from time import time from time import time
from importlib.resources import open_text
def load(proto: object, connection: Connection, model_class: type): def load(proto: object, connection: Connection, model_class: type):
@ -63,7 +64,7 @@ def init(connection: Connection):
cur = connection.cursor() cur = connection.cursor()
with open(path.join(path.dirname(__file__), 'paste.sql'), 'r') as fh: with open_text('httpaste.backend.sqlite', 'paste.sql') as fh:
cur.execute(fh.read()) cur.execute(fh.read())

View file

@ -3,6 +3,7 @@
from os import path from os import path
from sqlite3 import Connection from sqlite3 import Connection
from httpaste.model import User from httpaste.model import User
from importlib.resources import open_text
def load(proto: User, connection: Connection): def load(proto: User, connection: Connection):
@ -48,7 +49,7 @@ def init(connection: Connection):
cur = connection.cursor() cur = connection.cursor()
with open(path.join(path.dirname(__file__), 'user.sql'), 'r') as fh: with open_text('httpaste.backend.sqlite', 'user.sql') as fh:
cur.execute(fh.read()) cur.execute(fh.read())