Skip to content

Commit

Permalink
refactor(shader): move ShaderDirs
Browse files Browse the repository at this point in the history
  • Loading branch information
loqusion committed Mar 18, 2024
1 parent 635dee6 commit 2ec1bd3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 45 deletions.
48 changes: 3 additions & 45 deletions src/hyprshade/shader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,17 @@
from functools import cached_property
from typing import Final

from more_itertools import first_true, flatten
from more_itertools import flatten

from hyprshade.utils.fs import scandir_recursive
from hyprshade.utils.path import strip_all_extensions, stripped_basename
from hyprshade.utils.xdg import user_config_dir

from . import hyprctl


class _ShaderDirs:
ENV_VAR_NAME: Final = "HYPRSHADE_SHADERS_DIR"
SYSTEM_DIR: Final = "/usr/share/hyprshade/shaders"

@staticmethod
def env() -> str:
return os.path.expanduser(
os.path.expandvars(os.path.expandvars("$" + _ShaderDirs.ENV_VAR_NAME))
)

@staticmethod
def user_hypr() -> str:
return os.path.join(user_config_dir("hypr"), "shaders")

@staticmethod
def user_hyprshade() -> str:
return os.path.join(user_config_dir("hyprshade"), "shaders")

@staticmethod
def system() -> str:
import sysconfig

return first_true(
[os.path.join(sysconfig.get_path("data"), "share", "hyprshade", "shaders")],
pred=os.path.exists,
default=_ShaderDirs.SYSTEM_DIR,
)

@staticmethod
def all() -> list[str]:
return [
x
for x in [
_ShaderDirs.env(),
_ShaderDirs.user_hypr(),
_ShaderDirs.user_hyprshade(),
_ShaderDirs.system(),
]
if os.path.exists(x)
]
from .dirs import ShaderDirs


class Shader:
dirs: Final = _ShaderDirs
dirs: Final = ShaderDirs
_given_path: str | None
_name: str

Expand Down
50 changes: 50 additions & 0 deletions src/hyprshade/shader/dirs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

import os
from typing import Final

from more_itertools import first_true

from hyprshade.utils.xdg import user_config_dir


class ShaderDirs:
ENV_VAR_NAME: Final = "HYPRSHADE_SHADERS_DIR"
SYSTEM_DIR: Final = "/usr/share/hyprshade/shaders"

@staticmethod
def env() -> str:
return os.path.expanduser(
os.path.expandvars(os.path.expandvars("$" + ShaderDirs.ENV_VAR_NAME))
)

@staticmethod
def user_hypr() -> str:
return os.path.join(user_config_dir("hypr"), "shaders")

@staticmethod
def user_hyprshade() -> str:
return os.path.join(user_config_dir("hyprshade"), "shaders")

@staticmethod
def system() -> str:
import sysconfig

return first_true(
[os.path.join(sysconfig.get_path("data"), "share", "hyprshade", "shaders")],
pred=os.path.exists,
default=ShaderDirs.SYSTEM_DIR,
)

@staticmethod
def all() -> list[str]:
return [
x
for x in [
ShaderDirs.env(),
ShaderDirs.user_hypr(),
ShaderDirs.user_hyprshade(),
ShaderDirs.system(),
]
if os.path.exists(x)
]

0 comments on commit 2ec1bd3

Please sign in to comment.