Skip to content

Commit

Permalink
Use pyproject.toml + Hatch instead of setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jul 18, 2023
1 parent abdbaa8 commit 31f9662
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
34 changes: 34 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "sgm"
dynamic = ["version"]
description = "Stability Generative Models"
readme = "README.md"
license-files = { paths = ["LICENSE"] }
requires-python = ">=3.8"

[project.urls]
Homepage = "https://github.com/Stability-AI/generative-models"

[tool.hatch.version]
path = "sgm/__init__.py"

[tool.hatch.build]
# This needs to be explicitly set so the configuration files
# grafted into the `sgm` directory get included in the wheel's
# RECORD file.
include = [
"sgm",
]
# The force-include configurations below make Hatch copy
# the configs/ directory (containing the various YAML files required
# to generatively model) into the source distribution and the wheel.

[tool.hatch.build.targets.sdist.force-include]
"./configs" = "sgm/configs"

[tool.hatch.build.targets.wheel.force-include]
"./configs" = "sgm/configs"
13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

4 changes: 3 additions & 1 deletion sgm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .data import StableDataModuleFromConfig
from .models import AutoencodingEngine, DiffusionEngine
from .util import instantiate_from_config
from .util import instantiate_from_config, get_configs_path

__version__ = "0.0.1"
18 changes: 18 additions & 0 deletions sgm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

0 comments on commit 31f9662

Please sign in to comment.