From dfefdff706ad50932fd0eddf3eb3885d5fe4313b Mon Sep 17 00:00:00 2001 From: Thomas Seiler Date: Thu, 1 May 2025 13:16:31 +0200 Subject: [PATCH] html2print: minor cleanups on windows --- .gitattributes | 4 ++++ .github/workflows/ci-windows.yml | 13 +------------ html2print/html2print.py | 23 +++++++++++++++++++++-- tests/integration/lit.cfg | 6 ++++++ 4 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2e5faab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Mark the file as binary, so that Git won't not convert the line endings. +# Otherwise, the file becomes unreadable for bash inside Docker (on Windows platforms). +entrypoint.sh -text + diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 092e5ae..90e30b3 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -28,18 +28,7 @@ jobs: 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 + run: '(Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo' shell: powershell - name: Upgrade pip diff --git a/html2print/html2print.py b/html2print/html2print.py index bdfd64f..13c16dd 100644 --- a/html2print/html2print.py +++ b/html2print/html2print.py @@ -109,7 +109,18 @@ def _download_chromedriver( path_to_cached_chrome_driver: str, ) -> str: url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json" - response = ChromeDriverManager.send_http_get_request(url).json() + response = ChromeDriverManager.send_http_get_request(url) + if response is None: + raise RuntimeError( + "Could not download known-good-versions-with-downloads.json" + ) + + response = response.json() + if response is None: + raise RuntimeError( + "Could not parse known-good-versions-with-downloads.json" + ) + assert isinstance(response, dict) matching_versions = [ item @@ -118,7 +129,7 @@ def _download_chromedriver( ] if not matching_versions: - raise Exception( + raise RuntimeError( f"No compatible ChromeDriver found for Chrome version {chrome_major_version}" ) @@ -142,6 +153,11 @@ def _download_chromedriver( ) response = ChromeDriverManager.send_http_get_request(driver_url) + if response is None: + raise RuntimeError( + f"Could not download ChromeDriver from {driver_url}" + ) + Path(path_to_driver_cache_dir).mkdir(parents=True, exist_ok=True) zip_path = os.path.join(path_to_driver_cache_dir, "chromedriver.zip") print( # noqa: T201 @@ -179,6 +195,9 @@ def send_http_get_request(url: str) -> Response: f"html2print: " f"failed to get response for URL: {url} with error: {last_error}" ) + raise RuntimeError( + f"GET request failed after 3 attempts: {url}" + ) from last_error @staticmethod def get_chrome_version() -> Optional[str]: diff --git a/tests/integration/lit.cfg b/tests/integration/lit.cfg index 6c8c1a2..c84db86 100644 --- a/tests/integration/lit.cfg +++ b/tests/integration/lit.cfg @@ -23,3 +23,9 @@ config.suffixes = ['.itest', '.c'] config.is_windows = lit_config.isWindows if not lit_config.isWindows: config.available_features.add('PLATFORM_IS_NOT_WINDOWS') + +# In Linux CI, $HOME is required for Chrome as it needs to access things in ~/.local +config.environment['HOME'] = os.environ.get('HOME', '/tmp') + +# In Windows CI, %ProgramW6432% is required for Selenium to properly detect browsers +config.environment['ProgramW6432'] = os.environ.get('ProgramW6432', '')