-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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 |
---|---|---|
@@ -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) |
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,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) |