do fancy python packaging stuff
This commit is contained in:
parent
716a42858c
commit
5b2f99516f
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
env
|
env
|
||||||
result
|
result
|
||||||
|
*/__pycache__
|
2
MANIFEST.in
Normal file
2
MANIFEST.in
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
graft dlibrary/templates
|
||||||
|
graft dlibrary/static
|
1
dlibrary/__init__.py
Normal file
1
dlibrary/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .dlibrary import *
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import importlib_resources as resources
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os.path import relpath, splitext
|
from os.path import relpath, splitext
|
||||||
import re
|
import re
|
||||||
|
@ -12,7 +13,7 @@ import zipfile
|
||||||
|
|
||||||
from dlsite_async import DlsiteAPI
|
from dlsite_async import DlsiteAPI
|
||||||
import fitz
|
import fitz
|
||||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
NUMBER_REGEX = re.compile('[0-9]+')
|
NUMBER_REGEX = re.compile('[0-9]+')
|
||||||
|
@ -295,11 +296,14 @@ def metadata(args):
|
||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
def publish(args):
|
def copy_contents(src, dest):
|
||||||
source_dir = Path(__file__).parent
|
dest.mkdir(parents=True, exist_ok=True)
|
||||||
|
for item in src.iterdir():
|
||||||
|
shutil.copyfile(item, dest / item.name)
|
||||||
|
|
||||||
|
def publish(args):
|
||||||
jenv = Environment(
|
jenv = Environment(
|
||||||
loader=FileSystemLoader(source_dir / "templates"),
|
loader=PackageLoader("dlibrary"),
|
||||||
autoescape=select_autoescape()
|
autoescape=select_autoescape()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -336,7 +340,8 @@ def publish(args):
|
||||||
with open(work_dir / 'index.html', 'w') as f:
|
with open(work_dir / 'index.html', 'w') as f:
|
||||||
f.write(viewer_template.render(depth=2, work=work, title=title, images=images))
|
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")
|
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 = subparsers.add_parser('publish', help='generate HTML/CSS/JS for library site')
|
||||||
parser_publish.set_defaults(func=publish)
|
parser_publish.set_defaults(func=publish)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -48,11 +48,14 @@
|
||||||
dlibrary = buildPythonApplication {
|
dlibrary = buildPythonApplication {
|
||||||
pname = "dlibrary";
|
pname = "dlibrary";
|
||||||
version = "0.1";
|
version = "0.1";
|
||||||
|
pyproject = true;
|
||||||
propagatedBuildInputs = [
|
propagatedBuildInputs = [
|
||||||
pymupdf
|
pymupdf
|
||||||
requests
|
requests
|
||||||
dlsite-async
|
dlsite-async
|
||||||
jinja2
|
jinja2
|
||||||
|
importlib-resources
|
||||||
|
setuptools
|
||||||
];
|
];
|
||||||
src = ./.;
|
src = ./.;
|
||||||
};
|
};
|
||||||
|
|
17
pyproject.toml
Normal file
17
pyproject.toml
Normal 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"
|
|
@ -1,4 +0,0 @@
|
||||||
requests
|
|
||||||
PyMuPDF
|
|
||||||
dlsite-async
|
|
||||||
jinja2
|
|
Loading…
Reference in a new issue