Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Oct 18, 2024
1 parent ad7417d commit 007c5d0
Show file tree
Hide file tree
Showing 4 changed files with 735 additions and 539 deletions.
19 changes: 1 addition & 18 deletions .github/workflows/QA.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
javascript/src/fuzzyRules.js
javascript/test/fuzzyRules.js
name: rules
retention-days: 1

check-python-qa:
runs-on: ubuntu-24.04
Expand All @@ -48,21 +49,8 @@ jobs:
- name: Restore rules artifact
uses: actions/download-artifact@v4
with:
path: |
src/zimscraperlib/rewriting/rules.py
tests/rewriting/test_fuzzy_rules.py
javascript/src/fuzzyRules.js
javascript/test/fuzzyRules.js
name: rules

- name: Temp check
run: |
ls -lah .
ls -lah src/zimscraperlib/rewriting/rules.py
ls -lah tests/rewriting/test_fuzzy_rules.py
ls -lah javascript/src/fuzzyRules.js
ls -lah javascript/test/fuzzyRules.js
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -93,11 +81,6 @@ jobs:
- name: Restore rules artifact
uses: actions/download-artifact@v4
with:
path: |
src/zimscraperlib/rewriting/rules.py
tests/rewriting/test_fuzzy_rules.py
javascript/src/fuzzyRules.js
javascript/test/fuzzyRules.js
name: rules

- name: Temp check
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,50 @@ on:
- main

jobs:
generate-rules:
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
architecture: x64

- name: Install dependencies (and project)
run: |
pip install -U pip
pip install -e .[scripts]
- name: Generate rules
run: |
python rules/generate_rules.py
- name: Save rules artifact
uses: actions/upload-artifact@v4
with:
path: |
src/zimscraperlib/rewriting/rules.py
tests/rewriting/test_fuzzy_rules.py
javascript/src/fuzzyRules.js
javascript/test/fuzzyRules.js
name: rules
retention-days: 1

run-python-tests:
runs-on: ubuntu-24.04
needs: generate-rules

steps:
- uses: actions/checkout@v4

- name: Restore rules artifact
uses: actions/download-artifact@v4
with:
name: rules

- name: install ffmpeg and gifsicle
run: sudo apt update && sudo apt install ffmpeg gifsicle

Expand All @@ -38,9 +76,15 @@ jobs:

build_python:
runs-on: ubuntu-24.04
needs: generate-rules
steps:
- uses: actions/checkout@v4

- name: Restore rules artifact
uses: actions/download-artifact@v4
with:
name: rules

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -54,8 +98,15 @@ jobs:
build_javascript:
runs-on: ubuntu-24.04
needs: generate-rules
steps:
- uses: actions/checkout@v4

- name: Restore rules artifact
uses: actions/download-artifact@v4
with:
name: rules

# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
Expand Down
13 changes: 12 additions & 1 deletion src/zimscraperlib/rewriting/url_rewriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __hash__(self) -> int:
def __str__(self) -> str:
return f"HttpUrl({self.value})"

def __repr__(self) -> str:
return f"{self.__str__} - {super().__repr__()}" # pragma: no cover

@property
def value(self) -> str:
return self._value
Expand Down Expand Up @@ -120,6 +123,9 @@ def __hash__(self) -> int:
def __str__(self) -> str:
return f"ZimPath({self.value})"

def __repr__(self) -> str:
return f"{self.__str__} - {super().__repr__()}" # pragma: no cover

@property
def value(self) -> str:
return self._value
Expand Down Expand Up @@ -357,10 +363,15 @@ def normalize(cls, url: HttpUrl) -> ZimPath:
passed to python-libzim for UTF-8 encoding.
"""

if not isinstance(url, HttpUrl):
raise ValueError("Bad argument type passed, HttpUrl expected")

url_parts = urlsplit(url.value)

if not url_parts.hostname:
raise Exception("Hostname is missing")
# cannot happen because of the HttpUrl checks, but important to please the
# type checker
raise Exception("Hostname is missing") # pragma: no cover

# decode the hostname if it is punny-encoded
hostname = (
Expand Down
Loading

0 comments on commit 007c5d0

Please sign in to comment.