StableDiffusion/ldm/__init__.py
Aarni Koskela ab12d81663 Set up Python packaging
* Adds `ldm/__version__.py` (2.1.1 seems to approximately match what the readme says)
* Sets up packaging using `hatch` (removing the defunct `setup.py`)
  * `configs/` gets packaged as `ldm/configs` when using a packaged version
* Adds `ldm.get_configs_path()` to make it easy for downstream users to find the configs path
2023-05-30 14:17:18 +03:00

20 lines
622 B
Python

import os
def get_configs_path() -> str:
"""
Get the `configs` directory.
For a working copy, this is the one in the root of the repository,
but for an installed copy, it's in the `ldm` package (see pyproject.toml).
"""
this_dir = os.path.dirname(__file__)
candidates = (
os.path.join(this_dir, "configs"),
os.path.join(this_dir, "..", "configs"),
)
for candidate in candidates:
candidate = os.path.abspath(candidate)
if os.path.isdir(candidate):
return candidate
raise FileNotFoundError(f"Could not find LDM configs in {candidates}")