do fancy python packaging stuff

This commit is contained in:
xenofem 2024-01-22 22:06:04 -05:00
parent 716a42858c
commit 5b2f99516f
15 changed files with 39 additions and 20 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
env
result
result
*/__pycache__

2
MANIFEST.in Normal file
View file

@ -0,0 +1,2 @@
graft dlibrary/templates
graft dlibrary/static

1
dlibrary/__init__.py Normal file
View file

@ -0,0 +1 @@
from .dlibrary import *

View file

@ -2,6 +2,7 @@
import argparse
import asyncio
import importlib_resources as resources
from pathlib import Path
from os.path import relpath, splitext
import re
@ -12,7 +13,7 @@ import zipfile
from dlsite_async import DlsiteAPI
import fitz
from jinja2 import Environment, FileSystemLoader, select_autoescape
from jinja2 import Environment, PackageLoader, select_autoescape
import requests
NUMBER_REGEX = re.compile('[0-9]+')
@ -295,11 +296,14 @@ def metadata(args):
con.close()
def publish(args):
source_dir = Path(__file__).parent
def copy_contents(src, dest):
dest.mkdir(parents=True, exist_ok=True)
for item in src.iterdir():
shutil.copyfile(item, dest / item.name)
def publish(args):
jenv = Environment(
loader=FileSystemLoader(source_dir / "templates"),
loader=PackageLoader("dlibrary"),
autoescape=select_autoescape()
)
@ -336,7 +340,8 @@ def publish(args):
with open(work_dir / 'index.html', 'w') as f:
f.write(viewer_template.render(depth=2, work=work, title=title, images=images))
shutil.copytree(source_dir / 'static', args.destdir / 'site' / 'static', dirs_exist_ok=True)
with resources.as_file(resources.files("dlibrary")) as r:
copy_contents(r / 'static', args.destdir / 'site' / 'static')
list_template = jenv.get_template("list.html")
@ -405,6 +410,9 @@ parser_metadata.set_defaults(func=metadata)
parser_publish = subparsers.add_parser('publish', help='generate HTML/CSS/JS for library site')
parser_publish.set_defaults(func=publish)
if __name__ == "__main__":
def main():
args = argparser.parse_args()
args.func(args)
if __name__ == "__main__":
main()

View file

@ -48,11 +48,14 @@
dlibrary = buildPythonApplication {
pname = "dlibrary";
version = "0.1";
pyproject = true;
propagatedBuildInputs = [
pymupdf
requests
dlsite-async
jinja2
importlib-resources
setuptools
];
src = ./.;
};

17
pyproject.toml Normal file
View file

@ -0,0 +1,17 @@
[project]
name = "dlibrary"
version = "0.1"
dependencies = [
"requests",
"PyMuPDF",
"dlsite-async",
"jinja2",
"importlib_resources",
]
[project.scripts]
dlibrary = "dlibrary:main"
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

View file

@ -1,4 +0,0 @@
requests
PyMuPDF
dlsite-async
jinja2

View file

@ -1,9 +0,0 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='dlibrary',
version='0.1',
packages=find_packages(),
scripts=["dlibrary.py"],
)