From 89ee195cdd5604f857ee5d8e38a8e54876da3e08 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sun, 2 Feb 2025 12:56:37 +0100 Subject: [PATCH] Rework input paths parsing, add Windows CI Windows CI is very slow but at least it is working now. --- .github/workflows/ci-windows.yml | 29 ++++++++++++++++--- hpdf/hpdf.py | 7 +++-- tests/integration/01_hello_world/test.itest | 2 +- tests/integration/02_two_pages/test.itest | 2 +- .../03_cache_dir_argument/test.itest | 4 +-- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 5479969..8cf40f1 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -1,9 +1,10 @@ +# NOTE: In contrast to Linux and macOS, the Windows build machines do not have Chrome installed. + name: "HTML2PDF on Windows" -# FIXME: Disabled until WDM detects Chrome on Windows reliably. -# on: -# pull_request: -# branches: [ "**" ] +on: + pull_request: + branches: [ "**" ] jobs: build: @@ -21,6 +22,26 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install Google Chrome + run: | + choco install googlechrome --no-progress -y + shell: powershell + + - name: Check Chrome Version + run: '& "C:\Program Files\Google\Chrome\Application\chrome.exe" --version' + shell: powershell + + - name: Add Chrome to PATH + run: | + $chromePath = "C:\Program Files\Google\Chrome\Application" + echo "Adding $chromePath to PATH" + echo "$chromePath" | Out-File -Append -Encoding utf8 $env:GITHUB_PATH + shell: powershell + + - name: Verify Chrome Installation + run: chrome --version + shell: powershell + - name: Upgrade pip run: | python -m pip install --upgrade pip diff --git a/hpdf/hpdf.py b/hpdf/hpdf.py index c31d5b6..af4ddc9 100644 --- a/hpdf/hpdf.py +++ b/hpdf/hpdf.py @@ -265,8 +265,11 @@ def exit_handler(): print("html2pdf: exit handler: quitting the ChromeDriver.") # noqa: T201 driver.quit() - for separate_path_pair_ in paths: - path_to_input_html, path_to_output_pdf = separate_path_pair_.split(":") + assert len(paths) % 2 == 0, f"Expecting an even number of input/output path arguments: {paths}." + for current_pair_idx in range(0, 2, len(paths)): + path_to_input_html = paths[current_pair_idx] + path_to_output_pdf = paths[current_pair_idx + 1] + assert os.path.isfile(path_to_input_html), path_to_input_html path_to_output_pdf_dir = os.path.dirname(path_to_output_pdf) diff --git a/tests/integration/01_hello_world/test.itest b/tests/integration/01_hello_world/test.itest index c506d79..94fd0d7 100644 --- a/tests/integration/01_hello_world/test.itest +++ b/tests/integration/01_hello_world/test.itest @@ -1,4 +1,4 @@ -RUN: %html2pdf %S/index.html:%S/Output/index.pdf +RUN: %html2pdf %S/index.html %S/Output/index.pdf RUN: %check_exists --file "%S/Output/index.pdf" RUN: python %S/test.py diff --git a/tests/integration/02_two_pages/test.itest b/tests/integration/02_two_pages/test.itest index c506d79..94fd0d7 100644 --- a/tests/integration/02_two_pages/test.itest +++ b/tests/integration/02_two_pages/test.itest @@ -1,4 +1,4 @@ -RUN: %html2pdf %S/index.html:%S/Output/index.pdf +RUN: %html2pdf %S/index.html %S/Output/index.pdf RUN: %check_exists --file "%S/Output/index.pdf" RUN: python %S/test.py diff --git a/tests/integration/03_cache_dir_argument/test.itest b/tests/integration/03_cache_dir_argument/test.itest index 1835cb9..f22469f 100644 --- a/tests/integration/03_cache_dir_argument/test.itest +++ b/tests/integration/03_cache_dir_argument/test.itest @@ -1,10 +1,10 @@ -RUN: %html2pdf --cache-dir %S/Output/cache %S/index.html:%S/Output/index.pdf | filecheck %s --dump-input=fail --check-prefix CHECK-RUN1 +RUN: %html2pdf --cache-dir %S/Output/cache %S/index.html %S/Output/index.pdf | filecheck %s --dump-input=fail --check-prefix CHECK-RUN1 RUN: %check_exists --file "%S/Output/index.pdf" RUN: python %S/test.py CHECK-RUN1: html2pdf: ChromeDriver does not exist in the local cache: -RUN: %html2pdf --cache-dir %S/Output/cache %S/index.html:%S/Output/index.pdf | filecheck %s --dump-input=fail --check-prefix CHECK-RUN2 +RUN: %html2pdf --cache-dir %S/Output/cache %S/index.html %S/Output/index.pdf | filecheck %s --dump-input=fail --check-prefix CHECK-RUN2 RUN: %check_exists --file "%S/Output/index.pdf" RUN: python %S/test.py