Skip to content

Commit

Permalink
fix: get path of conda env (#123)
Browse files Browse the repository at this point in the history
* fix: get path of conda instead of "../Downloads" when the system is win32

* docs: ignore .idea/
  • Loading branch information
VON0000 authored Nov 19, 2024
1 parent 8fad802 commit 27ca962
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.idea/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
10 changes: 9 additions & 1 deletion src/pyopensky/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import sys
from importlib.metadata import version
from pathlib import Path

from .tzdata import download_tzdata_windows

Expand All @@ -10,4 +12,10 @@
# artifact that has been retained for compatibility with older versions of
# Python.
if sys.platform == "win32":
download_tzdata_windows(year=2022)
conda_env_path = os.getenv('CONDA_PREFIX', None)
if conda_env_path:
base_dir = Path(conda_env_path) / "Lib" / "site-packages" / "tzdata"
else:
base_dir = Path(os.path.expanduser("~")) / "Downloads"

download_tzdata_windows(year=2022, base_dir=base_dir)
11 changes: 8 additions & 3 deletions src/pyopensky/tzdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ def download_tzdata_windows(
name: str = "tzdata",
base_dir: None | Path = None,
) -> None:
folder = (
base_dir if base_dir else Path(os.path.expanduser("~")) / "Downloads"
)
if base_dir is None:
conda_env_path = os.getenv('CONDA_PREFIX', None)
if conda_env_path:
base_dir = Path(conda_env_path) / "Lib" / "site-packages" / "tzdata"
else:
base_dir = Path(os.path.expanduser("~")) / "Downloads"

folder = base_dir

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

0 comments on commit 27ca962

Please sign in to comment.