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
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
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
```
2. Activate your new venv using
```
source .venv/bin/activate
```
3. Install the requirements for this script using
```
pip install -r requirements.txt
pip install git+https://github.com/eneller/epub2go.py
```
This will provide the 'epub2go' command.

View File

@@ -15,8 +15,8 @@ epub2go = "epub2go.convert:main"
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages.find]
where = ["src"]
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
[tool.setuptools.package-data]
"epub2go" = ["blocklist.txt", "drama.css"]
[tool.setuptools_scm]
# 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,
url:str,
):
dir_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
dir_data = os.path.join(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()
# NOTE move non-code files to data folder
self.style_path_drama = pkg_resources.files('epub2go').joinpath("drama.css")
self.blocklist = open(pkg_resources.files('epub2go').joinpath('blocklist.txt')).read().splitlines()
self.root = os.path.dirname(url)
self.url = urlparse(self.root)
self.output = self.url.netloc + self.url.path