Set up Python packaging (#17)

* Sort .gitignore; add dist and *.py[cod]

* Use pyproject.toml + Hatch instead of setup.py

Sibling of https://github.com/Stability-AI/stablediffusion/pull/269

* Add packaging documentation
This commit is contained in:
Aarni Koskela
2023-07-18 14:06:05 +03:00
committed by GitHub
parent 5c10deee76
commit e5dc9669ed
6 changed files with 78 additions and 18 deletions

View File

@@ -229,3 +229,21 @@ def load_model_from_config(config, ckpt, verbose=True, freeze=True):
model.eval()
return model
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 `sgm` 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 SGM configs in {candidates}")