Skip to content

Commit

Permalink
yeet_api: Add support for windows and guard against unsupported OSSes
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimifr committed Jan 25, 2024
1 parent e132dca commit 6440954
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions yeet_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@

from pathlib import Path

_home_dir: str

if os.name == "posix":
_home_dir = os.getenv("HOME", "")
elif os.name == "nt":
_home_dir = os.getenv("USERPROFILE", "")
else:
raise OSError("Unsupported OS: yeet-api only supports Windows and unix-like OSses.")

if not shutil.which("git"):
raise FileNotFoundError("Git executable is not found."
"\nFor Windows, install it from https://git-scm.com/downloads"
"\nFor Linux, it is best to use your distro package manager. If "
"for some reason you can't, use the link for Windows.")

_config_dir = Path(os.getenv("HOME", "")).joinpath(".config", "yeet")
_config_dir = Path(_home_dir).joinpath(".config", "yeet")
if not _config_dir.exists():
os.makedirs(_config_dir, exist_ok=True)

_cache_dir = Path(os.getenv("HOME", "")).joinpath(".cache", "yeet")
_cache_dir = Path(_home_dir).joinpath(".cache", "yeet")
if not _cache_dir.exists():
os.makedirs(_cache_dir, exist_ok=True)

Expand Down

0 comments on commit 6440954

Please sign in to comment.