From 02270406be7f29f1c86fdaadde4dfec4772fa291 Mon Sep 17 00:00:00 2001 From: eneller Date: Fri, 17 Jan 2025 08:30:13 +0100 Subject: [PATCH] fix: data path inside package --- MANIFEST.in | 1 + README.md | 15 ++++----------- pyproject.toml | 8 ++++---- src/epub2go/__init__.py | 0 {data => src/epub2go}/blocklist.txt | 0 src/epub2go/convert.py | 7 +++---- {data => src/epub2go}/drama.css | 0 7 files changed, 12 insertions(+), 19 deletions(-) create mode 100644 MANIFEST.in create mode 100644 src/epub2go/__init__.py rename {data => src/epub2go}/blocklist.txt (100%) rename {data => src/epub2go}/drama.css (100%) diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..4a103a0 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include src/epub2go/data * diff --git a/README.md b/README.md index 21f75df..e8314aa 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 2bede5d..4ef3cac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] \ No newline at end of file +[tool.setuptools_scm] +# can be empty if no extra settings are needed, presence enables setuptools-scm \ No newline at end of file diff --git a/src/epub2go/__init__.py b/src/epub2go/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/data/blocklist.txt b/src/epub2go/blocklist.txt similarity index 100% rename from data/blocklist.txt rename to src/epub2go/blocklist.txt diff --git a/src/epub2go/convert.py b/src/epub2go/convert.py index 5c7f633..9f35341 100644 --- a/src/epub2go/convert.py +++ b/src/epub2go/convert.py @@ -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 diff --git a/data/drama.css b/src/epub2go/drama.css similarity index 100% rename from data/drama.css rename to src/epub2go/drama.css