-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from openzim/adopt_python_bootstrap
Adopt python bootstrap conventions
- Loading branch information
Showing
94 changed files
with
1,119 additions
and
772 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Build and upload to PyPI | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
id-token: write # mandatory for PyPI trusted publishing | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: pyproject.toml | ||
architecture: x64 | ||
|
||
- name: Build packages | ||
run: | | ||
pip install -U pip build | ||
python -m build --sdist --wheel | ||
- name: Upload to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1.8 | ||
|
||
- name: Build and push Docker image | ||
uses: openzim/docker-publish-action@v10 | ||
with: | ||
image-name: openzim/gutenberg | ||
tag-pattern: /^v([0-9.]+)$/ | ||
latest-on-tag: true | ||
restrict-to: openzim/gutenberg | ||
registries: ghcr.io | ||
credentials: | ||
GHCRIO_USERNAME=${{ secrets.GHCR_USERNAME }} | ||
GHCRIO_TOKEN=${{ secrets.GHCR_TOKEN }} | ||
repo_description: auto | ||
repo_overview: auto |
16 changes: 8 additions & 8 deletions
16
.github/workflows/docker.yml → .github/workflows/PublishDockerDevImage.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
name: Docker | ||
name: Publish Docker dev image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-push: | ||
name: Deploy Docker Image | ||
publish: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
- name: Build and push | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Build and push Docker image | ||
uses: openzim/docker-publish-action@v10 | ||
with: | ||
image-name: openzim/gutenberg | ||
on-master: dev | ||
tag-pattern: /^v([0-9.]+)$/ | ||
latest-on-tag: true | ||
manual-tag: dev | ||
latest-on-tag: false | ||
restrict-to: openzim/gutenberg | ||
registries: ghcr.io | ||
credentials: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: QA | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check-qa: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: pyproject.toml | ||
architecture: x64 | ||
|
||
- name: Install dependencies (and project) | ||
run: | | ||
pip install -U pip | ||
pip install -e .[lint,scripts,test,check] | ||
- name: Check black formatting | ||
run: inv lint-black | ||
|
||
- name: Check ruff | ||
run: inv lint-ruff | ||
|
||
- name: Check pyright | ||
run: inv check-pyright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: pyproject.toml | ||
architecture: x64 | ||
|
||
- name: Install dependencies (and project) | ||
run: | | ||
pip install -U pip | ||
pip install -e .[test,scripts] | ||
- name: Run the tests | ||
run: inv coverage --args "-vvv" | ||
|
||
- name: Upload coverage report to codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
build_python: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: pyproject.toml | ||
architecture: x64 | ||
|
||
- name: Ensure we can build Python targets | ||
run: | | ||
pip install -U pip build | ||
python3 -m build --sdist --wheel | ||
build_docker: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Ensure we can build the Docker image | ||
run: | | ||
docker build -t gutenberg . | ||
- name: Ensure we can start the Docker image | ||
run: | | ||
docker run --rm gutenberg |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- repo: https://github.com/psf/black | ||
rev: "23.3.0" | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.0.272 | ||
hooks: | ||
- id: ruff | ||
- repo: https://github.com/RobertCraigie/pyright-python | ||
rev: v1.1.323 | ||
hooks: | ||
- id: pyright | ||
name: pyright (system) | ||
description: 'pyright static type checker' | ||
entry: pyright | ||
language: system | ||
'types_or': [python, pyi] | ||
require_serial: true | ||
minimum_pre_commit_version: '2.9.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
FROM python:3.11.4-bookworm | ||
|
||
# Install necessary packages | ||
RUN apt-get update -y && \ | ||
apt-get install -y --no-install-recommends advancecomp libxml2-dev libxslt-dev python3-pillow rsync libjpeg-dev libpng-dev libmagic1 locales jpegoptim pngquant gifsicle && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
advancecomp \ | ||
libxml2-dev \ | ||
libxslt-dev \ | ||
python3-pillow \ | ||
rsync \ | ||
libjpeg-dev \ | ||
libpng-dev \ | ||
libmagic1 \ | ||
locales \ | ||
jpegoptim \ | ||
pngquant \ | ||
gifsicle \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& python -m pip install --no-cache-dir -U \ | ||
pip \ | ||
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \ | ||
&& locale-gen "en_US.UTF-8" | ||
|
||
# Install gutenberg (from source) | ||
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen "en_US.UTF-8" | ||
COPY requirements.pip /src/ | ||
RUN python3 -m pip install -r /src/requirements.pip | ||
COPY LICENSE /src/ | ||
COPY pypi-readme.rst /src/ | ||
COPY MANIFEST.in /src/ | ||
COPY setup.py /src/ | ||
COPY get_js_deps.sh /src/ | ||
COPY gutenberg2zim /src/ | ||
COPY gutenbergtozim /src/gutenbergtozim | ||
WORKDIR /src/ | ||
RUN python3 ./setup.py install | ||
# Copy code + associated artifacts | ||
COPY src /src/src | ||
COPY pyproject.toml *.md *.rst get_js_deps.sh LICENSE *.py /src/ | ||
|
||
# Boot commands | ||
# Install + cleanup | ||
RUN pip install --no-cache-dir /src \ | ||
&& rm -rf /src | ||
|
||
# default output directory | ||
RUN mkdir -p /output | ||
WORKDIR /output | ||
|
||
ENV LANG=en_US.UTF-8 | ||
ENV LANGUAGE=en_US:en | ||
ENV LC_ALL=en_US.UTF-8 | ||
CMD gutenberg2zim --help ; /bin/bash | ||
ENV LANG=en_US.UTF-8 \ | ||
LANGUAGE=en_US:en \ | ||
LC_ALL=en_US.UTF-8 | ||
|
||
CMD ["gutenberg2zim", "--help"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
import subprocess | ||
from pathlib import Path | ||
|
||
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 = [ | ||
"datatables/datatables.min.css", | ||
"datatables/datatables.min.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 | ||
subprocess.run( | ||
str(Path(self.root).joinpath("get_js_deps.sh")), | ||
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("gutebergtozim/templates") | ||
.joinpath(dep) | ||
.exists() | ||
): | ||
return False | ||
return True |
Oops, something went wrong.