From ab12d81663517796c18c7bf9266e7343cf0b1705 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 30 May 2023 14:17:18 +0300 Subject: [PATCH] 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 --- ldm/__init__.py | 20 ++++++++++++++++++++ ldm/__version__.py | 1 + pyproject.toml | 37 +++++++++++++++++++++++++++++++++++++ setup.py | 13 ------------- 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 ldm/__init__.py create mode 100644 ldm/__version__.py create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/ldm/__init__.py b/ldm/__init__.py new file mode 100644 index 0000000..1cc20f6 --- /dev/null +++ b/ldm/__init__.py @@ -0,0 +1,20 @@ +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}") diff --git a/ldm/__version__.py b/ldm/__version__.py new file mode 100644 index 0000000..58039f5 --- /dev/null +++ b/ldm/__version__.py @@ -0,0 +1 @@ +__version__ = "2.1.1" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4e85a0a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,37 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "stable-diffusion" +dynamic = ["version"] +description = "Stable Diffusion is a latent text-to-image diffusion model." +readme = "README.md" +license = "MIT" +requires-python = ">=3.8" # based on environment.yaml +zip-safe = false # we need to be read the YAMLs from disk +dependencies = [ + "numpy", + "torch", + "tqdm", +] + +[tool.hatch.version] +path = "ldm/__version__.py" + +[tool.hatch.build] +# This needs to be explicitly set so the configuration files +# grafted into the `ldm` directory get included in the wheel's +# RECORD file. +include = [ + "ldm", +] +# The force-include configurations below make Hatch copy +# the configs/ directory (containing the various YAML files required +# to stably diffuse) into the source distribution and the wheel. + +[tool.hatch.build.targets.sdist.force-include] +"./configs" = "ldm/configs" + +[tool.hatch.build.targets.wheel.force-include] +"./configs" = "ldm/configs" diff --git a/setup.py b/setup.py deleted file mode 100644 index 00f5b4d..0000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -from setuptools import setup, find_packages - -setup( - name='stable-diffusion', - version='0.0.1', - description='', - packages=find_packages(), - install_requires=[ - 'torch', - 'numpy', - 'tqdm', - ], -) \ No newline at end of file