fix: data path inside package

This commit is contained in:
eneller
2025-01-17 08:30:13 +01:00
parent 2c037d2cfd
commit 02270406be
7 changed files with 12 additions and 19 deletions

1
MANIFEST.in Normal file
View File

@@ -0,0 +1 @@
recursive-include src/epub2go/data *

View File

@@ -7,18 +7,11 @@ Requires:
## Usage ## Usage
Invoke the script using the url of any page of the book you would like to download: Invoke the script using the url of any page of the book you would like to download:
``` ```
python convert.py https://example.com epub2go https://www.projekt-gutenberg.org/ibsen/solness/
``` ```
## Installation ## Installation
1. Assuming you have a recent version of [Python](https://www.python.org/downloads/) and Pip installed, create virtual environment using Assuming you have a recent version of python installed, run
``` ```
python -m venv .venv pip install git+https://github.com/eneller/epub2go.py
```
2. Activate your new venv using
```
source .venv/bin/activate
```
3. Install the requirements for this script using
```
pip install -r requirements.txt
``` ```
This will provide the 'epub2go' command.

View File

@@ -15,8 +15,8 @@ epub2go = "epub2go.convert:main"
[tool.setuptools] [tool.setuptools]
include-package-data = true include-package-data = true
[tool.setuptools.packages.find] [build-system]
where = ["src"] requires = ["setuptools>=64", "setuptools_scm>=8"]
[tool.setuptools.package-data] [tool.setuptools_scm]
"epub2go" = ["blocklist.txt", "drama.css"] # can be empty if no extra settings are needed, presence enables setuptools-scm

0
src/epub2go/__init__.py Normal file
View File

View File

@@ -12,10 +12,9 @@ class GBConvert():
def __init__(self, def __init__(self,
url:str, url:str,
): ):
dir_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) # NOTE move non-code files to data folder
dir_data = os.path.join(dir_root, "data/") self.style_path_drama = pkg_resources.files('epub2go').joinpath("drama.css")
self.style_path_drama = os.path.join(dir_data, "drama.css") self.blocklist = open(pkg_resources.files('epub2go').joinpath('blocklist.txt')).read().splitlines()
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