fix: package data file paths

This commit is contained in:
eneller
2025-01-16 13:08:57 +01:00
parent 37968f03b7
commit a51588d5e9
3 changed files with 17 additions and 7 deletions

1
.gitignore vendored
View File

@@ -418,4 +418,3 @@ wheels/
*.css *.css
*.js *.js
*.txt *.txt
!data/*

View File

@@ -11,3 +11,12 @@ dependencies = [
] ]
[project.scripts] [project.scripts]
epub2go = "convert:main" epub2go = "convert:main"
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages.find]
where = ["src"]
[tool.setuptools.package-data]
"epub2go" = ["../data/*"]

View File

@@ -4,19 +4,21 @@ from urllib.parse import urljoin
from urllib.request import urlopen, urlparse from urllib.request import urlopen, urlparse
import os, sys import os, sys
import importlib.resources as pkg_resources
from pathlib import Path from pathlib import Path
class GBConvert(): class GBConvert():
#TODO fix toc / headings #TODO fix toc / headings
def __init__(self def __init__(self,
, url:str url:str,
): ):
self.dir_root = os.path.dirname(os.path.realpath(__file__)) dir_root = os.path.dirname(os.path.realpath(__file__))
self.dir_data = os.path.join(os.path.dirname(self.dir_root), "data/") dir_data = os.path.join(os.path.dirname(dir_root), "data/")
self.style_path_drama = os.path.join(dir_data, "drama.css")
self.blocklist = open(os.path.join(dir_data, "blocklist.txt"), 'r').read().splitlines()
self.root = os.path.dirname(url) self.root = os.path.dirname(url)
self.url = urlparse(self.root) self.url = urlparse(self.root)
self.output = self.url.netloc + self.url.path self.output = self.url.netloc + self.url.path
self.blocklist = open(os.path.join(self.dir_data, "blocklist.txt"), 'r').read().splitlines()
def get_meta(self): def get_meta(self):
response = requests.get(self.root) response = requests.get(self.root)
@@ -51,7 +53,7 @@ class GBConvert():
command = f'''pandoc -f html -t epub \ command = f'''pandoc -f html -t epub \
-o "{filename}" \ -o "{filename}" \
--reference-location=section \ --reference-location=section \
--css="{os.path.join(self.dir_data, "drama.css")}" \ --css="{self.style_path_drama}" \
--metadata title="{self.title}" \ --metadata title="{self.title}" \
--metadata author="{self.author}" \ --metadata author="{self.author}" \
--epub-title-page=false \ --epub-title-page=false \