Skip to content

Commit

Permalink
Ensure assets are not downloaded twice at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Jul 24, 2023
1 parent f6ede9f commit 0a4082d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build packages
run: |
pip install -U pip hatch
HATCH_BUILD_HOOKS_ENABLE=true hatch build
hatch build
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1.8
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apt-get update -y \
#RUN pip3 install --no-cache-dir -r /src/requirements.txt
COPY kolibri2zim /src/kolibri2zim
COPY pyproject.toml *.md get_js_deps.sh install.sh MANIFEST.in LICENSE *.py /src/
RUN cd /src/ && HATCH_BUILD_HOOKS_ENABLE=true hatch build -t sdist && ./install.sh
RUN cd /src/ && hatch build -t sdist && ./install.sh

# default output directory
RUN mkdir -p /output
Expand Down
29 changes: 29 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,42 @@

from hatchling.builders.hooks.plugin.interface import BuildHookInterface

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

# update list in constants.py as well
JS_DEPS = [
"pdfjs",
"videojs",
"ogvjs",
"bootstrap",
"bootstrap-icons",
"perseus",
"epub.min.js",
"jszip.min.js",
"jquery.min.js",
"videojs-ogvjs.js",
]


class GetJsDepsHook(BuildHookInterface):
def initialize(self, version, build_data):
if self.deps_already_installed():
logger.info("JS dependencies are already installed, skipping it")
return
Path(self.root).joinpath("src/kolibri2zim/templates/assets")
subprocess.run(
str(Path(self.root).joinpath("get_js_deps.sh")), # noqa : S603
check=True,
)
return super().initialize(version, build_data)

def deps_already_installed(self) -> bool:
for dep in JS_DEPS:
if (
not Path(self.root)
.joinpath(f"src/kolibri2zim/templates/assets/{dep}")
.exists()
):
return False
return True

0 comments on commit 0a4082d

Please sign in to comment.