Skip to content

Commit

Permalink
fix for tzdata missing in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Nov 10, 2024
1 parent 4c06f8c commit 05ed407
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pyopensky/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import sys
from importlib.metadata import version

from .tzdata import download_tzdata_windows

__version__ = version("pyopensky")

# Despite the 'win32' string, this value is returned on all versions of Windows,
# including both 32-bit and 64-bit. The 'win32' identifier is a historical
# artifact that has been retained for compatibility with older versions of
# Python.
if sys.platform == "win32":
download_tzdata_windows(year=2022)
48 changes: 48 additions & 0 deletions src/pyopensky/tzdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# While Arrow uses the OS-provided timezone database on Linux and macOS, it
# requires a user-provided database on Windows. You must download and extract
# the text version of the IANA timezone database and add the Windows timezone
# mapping XML.
# https://arrow.apache.org/docs/cpp/build_system.html#runtime-dependencies

from __future__ import annotations

import os
import tarfile
from pathlib import Path

import httpx


def download_tzdata_windows(
year: int = 2022,
*,
name: str = "tzdata",
base_dir: None | Path = None,
) -> None:
folder = (
base_dir if base_dir else Path(os.path.expanduser("~")) / "Downloads"
)

if (folder / name).is_dir():
return

tz_path = folder / "tzdata.tar.gz"

c = httpx.get(
f"https://data.iana.org/time-zones/releases/tzdata{year}f.tar.gz"
)
c.raise_for_status()
tz_path.write_bytes(c.content)

extracted_folder = folder / name

if not extracted_folder.exists():
extracted_folder.mkdir(parents=True)

tarfile.open(tz_path).extractall(extracted_folder)

c = httpx.get(
"https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml"
)
c.raise_for_status()
(extracted_folder / "windowsZone.xml").write_bytes(c.content)

0 comments on commit 05ed407

Please sign in to comment.